diff --git a/extras/strfry/ldap-policy.ts b/extras/strfry/ldap-policy.ts index 6ac8fda..a200639 100644 --- a/extras/strfry/ldap-policy.ts +++ b/extras/strfry/ldap-policy.ts @@ -1,22 +1,22 @@ import type { Policy } from 'https://gitlab.com/soapbox-pub/strfry-policies/-/raw/develop/mod.ts'; import { Client } from 'npm:ldapts'; -import { load } from "https://deno.land/std@0.224.0/dotenv/mod.ts"; -const env = await load({ export: true }); -const url = Deno.env.get("LDAP_URL"); -const bindDN = Deno.env.get("LDAP_BIND_DN"); -const password = Deno.env.get("LDAP_PASSWORD"); -const searchDN = Deno.env.get("LDAP_SEARCH_DN"); +interface LdapConfig { + url: string; + bindDN: string; + password: string; + searchDN: string; +} -const ldapPolicy: Policy = async (msg) => { - const client = new Client({ url }); +const ldapPolicy: Policy = async (msg, opts) => { + const client = new Client({ url: opts.url }); const { pubkey, kind, tags } = msg.event; let out = { id: msg.event.id } try { - await client.bind(bindDN, password); + await client.bind(opts.bindDN, opts.password); - const { searchEntries } = await client.search(searchDN, { + const { searchEntries } = await client.search(opts.searchDN, { filter: `(nostrKey=${pubkey})`, attributes: ['nostrKey'] }); diff --git a/extras/strfry/strfry-policy.ts b/extras/strfry/strfry-policy.ts index 0838170..15fafe9 100755 --- a/extras/strfry/strfry-policy.ts +++ b/extras/strfry/strfry-policy.ts @@ -8,15 +8,25 @@ import { readStdin, writeStdout, } from 'https://gitlab.com/soapbox-pub/strfry-policies/-/raw/develop/mod.ts'; - import ldapPolicy from './ldap-policy.ts'; +import { load } from "https://deno.land/std@0.224.0/dotenv/mod.ts"; + +const dirname = new URL('.', import.meta.url).pathname; +await load({ envPath: `${dirname}/.env`, export: true }); + +const ldapConfig = { + url: Deno.env.get("LDAP_URL"), + bindDN: Deno.env.get("LDAP_BIND_DN"), + password: Deno.env.get("LDAP_PASSWORD"), + searchDN: Deno.env.get("LDAP_SEARCH_DN"), +} for await (const msg of readStdin()) { const result = await pipeline(msg, [ [hellthreadPolicy, { limit: 10 }], [antiDuplicationPolicy, { ttl: 60000, minLength: 50 }], [rateLimitPolicy, { whitelist: ['127.0.0.1'] }], - [ldapPolicy], + [ldapPolicy, ldapConfig], ]); writeStdout(result);