Skip to content

Commit

Permalink
support label issuer tied to appview
Browse files Browse the repository at this point in the history
  • Loading branch information
devinivy committed Jan 9, 2024
1 parent 14d8773 commit 4c80b12
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 8 deletions.
9 changes: 9 additions & 0 deletions packages/bsky/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface ServerConfigValues {
dataplaneHttpVersion?: '1.1' | '2'
dataplaneIgnoreBadTls?: boolean
didPlcUrl: string
labelsFromIssuerDids?: string[]
handleResolveNameservers?: string[]
imgUriEndpoint?: string
blobCacheLocation?: string
Expand Down Expand Up @@ -45,6 +46,9 @@ export class ServerConfig {
const dataplaneHttpVersion = process.env.BSKY_DATAPLANE_HTTP_VERSION || '2'
const dataplaneIgnoreBadTls =
process.env.BSKY_DATAPLANE_IGNORE_BAD_TLS === 'true'
const labelsFromIssuerDids = process.env.BSKY_LABELS_FROM_ISSUER_DIDS
? process.env.BSKY_LABELS_FROM_ISSUER_DIDS.split(',')
: []
const adminPassword = process.env.BSKY_ADMIN_PASSWORD
assert(adminPassword)
const moderatorPassword = process.env.BSKY_MODERATOR_PASSWORD
Expand All @@ -67,6 +71,7 @@ export class ServerConfig {
dataplaneHttpVersion,
dataplaneIgnoreBadTls,
didPlcUrl,
labelsFromIssuerDids,
handleResolveNameservers,
imgUriEndpoint,
blobCacheLocation,
Expand Down Expand Up @@ -127,6 +132,10 @@ export class ServerConfig {
return this.cfg.dataplaneIgnoreBadTls
}

get labelsFromIssuerDids() {
return this.cfg.labelsFromIssuerDids ?? []
}

get handleResolveNameservers() {
return this.cfg.handleResolveNameservers
}
Expand Down
6 changes: 3 additions & 3 deletions packages/bsky/src/data-plane/server/routes/labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { Database } from '../db'

export default (db: Database): Partial<ServiceImpl<typeof Service>> => ({
async getLabels(req) {
// @TODO add in issues param
const { subjects } = req
if (subjects.length === 0) {
const { subjects, issuers } = req
if (subjects.length === 0 || issuers.length === 0) {
return { records: [] }
}
const res = await db.db
.selectFrom('label')
.where('uri', 'in', subjects)
.where('src', 'in', issuers)
.selectAll()
.execute()

Expand Down
7 changes: 5 additions & 2 deletions packages/bsky/src/hydration/hydrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,14 @@ export class Hydrator {
graph: GraphHydrator
label: LabelHydrator

constructor(public dataplane: DataPlaneClient) {
constructor(
public dataplane: DataPlaneClient,
public opts?: { labelsFromIssuerDids?: string[] },
) {
this.actor = new ActorHydrator(dataplane)
this.feed = new FeedHydrator(dataplane)
this.graph = new GraphHydrator(dataplane)
this.label = new LabelHydrator(dataplane)
this.label = new LabelHydrator(dataplane, opts)
}

// app.bsky.actor.defs#profileView
Expand Down
8 changes: 7 additions & 1 deletion packages/bsky/src/hydration/label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@ export type { Label } from '../lexicon/types/com/atproto/label/defs'
export type Labels = HydrationMap<Label[]>

export class LabelHydrator {
constructor(public dataplane: DataPlaneClient) {}
constructor(
public dataplane: DataPlaneClient,
public opts?: { labelsFromIssuerDids?: string[] },
) {}

async getLabelsForSubjects(
subjects: string[],
issuers?: string[],
): Promise<Labels> {
issuers = ([] as string[])
.concat(issuers ?? [])
.concat(this.opts?.labelsFromIssuerDids ?? [])
const res = await this.dataplane.getLabels({ subjects, issuers })
return res.labels.reduce((acc, cur) => {
const label = parseJsonBytes(cur) as Label | undefined
Expand Down
4 changes: 3 additions & 1 deletion packages/bsky/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ export class BskyAppView {
httpVersion: config.dataplaneHttpVersion,
rejectUnauthorized: !config.dataplaneIgnoreBadTls,
})
const hydrator = new Hydrator(dataplane)
const hydrator = new Hydrator(dataplane, {
labelsFromIssuerDids: config.labelsFromIssuerDids,
})
const views = new Views(imgUriBuilder)

const ctx = new AppContext({
Expand Down
1 change: 1 addition & 0 deletions packages/dev-env/src/bsky.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export class TestBsky {
dataplaneUrls: [`http://localhost:${dataplanePort}`],
dataplaneHttpVersion: '1.1',
modServiceDid: cfg.modServiceDid ?? 'did:example:invalidMod',
labelsFromIssuerDids: ['did:example:labeler'], // this did is also used as the labeler in seeds
...cfg,
adminPassword: ADMIN_PASSWORD,
moderatorPassword: MOD_PASSWORD,
Expand Down
2 changes: 1 addition & 1 deletion packages/dev-env/src/seed/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ const createLabel = async (
val: opts.val,
cts: new Date().toISOString(),
neg: false,
src: 'did:example:labeler',
src: 'did:example:labeler', // this did is also configured on labelsFromIssuerDids
})
.execute()
}

0 comments on commit 4c80b12

Please sign in to comment.