Skip to content

Commit

Permalink
remove labelerDid cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
dholms committed Jan 4, 2024
1 parent b11086e commit de48f83
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 45 deletions.
8 changes: 4 additions & 4 deletions packages/bsky/src/auto-moderator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export class AutoModerator {
reasonType: REASONOTHER,
reason: `Automatically flagged for possible slurs: ${matches.join(', ')}`,
subject: formattedSubject,
reportedBy: this.ctx.cfg.labelerDid,
reportedBy: this.ctx.cfg.serverDid,
})
}

Expand Down Expand Up @@ -199,7 +199,7 @@ export class AutoModerator {
)

await this.pushAgent.com.atproto.moderation.createReport({
reportedBy: this.ctx.cfg.labelerDid,
reportedBy: this.ctx.cfg.serverDid,
reasonType: REASONVIOLATION,
subject: {
$type: 'com.atproto.repo.strongRef',
Expand All @@ -220,7 +220,7 @@ export class AutoModerator {
cid: recordCid.toString(),
},
subjectBlobCids: takedownCids.map((c) => c.toString()),
createdBy: this.ctx.cfg.labelerDid,
createdBy: this.ctx.cfg.serverDid,
})
}

Expand All @@ -239,7 +239,7 @@ export class AutoModerator {
uri: uri.toString(),
cid: cid.toString(),
},
createdBy: this.ctx.cfg.labelerDid,
createdBy: this.ctx.cfg.serverDid,
})
}

Expand Down
7 changes: 0 additions & 7 deletions packages/bsky/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export interface ServerConfigValues {
imgUriEndpoint?: string
blobCacheLocation?: string
searchEndpoint?: string
labelerDid: string
adminPassword: string
moderatorPassword: string
triagePassword: string
Expand Down Expand Up @@ -117,7 +116,6 @@ export class ServerConfig {
assert(moderatorPassword)
const triagePassword = process.env.TRIAGE_PASSWORD || undefined
assert(triagePassword)
const labelerDid = process.env.LABELER_DID || 'did:example:labeler'
const modServiceUrl =
overrides?.modServiceUrl || process.env.MODERATION_PUSH_URL || undefined
const modServiceDid =
Expand Down Expand Up @@ -156,7 +154,6 @@ export class ServerConfig {
imgUriEndpoint,
blobCacheLocation,
searchEndpoint,
labelerDid,
adminPassword,
moderatorPassword,
triagePassword,
Expand Down Expand Up @@ -274,10 +271,6 @@ export class ServerConfig {
return this.cfg.searchEndpoint
}

get labelerDid() {
return this.cfg.labelerDid
}

get adminPassword() {
return this.cfg.adminPassword
}
Expand Down
14 changes: 7 additions & 7 deletions packages/bsky/src/indexer/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DAY, HOUR, parseIntWithFallback } from '@atproto/common'

export interface IndexerConfigValues {
version: string
serverDid: string
dbPostgresUrl: string
dbPostgresSchema?: string
redisHost?: string // either set redis host, or both sentinel name and hosts
Expand All @@ -13,7 +14,6 @@ export interface IndexerConfigValues {
didCacheStaleTTL: number
didCacheMaxTTL: number
handleResolveNameservers?: string[]
labelerDid: string
hiveApiKey?: string
abyssEndpoint?: string
abyssPassword?: string
Expand All @@ -37,6 +37,7 @@ export class IndexerConfig {

static readEnv(overrides?: Partial<IndexerConfigValues>) {
const version = process.env.BSKY_VERSION || '0.0.0'
const serverDid = process.env.SERVER_DID || 'did:example:test'
const dbPostgresUrl =
overrides?.dbPostgresUrl || process.env.DB_PRIMARY_POSTGRES_URL
const dbPostgresSchema =
Expand Down Expand Up @@ -66,7 +67,6 @@ export class IndexerConfig {
const handleResolveNameservers = process.env.HANDLE_RESOLVE_NAMESERVERS
? process.env.HANDLE_RESOLVE_NAMESERVERS.split(',')
: []
const labelerDid = process.env.LABELER_DID || 'did:example:labeler'
const moderationPushUrl =
overrides?.moderationPushUrl ||
process.env.MODERATION_PUSH_URL ||
Expand Down Expand Up @@ -102,6 +102,7 @@ export class IndexerConfig {
assert(indexerPartitionIds.length > 0)
return new IndexerConfig({
version,
serverDid,
dbPostgresUrl,
dbPostgresSchema,
redisHost,
Expand All @@ -112,7 +113,6 @@ export class IndexerConfig {
didCacheStaleTTL,
didCacheMaxTTL,
handleResolveNameservers,
labelerDid,
moderationPushUrl,
hiveApiKey,
abyssEndpoint,
Expand All @@ -137,6 +137,10 @@ export class IndexerConfig {
return this.cfg.version
}

get serverDid() {
return this.cfg.serverDid
}

get dbPostgresUrl() {
return this.cfg.dbPostgresUrl
}
Expand Down Expand Up @@ -177,10 +181,6 @@ export class IndexerConfig {
return this.cfg.handleResolveNameservers
}

get labelerDid() {
return this.cfg.labelerDid
}

get moderationPushUrl() {
return this.cfg.moderationPushUrl
}
Expand Down
6 changes: 2 additions & 4 deletions packages/bsky/tests/auto-moderator/labeler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ describe('labeler', () => {
let ozone: TestOzone
let autoMod: AutoModerator
let ctx: IndexerContext
let labelerDid: string
let badBlob1: BlobRef
let badBlob2: BlobRef
let goodBlob: BlobRef
Expand All @@ -32,7 +31,6 @@ describe('labeler', () => {
ozone = network.ozone
ctx = network.bsky.indexer.ctx
const pdsCtx = network.pds.ctx
labelerDid = ctx.cfg.labelerDid
autoMod = ctx.autoMod
autoMod.imgLabeler = new TestImgLabeler()
const sc = network.getSeedClient()
Expand Down Expand Up @@ -90,7 +88,7 @@ describe('labeler', () => {
const labels = await getLabels(uri.toString())
expect(labels.length).toBe(1)
expect(labels[0]).toMatchObject({
src: labelerDid,
src: ozone.ctx.cfg.service.did,
uri: uri.toString(),
cid: cid.toString(),
val: 'test-label',
Expand All @@ -113,7 +111,7 @@ describe('labeler', () => {
createLabelVals: 'test-label',
negateLabelVals: null,
comment: `[AutoModerator]: Applying labels`,
createdBy: labelerDid,
createdBy: network.bsky.indexer.ctx.cfg.serverDid,
})
})

Expand Down
4 changes: 2 additions & 2 deletions packages/bsky/tests/views/timeline.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ describe('timeline views', () => {
await network.bsky.ctx.services
.label(network.bsky.ctx.db.getPrimary())
.formatAndCreate(
network.bsky.ctx.cfg.labelerDid,
network.ozone.ctx.cfg.service.did,
labelPostA.uriStr,
labelPostA.cidStr,
{ create: ['kind'] },
)
await network.bsky.ctx.services
.label(network.bsky.ctx.db.getPrimary())
.formatAndCreate(
network.bsky.ctx.cfg.labelerDid,
network.ozone.ctx.cfg.service.did,
labelPostB.uriStr,
labelPostB.cidStr,
{ create: ['kind'] },
Expand Down
5 changes: 2 additions & 3 deletions packages/dev-env/src/bsky.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export class TestBsky {
adminPassword: ADMIN_PASSWORD,
moderatorPassword: MOD_PASSWORD,
triagePassword: TRIAGE_PASSWORD,
labelerDid: 'did:example:labeler',
feedGenDid: 'did:example:feedGen',
rateLimitsEnabled: false,
})
Expand Down Expand Up @@ -100,9 +99,9 @@ export class TestBsky {
// indexer
const indexerCfg = new bsky.IndexerConfig({
version: '0.0.0',
serverDid,
didCacheStaleTTL: HOUR,
didCacheMaxTTL: DAY,
labelerDid: 'did:example:labeler',
redisHost: cfg.redisHost,
dbPostgresUrl: cfg.dbPrimaryPostgresUrl,
dbPostgresSchema: cfg.dbPostgresSchema,
Expand Down Expand Up @@ -258,9 +257,9 @@ export async function getIndexers(
const ns = name ? await randomIntFromSeed(name, 1000000) : undefined
const baseCfg: bsky.IndexerConfigValues = {
version: '0.0.0',
serverDid: 'did:example:bsky',
didCacheStaleTTL: HOUR,
didCacheMaxTTL: DAY,
labelerDid: 'did:example:labeler',
labelerKeywords: { label_me: 'test-label', label_me_2: 'test-label-2' },
redisHost: process.env.REDIS_HOST || '',
dbPostgresUrl: process.env.DB_POSTGRES_URL || '',
Expand Down
4 changes: 2 additions & 2 deletions packages/dev-env/src/mock/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,15 @@ export async function generateMockSetup(env: TestNetwork) {
const labelSrvc = ctx.services.label(ctx.db.getPrimary())
await labelSrvc.createLabels([
{
src: ctx.cfg.labelerDid,
src: env.ozone.ctx.cfg.service.did,
uri: labeledPost.uri,
cid: labeledPost.cid,
val: 'nudity',
neg: false,
cts: new Date().toISOString(),
},
{
src: ctx.cfg.labelerDid,
src: env.ozone.ctx.cfg.service.did,
uri: filteredPost.uri,
cid: filteredPost.cid,
val: 'dmca-violation',
Expand Down
1 change: 0 additions & 1 deletion packages/dev-env/src/ozone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export class TestOzone {
adminPassword: ADMIN_PASSWORD,
moderatorPassword: MOD_PASSWORD,
triagePassword: TRIAGE_PASSWORD,
labelerDid: 'did:example:labeler',
}

// Separate migration db in case migration changes some connection state that we need in the tests, e.g. "alter database ... set ..."
Expand Down
2 changes: 1 addition & 1 deletion packages/ozone/src/api/admin/emitModerationEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default function (server: Server, ctx: AppContext) {

if (isLabelEvent) {
await moderationTxn.formatAndCreateLabels(
ctx.cfg.service.labelerDid,
ctx.cfg.service.did,
result.subjectUri ?? result.subjectDid,
result.subjectCid,
{
Expand Down
4 changes: 1 addition & 3 deletions packages/ozone/src/api/moderation/createReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ export default function (server: Server, ctx: AppContext) {
auth: ctx.authOptionalAccessOrRoleVerifier,
handler: async ({ input, auth }) => {
const requester =
'did' in auth.credentials
? auth.credentials.did
: ctx.cfg.service.labelerDid
'did' in auth.credentials ? auth.credentials.did : ctx.cfg.service.did
const { reasonType, reason } = input.body
const subject = subjectFromInput(input.body.subject)

Expand Down
3 changes: 0 additions & 3 deletions packages/ozone/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ export const envToCfg = (env: OzoneEnvironment): OzoneConfig => {
const port = env.port ?? 3000
assert(env.publicUrl)
assert(env.serverDid)
assert(env.labelerDid)
const serviceCfg: OzoneConfig['service'] = {
port,
publicUrl: env.publicUrl,
did: env.serverDid,
labelerDid: env.labelerDid,
version: env.version,
}

Expand Down Expand Up @@ -63,7 +61,6 @@ export type ServiceConfig = {
port: number
publicUrl: string
did: string
labelerDid: string
version?: string
}

Expand Down
4 changes: 1 addition & 3 deletions packages/ozone/src/config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const readEnv = (): OzoneEnvironment => {
nodeEnv: envStr('NODE_ENV'),
version: envStr('OZONE_VERSION'),
port: envInt('OZONE_PORT'),
publicUrl: envStr('OZONE_PUBLIC_URI'),
publicUrl: envStr('OZONE_PUBLIC_URL'),
serverDid: envStr('OZONE_SERVER_DID'),
appviewUrl: envStr('OZONE_APPVIEW_URL'),
appviewDid: envStr('OZONE_APPVIEW_DID'),
Expand All @@ -14,7 +14,6 @@ export const readEnv = (): OzoneEnvironment => {
dbPostgresUrl: envStr('OZONE_DB_POSTGRES_URL'),
dbPostgresSchema: envStr('OZONE_DB_POSTGRES_SCHEMA'),
didPlcUrl: envStr('OZONE_DID_PLC_URL'),
labelerDid: envStr('OZONE_'),
adminPassword: envStr('OZONE_ADMIN_PASSWORD'),
moderatorPassword: envStr('OZONE_MODERATOR_PASSWORD'),
triagePassword: envStr('OZONE_TRIAGE_PASSWORD'),
Expand All @@ -35,7 +34,6 @@ export type OzoneEnvironment = {
dbPostgresUrl?: string
dbPostgresSchema?: string
didPlcUrl?: string
labelerDid?: string
adminPassword?: string
moderatorPassword?: string
triagePassword?: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`moderation-events get event gets an event by specific id 1`] = `
Object {
"createdAt": "1970-01-01T00:00:00.000Z",
"createdBy": "did:example:labeler",
"createdBy": "user(2)",
"event": Object {
"$type": "com.atproto.admin.defs#modEventLabel",
"comment": "[AutoModerator]: Applying labels",
Expand Down
8 changes: 4 additions & 4 deletions packages/ozone/tests/moderation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ describe('moderation', () => {
}
const modService = ctx.modService(ctx.db)
await modService.formatAndCreateLabels(
ctx.cfg.service.labelerDid,
ctx.cfg.service.did,
post.uriStr,
post.cidStr,
{ create: ['kittens'] },
Expand All @@ -465,7 +465,7 @@ describe('moderation', () => {
await expect(getRecordLabels(post.uriStr)).resolves.toEqual(['kittens'])
// Cleanup
await modService.formatAndCreateLabels(
ctx.cfg.service.labelerDid,
ctx.cfg.service.did,
post.uriStr,
post.cidStr,
{ negate: ['kittens'] },
Expand Down Expand Up @@ -498,7 +498,7 @@ describe('moderation', () => {
await expect(getRecordLabels(post.uriStr)).resolves.toEqual(['bears'])
// Cleanup
await modService.formatAndCreateLabels(
ctx.cfg.service.labelerDid,
ctx.cfg.service.did,
post.uriStr,
post.cidStr,
{ negate: ['bears'] },
Expand Down Expand Up @@ -560,7 +560,7 @@ describe('moderation', () => {
const { ctx } = ozone
const modService = ctx.modService(ctx.db)
await modService.formatAndCreateLabels(
ctx.cfg.service.labelerDid,
ctx.cfg.service.did,
sc.dids.bob,
null,
{ create: ['kittens'] },
Expand Down

0 comments on commit de48f83

Please sign in to comment.