2020-07-28 12:39:54 +00:00
|
|
|
import { Ini } from "./deps.ts";
|
|
|
|
|
2020-07-28 13:56:02 +00:00
|
|
|
import { FS } from "./deps.ts";
|
|
|
|
|
2020-07-28 12:39:54 +00:00
|
|
|
const config =
|
|
|
|
Ini.decode(
|
2020-07-28 13:56:02 +00:00
|
|
|
await Deno.readFile("./config.ini")
|
2020-07-28 13:35:50 +00:00
|
|
|
.then((e) => new TextDecoder().decode(e))
|
|
|
|
.catch((err) => {
|
|
|
|
if (!(err instanceof Deno.errors.NotFound)) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
})
|
2020-07-28 12:39:54 +00:00
|
|
|
) || {};
|
|
|
|
|
2020-07-28 13:35:50 +00:00
|
|
|
const env = Deno.env.toObject();
|
|
|
|
|
|
|
|
for (const key in env) {
|
|
|
|
if (key.startsWith("DENREG_")) {
|
|
|
|
const stripped = key.slice(7);
|
|
|
|
if (stripped.startsWith("USER_")) {
|
|
|
|
const username = stripped.slice(5);
|
|
|
|
const password = env[key];
|
|
|
|
|
|
|
|
config.user = config.user || {};
|
|
|
|
config.user[username] = { password };
|
|
|
|
} else {
|
|
|
|
switch (stripped) {
|
|
|
|
case "S3_ENDPOINT":
|
|
|
|
config.s3 = { ...(config.s3 || {}), endpoint: env[key] };
|
|
|
|
break;
|
|
|
|
case "S3_BUCKET":
|
|
|
|
config.s3 = { ...(config.s3 || {}), bucket: env[key] };
|
|
|
|
break;
|
|
|
|
case "S3_ACCESS":
|
|
|
|
config.s3 = { ...(config.s3 || {}), accessKey: env[key] };
|
|
|
|
break;
|
|
|
|
case "S3_SECRET":
|
|
|
|
config.s3 = { ...(config.s3 || {}), secretKey: env[key] };
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log("Known users:", Object.keys(config.user));
|
|
|
|
|
2020-07-28 12:39:54 +00:00
|
|
|
export default config;
|