34 lines
835 B
TypeScript
34 lines
835 B
TypeScript
import config from "./config.ts";
|
|
import { lookupUsernameByPubkey as ldapLookupUsername } from "./ldap.ts";
|
|
import { lookupPubkeyByUsername as ldapLookupPubkey } from "./ldap.ts";
|
|
|
|
export async function lookupUsernameByPubkey(pubkey: string): Promise<string | undefined> {
|
|
let username;
|
|
for (const [key, value] of Object.entries(config.staticUsers)) {
|
|
if (value === pubkey) {
|
|
username = key;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (username) {
|
|
return username;
|
|
} else {
|
|
if (config.ldapEnabled) {
|
|
return ldapLookupUsername(pubkey);
|
|
}
|
|
}
|
|
}
|
|
|
|
export async function lookupPubkeyByUsername(username: string): Promise<string | undefined> {
|
|
const pubkey = config.staticUsers[username];
|
|
|
|
if (pubkey) {
|
|
return pubkey;
|
|
} else {
|
|
if (config.ldapEnabled) {
|
|
return ldapLookupPubkey(username);
|
|
}
|
|
}
|
|
}
|