Add strfry policies and members-only LDAP policy #196

Merged
raucao merged 5 commits from feature/strfry_policies into master 2024-06-11 20:10:34 +00:00
2 changed files with 22 additions and 12 deletions
Showing only changes of commit 2a675fd135 - Show all commits

View File

@ -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<void> = async (msg) => {
const client = new Client({ url });
const ldapPolicy: Policy<LdapConfig> = 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']
});

View File

@ -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);