Return members
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
597f1961c4
commit
615aa3f95f
|
@ -0,0 +1,48 @@
|
|||
import { Client } from "ldapts";
|
||||
|
||||
interface MemberItem {
|
||||
name: string;
|
||||
id: string;
|
||||
program: string;
|
||||
}
|
||||
|
||||
// note: the term parameter is different due to the way the LDAP database is structured
|
||||
export async function getMembers(
|
||||
year: string,
|
||||
term: "w" | "s" | "f"
|
||||
): Promise<MemberItem[]> {
|
||||
let members: MemberItem[] = [];
|
||||
|
||||
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}${year}))`,
|
||||
});
|
||||
|
||||
members = searchEntries
|
||||
.map((item) => {
|
||||
return {
|
||||
name: item.cn as string,
|
||||
id: item.uid as string,
|
||||
program: item.program === undefined ? "" : (item.program as string),
|
||||
};
|
||||
})
|
||||
.sort((item1: MemberItem, item2: MemberItem) =>
|
||||
item1.id.localeCompare(item2.id)
|
||||
);
|
||||
}
|
||||
// catch (ex) {
|
||||
// throw ex;
|
||||
// }
|
||||
finally {
|
||||
await client.unbind();
|
||||
}
|
||||
|
||||
return members;
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
import { getMembers } from "./ldap";
|
||||
|
||||
const main = async () => {
|
||||
const members = await getMembers("2020", "w");
|
||||
console.log(members);
|
||||
};
|
||||
|
||||
void main();
|
File diff suppressed because it is too large
Load Diff
|
@ -14,7 +14,6 @@
|
|||
"lint": "eslint \"{pages,components,lib,hooks,scripts}/**/*.{js,ts,tsx,jsx}\" --quiet",
|
||||
"lint:fix": "eslint \"{pages,components,lib,hooks,scripts}/**/*.{js,ts,tsx,jsx}\" --quiet --fix",
|
||||
"generate:calendar": "ts-node ./scripts/generate-calendar",
|
||||
"generate:members": "ts-node ./scripts/generate-members",
|
||||
"check-lockfile": "ts-node ./scripts/check-lockfile"
|
||||
},
|
||||
"dependencies": {
|
||||
|
@ -23,7 +22,6 @@
|
|||
"@next/mdx": "11.0.1",
|
||||
"@types/ldapjs": "^2.2.1",
|
||||
"date-fns": "^2.11.1",
|
||||
"ldapjs": "^2.3.1",
|
||||
"ldapts": "^3.1.0",
|
||||
"next": "11.0.1",
|
||||
"next-mdx-remote": "3.0.4",
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
// import ldap from "ldapjs";
|
||||
import { Client } from "ldapts";
|
||||
|
||||
export async function getMembers(year: string, term: string) {
|
||||
// LDAPJS
|
||||
// const client = ldap.createClient({
|
||||
// url: [
|
||||
// "ldap://ldap1.csclub.uwaterloo.ca",
|
||||
// "ldap://ldap2.csclub.uwaterloo.ca",
|
||||
// ],
|
||||
// });
|
||||
// client.bind("cn=root", "", (err) => {
|
||||
// throw err;
|
||||
// });
|
||||
// const opts = {
|
||||
// filter: `(&(objectClass=member)(term=${term}${year}))`,
|
||||
// // scope: "sub",
|
||||
// // attributes: ["dn", "sn", "cn"],
|
||||
// };
|
||||
// client.search("ou=People,dc=csclub,dc=uwaterloo,dc=ca", opts, (err, res) => {
|
||||
// console.log("h3");
|
||||
// res.on("searchEntry", (entry) => {
|
||||
// console.log("entry: " + JSON.stringify(entry.object));
|
||||
// });
|
||||
// });
|
||||
// client.unbind();
|
||||
|
||||
// LDAPTS
|
||||
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("cn=root", "secret");
|
||||
const { searchEntries, searchReferences } = await client.search(searchDN, {
|
||||
scope: "sub",
|
||||
filter: `(&(objectClass=member)(term=${term}${year}))`,
|
||||
});
|
||||
} catch (ex) {
|
||||
throw ex;
|
||||
} finally {
|
||||
await client.unbind();
|
||||
}
|
||||
}
|
||||
|
||||
void getMembers("2020", "winter");
|
Loading…
Reference in New Issue