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 40 additions and 0 deletions
Showing only changes of commit 61cb8f4941 - Show all commits

View File

@@ -113,6 +113,7 @@ services:
- ./docker/strfry/strfry.conf:/etc/strfry.conf
- ./extras/strfry/ldap-policy.ts:/opt/ldap-policy.ts
- ./extras/strfry/strfry-policy.ts:/opt/strfry-policy.ts
- ./extras/strfry/strfry-sync.ts:/opt/strfry-sync.ts
- strfry-data:/var/lib/strfry
networks:
- external_network

View File

@@ -0,0 +1,39 @@
import { load } from "https://deno.land/std@0.224.0/dotenv/mod.ts";
import { Client } from 'npm:ldapts';
const dirname = new URL('.', import.meta.url).pathname;
await load({ envPath: `${dirname}/.env`, export: true });
const opts = {
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"),
relayUrl: Deno.args[0]
}
const client = new Client({ url: opts.url });
try {
await client.bind(opts.bindDN, opts.password);
const { searchEntries } = await client.search(opts.searchDN, {
filter: `(nostrKey=*)`,
attributes: ['nostrKey']
});
const pubkeys = searchEntries.map(e => e.nostrKey);
const filter = JSON.stringify({ authors: pubkeys });
const p = Deno.run({ cmd: [
"strfry", "sync", opts.relayUrl,
"--dir", "down", "--filter", filter
]});
const result = await p.status();
Deno.exit(result.code);
} catch (ex) {
console.error(ex);
Deno.exit(1);
}