Test Ldap
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
b9cd0f6b66
commit
b06189f5f3
33
lib/team.ts
33
lib/team.ts
|
@ -2,10 +2,14 @@ import { readFile, readdir, access } from "fs/promises";
|
|||
import path from "path";
|
||||
|
||||
import matter from "gray-matter";
|
||||
import { Client } from "ldapts";
|
||||
import { serialize } from "next-mdx-remote/serialize";
|
||||
|
||||
import { getCurrentTerm } from "@/lib/events";
|
||||
|
||||
const EXECS_PATH = path.join("content", "team", "execs");
|
||||
const fileType = ".md";
|
||||
const { year, term } = getCurrentTerm();
|
||||
|
||||
export interface Metadata {
|
||||
name: string;
|
||||
|
@ -13,10 +17,39 @@ export interface Metadata {
|
|||
image: string;
|
||||
}
|
||||
|
||||
// export async function getExecNames() {
|
||||
// return (await readdir(EXECS_PATH))
|
||||
// .filter((name) => name.endsWith(fileType))
|
||||
// .map((name) => name.slice(0, -1 * fileType.length));
|
||||
// }
|
||||
|
||||
export async function getExecNames() {
|
||||
if (process.env.USE_LDAP?.toLowerCase() !== "true") {
|
||||
return (await readdir(EXECS_PATH))
|
||||
.filter((name) => name.endsWith(fileType))
|
||||
.map((name) => name.slice(0, -1 * fileType.length));
|
||||
}
|
||||
|
||||
const url = "ldap://ldap1.csclub.uwaterloo.ca";
|
||||
const searchDN = "ou=People,dc=csclub,dc=uwaterloo,dc=ca";
|
||||
const client = new Client({ url });
|
||||
|
||||
try {
|
||||
await client.bind("", "");
|
||||
const { searchEntries } = await client.search(searchDN, {
|
||||
scope: "sub",
|
||||
filter: `(&(objectClass=member)(term=${(term as string).slice(
|
||||
0,
|
||||
1
|
||||
)}${year})(exec=True))`,
|
||||
});
|
||||
|
||||
const execMembers = searchEntries.map((item) => item.cn as string);
|
||||
} finally {
|
||||
await client.unbind();
|
||||
}
|
||||
|
||||
return execMembers;
|
||||
}
|
||||
|
||||
export async function getExec(fileName: string, convert = true) {
|
||||
|
|
Loading…
Reference in New Issue