Skip to content

Commit

Permalink
update divert blob config to use basic admin auth
Browse files Browse the repository at this point in the history
  • Loading branch information
devinivy committed Mar 11, 2024
1 parent 641fcd6 commit f2ac002
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
16 changes: 8 additions & 8 deletions packages/ozone/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ export const envToCfg = (env: OzoneEnvironment): OzoneConfig => {
}

const blobDivertServiceCfg =
env.blobDivertServiceUrl && env.blobDivertServiceAuthToken
env.blobDivertUrl && env.blobDivertAdminPassword
? {
url: env.blobDivertServiceUrl,
authToken: env.blobDivertServiceAuthToken,
url: env.blobDivertUrl,
adminPassword: env.blobDivertAdminPassword,
}
: undefined
: null
const accessCfg: OzoneConfig['access'] = {
admins: env.adminDids,
moderators: env.moderatorDids,
Expand All @@ -70,7 +70,7 @@ export const envToCfg = (env: OzoneEnvironment): OzoneConfig => {
pds: pdsCfg,
cdn: cdnCfg,
identity: identityCfg,
blobDivertService: blobDivertServiceCfg,
blobDivert: blobDivertServiceCfg,
access: accessCfg,
}
}
Expand All @@ -82,7 +82,7 @@ export type OzoneConfig = {
pds: PdsConfig | null
cdn: CdnConfig
identity: IdentityConfig
blobDivertService?: BlobReportServiceConfig
blobDivert: BlobDivertConfig | null
access: AccessConfig
}

Expand All @@ -94,9 +94,9 @@ export type ServiceConfig = {
devMode?: boolean
}

export type BlobReportServiceConfig = {
export type BlobDivertConfig = {
url: string
authToken: string
adminPassword: string
}

export type DatabaseConfig = {
Expand Down
8 changes: 4 additions & 4 deletions packages/ozone/src/config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export const readEnv = (): OzoneEnvironment => {
triageDids: envList('OZONE_TRIAGE_DIDS'),
adminPassword: envStr('OZONE_ADMIN_PASSWORD'),
signingKeyHex: envStr('OZONE_SIGNING_KEY_HEX'),
blobDivertServiceUrl: envStr('OZONE_BLOB_DIVERT_SERVICE_URL'),
blobDivertServiceAuthToken: envStr('OZONE_BLOB_DIVERT_SERVICE_AUTH_TOKEN'),
blobDivertUrl: envStr('OZONE_BLOB_DIVERT_URL'),
blobDivertAdminPassword: envStr('OZONE_BLOB_DIVERT_ADMIN_PASSWORD'),
}
}

Expand Down Expand Up @@ -54,6 +54,6 @@ export type OzoneEnvironment = {
triageDids: string[]
adminPassword?: string
signingKeyHex?: string
blobDivertServiceUrl?: string
blobDivertServiceAuthToken?: string
blobDivertUrl?: string
blobDivertAdminPassword?: string
}
4 changes: 2 additions & 2 deletions packages/ozone/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ export class AppContext {
})

const backgroundQueue = new BackgroundQueue(db)
const blobDiverter = cfg.blobDivertService
const blobDiverter = cfg.blobDivert
? new BlobDiverter(db, {
idResolver,
serviceConfig: cfg.blobDivertService,
serviceConfig: cfg.blobDivert,
})
: undefined
const eventPusher = new EventPusher(db, createAuthHeaders, {
Expand Down
12 changes: 8 additions & 4 deletions packages/ozone/src/daemon/blob-diverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ import { CID } from 'multiformats/cid'

import Database from '../db'
import { retryHttp } from '../util'
import { BlobReportServiceConfig } from '../config'
import { BlobDivertConfig } from '../config'

export class BlobDiverter {
serviceConfig: BlobReportServiceConfig
serviceConfig: BlobDivertConfig
idResolver: IdResolver

constructor(
public db: Database,
services: {
idResolver: IdResolver
serviceConfig: BlobReportServiceConfig
serviceConfig: BlobDivertConfig
},
) {
this.serviceConfig = services.serviceConfig
Expand Down Expand Up @@ -69,7 +69,7 @@ export class BlobDiverter {
method: 'POST',
data: imageStream,
headers: {
Authorization: this.serviceConfig.authToken,
Authorization: basicAuth('admin', this.serviceConfig.adminPassword),
'Content-Type': contentType,
},
})
Expand Down Expand Up @@ -144,3 +144,7 @@ export class BlobDiverter {
return true
}
}

const basicAuth = (username: string, password: string) => {
return 'Basic ' + Buffer.from(`${username}:${password}`).toString('base64')
}

0 comments on commit f2ac002

Please sign in to comment.