Skip to content

Commit

Permalink
stripping authlimit
Browse files Browse the repository at this point in the history
  • Loading branch information
Bossett committed Sep 6, 2024
1 parent a8fe76e commit 617b8a0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 61 deletions.
26 changes: 4 additions & 22 deletions src/emitAccountReport.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { agent, reauth, agentDid } from '@/lib/bskyAgent.js'
import { agent, agentDid } from '@/lib/bskyAgent.js'
import { ToolsOzoneModerationEmitEvent } from '@atproto/api'
import logger from '@/helpers/logger.js'
import env from '@/env/env.js'
Expand All @@ -7,7 +7,6 @@ import { pdsLimit } from '@/env/rateLimit.js'

export default async function emitAccountReport(
eventInput: ToolsOzoneModerationEmitEvent.InputSchema,
isRetry = false,
): Promise<boolean> {
if (env.DANGEROUSLY_EXPOSE_SECRETS) {
logger.debug(
Expand All @@ -26,26 +25,9 @@ export default async function emitAccountReport(
.api.tools.ozone.moderation.emitEvent(eventInput),
)
} catch (e) {
if (
e.message === 'queue maxDelay timeout exceeded' ||
`${e}` === 'Error: TypeError: fetch failed'
)
return false

if (isRetry) {
logger.warn(`${e.message} from emitAccountReport failed after re-auth`)
return false
}

try {
await reauth(agent)
} catch (e) {
logger.warn(
`${e.message} from emitAccountReport failed attempting re-auth`,
)
throw e
}
return emitAccountReport(eventInput, true)
logger.warn(`${e.message} from emitAccountReport failed`)
return false
}

return true
}
5 changes: 0 additions & 5 deletions src/env/limits.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
const limits = {
// ***** RATE LIMITERS *****
// the rate limiter for agent login attempts
AUTH_LIMIT_MAX_CONCURRENT: 1,
AUTH_LIMIT_MAX_DELAY_MS: undefined,
AUTH_LIMIT_MAX_RATE: 8,
AUTH_LIMIT_RATE_INTERVAL_MS: 40 * 60 * 1000,
// rate limiter for authed request
PDS_LIMIT_MAX_CONCURRENT: 256,
PDS_LIMIT_MAX_DELAY_MS: undefined,
Expand Down
7 changes: 0 additions & 7 deletions src/env/rateLimit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,3 @@ export const publicLimit = pRateLimit({
concurrency: env.limits.PUBLIC_LIMIT_MAX_CONCURRENT,
maxDelay: env.limits.PUBLIC_LIMIT_MAX_DELAY_MS,
})

export const authLimit = pRateLimit({
interval: env.limits.AUTH_LIMIT_RATE_INTERVAL_MS,
rate: env.limits.AUTH_LIMIT_MAX_RATE,
concurrency: env.limits.AUTH_LIMIT_MAX_CONCURRENT,
maxDelay: env.limits.AUTH_LIMIT_MAX_DELAY_MS,
})
38 changes: 11 additions & 27 deletions src/lib/bskyAgent.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,23 @@
import { BskyAgent } from '@atproto/api'
import env from '@/env/env.js'

import { authLimit } from '@/env/rateLimit.js'

const _agent = new BskyAgent({ service: env.LABELLER_SERVICE })

const _reauth = async (agent: BskyAgent) => {
try {
await authLimit(
async () =>
await agent.login({
identifier: env.LABELLER_HANDLE,
password: env.LABELLER_PASSWORD,
}),
)
} catch (e) {
return false
}
return true
}

if (!(await _reauth(_agent))) throw 'Agent Authentication Failed'
await _agent.login({
identifier: env.LABELLER_HANDLE,
password: env.LABELLER_PASSWORD,
})

export const agentDid: string = (
await authLimit(
async () =>
await _agent.com.atproto.identity.resolveHandle({
handle: env.LABELLER_HANDLE,
}),
)
).data.did
export const agentDid: string = `${
(
await _agent.com.atproto.identity.resolveHandle({
handle: env.LABELLER_HANDLE,
})
).data.did
}`

BskyAgent.configure({
appLabelers: [agentDid],
})

export const agent: BskyAgent = _agent
export const reauth = _reauth

0 comments on commit 617b8a0

Please sign in to comment.