Add alternative default path for users config
This commit is contained in:
parent
52d56c387d
commit
e921fb2d84
21
config.ts
21
config.ts
@ -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");
|
||||
|
Loading…
x
Reference in New Issue
Block a user