Hand LDAP config to policy from main policy file
Deployments will differ in production. The policy itself just needs the configs, but should not care where credentials are fetched from.
This commit is contained in:
parent
c2c3ebc2e1
commit
2a675fd135
@ -1,22 +1,22 @@
|
|||||||
import type { Policy } from 'https://gitlab.com/soapbox-pub/strfry-policies/-/raw/develop/mod.ts';
|
import type { Policy } from 'https://gitlab.com/soapbox-pub/strfry-policies/-/raw/develop/mod.ts';
|
||||||
import { Client } from 'npm:ldapts';
|
import { Client } from 'npm:ldapts';
|
||||||
import { load } from "https://deno.land/std@0.224.0/dotenv/mod.ts";
|
|
||||||
|
|
||||||
const env = await load({ export: true });
|
interface LdapConfig {
|
||||||
const url = Deno.env.get("LDAP_URL");
|
url: string;
|
||||||
const bindDN = Deno.env.get("LDAP_BIND_DN");
|
bindDN: string;
|
||||||
const password = Deno.env.get("LDAP_PASSWORD");
|
password: string;
|
||||||
const searchDN = Deno.env.get("LDAP_SEARCH_DN");
|
searchDN: string;
|
||||||
|
}
|
||||||
|
|
||||||
const ldapPolicy: Policy<void> = async (msg) => {
|
const ldapPolicy: Policy<LdapConfig> = async (msg, opts) => {
|
||||||
const client = new Client({ url });
|
const client = new Client({ url: opts.url });
|
||||||
const { pubkey, kind, tags } = msg.event;
|
const { pubkey, kind, tags } = msg.event;
|
||||||
let out = { id: msg.event.id }
|
let out = { id: msg.event.id }
|
||||||
|
|
||||||
try {
|
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})`,
|
filter: `(nostrKey=${pubkey})`,
|
||||||
attributes: ['nostrKey']
|
attributes: ['nostrKey']
|
||||||
});
|
});
|
||||||
|
@ -8,15 +8,25 @@ import {
|
|||||||
readStdin,
|
readStdin,
|
||||||
writeStdout,
|
writeStdout,
|
||||||
} from 'https://gitlab.com/soapbox-pub/strfry-policies/-/raw/develop/mod.ts';
|
} from 'https://gitlab.com/soapbox-pub/strfry-policies/-/raw/develop/mod.ts';
|
||||||
|
|
||||||
import ldapPolicy from './ldap-policy.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()) {
|
for await (const msg of readStdin()) {
|
||||||
const result = await pipeline(msg, [
|
const result = await pipeline(msg, [
|
||||||
[hellthreadPolicy, { limit: 10 }],
|
[hellthreadPolicy, { limit: 10 }],
|
||||||
[antiDuplicationPolicy, { ttl: 60000, minLength: 50 }],
|
[antiDuplicationPolicy, { ttl: 60000, minLength: 50 }],
|
||||||
[rateLimitPolicy, { whitelist: ['127.0.0.1'] }],
|
[rateLimitPolicy, { whitelist: ['127.0.0.1'] }],
|
||||||
[ldapPolicy],
|
[ldapPolicy, ldapConfig],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
writeStdout(result);
|
writeStdout(result);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user