Add alternative default path for users config

This commit is contained in:
Râu Cao 2024-10-23 01:03:55 +02:00
parent 52d56c387d
commit e921fb2d84
Signed by: raucao
GPG Key ID: 37036C356E56CC51

View File

@ -1,15 +1,30 @@
import { load } from "@std/dotenv";
import { parse } from "jsr:@std/yaml";
import { parse as parseYaml } from "jsr:@std/yaml";
import { log } from "./log.ts";
const dirname = Deno.cwd();
await load({ envPath: `${dirname}/.env`, export: true });
let userConfigPath: string = '';
let staticUsers: { [key: string]: string } = {};
const defaultUserConfigPaths = [
"/etc/substr/users.yaml",
`${dirname}/users.yaml`
]
for (const path of defaultUserConfigPaths) {
const fileInfo = await Deno.lstat(path).catch(_e => undefined);
if (fileInfo && fileInfo.isFile) {
userConfigPath = path;
break;
}
}
try {
const yamlContent = await Deno.readTextFile(`${dirname}/users.yaml`);
const parsedContent = parse(yamlContent);
const fileContent = await Deno.readTextFile(userConfigPath);
const parsedContent = parseYaml(fileContent);
if (parsedContent !== null && typeof parsedContent === "object") {
staticUsers = parsedContent as { [key: string]: string };
log(`Serving content for pubkeys in users.yaml`, "blue");