Skip to content

Commit

Permalink
✨ Add proxy route on ozone for email search endpoint on entryway (blu…
Browse files Browse the repository at this point in the history
…esky-social#2587)

* ✨ Add proxy route on ozone for email search endpoint on entryway

* Use entrywayAuth instead of appviewAuth

Co-authored-by: Daniel Holmgren <[email protected]>

---------

Co-authored-by: Daniel Holmgren <[email protected]>
  • Loading branch information
foysalit and dholms authored Jun 18, 2024
1 parent a8d6c11 commit 37c5719
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/ozone/src/api/proxied.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,21 @@ export default function (server: Server, ctx: AppContext) {
}
},
})

server.com.atproto.admin.searchAccounts({
auth: ctx.authVerifier.moderator,
handler: async (request) => {
if (!ctx.entrywayAgent) {
throw new Error('Entryway not configured')
}
const res = await ctx.entrywayAgent.api.com.atproto.admin.searchAccounts(
request.params,
await ctx.entrywayAuth(),
)
return {
encoding: 'application/json',
body: res.data,
}
},
})
}
16 changes: 16 additions & 0 deletions packages/ozone/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ export const envToCfg = (env: OzoneEnvironment): OzoneConfig => {
}
}

let entrywayCfg: OzoneConfig['entryway'] = null
if (env.entrywayUrl || env.entrywayDid) {
assert(env.entrywayUrl && env.entrywayDid)
chatCfg = {
url: env.entrywayUrl,
did: env.entrywayDid,
}
}

const cdnCfg: OzoneConfig['cdn'] = {
paths: env.cdnPaths,
}
Expand Down Expand Up @@ -81,6 +90,7 @@ export const envToCfg = (env: OzoneEnvironment): OzoneConfig => {
appview: appviewCfg,
pds: pdsCfg,
chat: chatCfg,
entryway: entrywayCfg,
cdn: cdnCfg,
identity: identityCfg,
blobDivert: blobDivertServiceCfg,
Expand All @@ -94,6 +104,7 @@ export type OzoneConfig = {
appview: AppviewConfig
pds: PdsConfig | null
chat: ChatConfig | null
entryway: EntrywayConfig | null
cdn: CdnConfig
identity: IdentityConfig
blobDivert: BlobDivertConfig | null
Expand Down Expand Up @@ -137,6 +148,11 @@ export type ChatConfig = {
did: string
}

export type EntrywayConfig = {
url: string
did: string
}

export type CdnConfig = {
paths?: string[]
}
Expand Down
4 changes: 4 additions & 0 deletions packages/ozone/src/config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export const readEnv = (): OzoneEnvironment => {
pdsDid: envStr('OZONE_PDS_DID'),
chatUrl: envStr('OZONE_CHAT_URL'),
chatDid: envStr('OZONE_CHAT_DID'),
entrywayUrl: envStr('OZONE_ENTRYWAY_URL'),
entrywayDid: envStr('OZONE_ENTRYWAY_DID'),
dbPostgresUrl: envStr('OZONE_DB_POSTGRES_URL'),
dbPostgresSchema: envStr('OZONE_DB_POSTGRES_SCHEMA'),
dbPoolSize: envInt('OZONE_DB_POOL_SIZE'),
Expand Down Expand Up @@ -46,6 +48,8 @@ export type OzoneEnvironment = {
pdsDid?: string
chatUrl?: string
chatDid?: string
entrywayUrl?: string
entrywayDid?: string
dbPostgresUrl?: string
dbPostgresSchema?: string
dbPoolSize?: number
Expand Down
16 changes: 16 additions & 0 deletions packages/ozone/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export type AppContextOptions = {
appviewAgent: AtpAgent
pdsAgent: AtpAgent | undefined
chatAgent: AtpAgent | undefined
entrywayAgent: AtpAgent | undefined
blobDiverter?: BlobDiverter
signingKey: Keypair
signingKeyId: number
Expand Down Expand Up @@ -71,6 +72,9 @@ export class AppContext {
const chatAgent = cfg.chat
? new AtpAgent({ service: cfg.chat.url })
: undefined
const entrywayAgent = cfg.entryway
? new AtpAgent({ service: cfg.entryway.url })
: undefined

const idResolver = new IdResolver({
plcUrl: cfg.identity.plcUrl,
Expand Down Expand Up @@ -127,6 +131,7 @@ export class AppContext {
appviewAgent,
pdsAgent,
chatAgent,
entrywayAgent,
signingKey,
signingKeyId,
idResolver,
Expand Down Expand Up @@ -180,6 +185,10 @@ export class AppContext {
return this.opts.chatAgent
}

get entrywayAgent(): AtpAgent | undefined {
return this.opts.entrywayAgent
}

get signingKey(): Keypair {
return this.opts.signingKey
}
Expand Down Expand Up @@ -235,6 +244,13 @@ export class AppContext {
return this.serviceAuthHeaders(this.cfg.chat.did)
}

async entrywayAuth() {
if (!this.cfg.entryway) {
throw new Error('No entryway service configured')
}
return this.serviceAuthHeaders(this.cfg.entryway.did)
}

devOverride(overrides: Partial<AppContextOptions>) {
this.opts = {
...this.opts,
Expand Down

0 comments on commit 37c5719

Please sign in to comment.