mirror of
https://github.com/fosrl/pangolin.git
synced 2025-05-13 05:40:38 +01:00
update badger in migration
This commit is contained in:
parent
6cc4bc2645
commit
0b7ca95d21
2 changed files with 49 additions and 3 deletions
|
@ -92,7 +92,7 @@ export async function generateAccessToken(
|
||||||
? createDate(new TimeSpan(validForSeconds, "s")).getTime()
|
? createDate(new TimeSpan(validForSeconds, "s")).getTime()
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
const token = generateIdFromEntropySize(12);
|
const token = generateIdFromEntropySize(16);
|
||||||
|
|
||||||
const tokenHash = encodeHexLowerCase(
|
const tokenHash = encodeHexLowerCase(
|
||||||
sha256(new TextEncoder().encode(token))
|
sha256(new TextEncoder().encode(token))
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
import db from "@server/db";
|
import db from "@server/db";
|
||||||
import { configFilePath1, configFilePath2 } from "@server/lib/consts";
|
import { APP_PATH, configFilePath1, configFilePath2 } from "@server/lib/consts";
|
||||||
import { sql } from "drizzle-orm";
|
import { sql } from "drizzle-orm";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import yaml from "js-yaml";
|
import yaml from "js-yaml";
|
||||||
|
import path from "path";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { fromZodError } from "zod-validation-error";
|
||||||
|
|
||||||
const version = "1.2.0";
|
const version = "1.2.0";
|
||||||
|
|
||||||
|
@ -49,7 +52,7 @@ export default async function migration() {
|
||||||
}
|
}
|
||||||
|
|
||||||
rawConfig.server.resource_access_token_headers = {
|
rawConfig.server.resource_access_token_headers = {
|
||||||
id: "P-Access-Token-ID",
|
id: "P-Access-Token-Id",
|
||||||
token: "P-Access-Token"
|
token: "P-Access-Token"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -65,5 +68,48 @@ export default async function migration() {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const traefikPath = path.join(
|
||||||
|
APP_PATH,
|
||||||
|
"traefik",
|
||||||
|
"traefik_config.yml"
|
||||||
|
);
|
||||||
|
|
||||||
|
const schema = z.object({
|
||||||
|
experimental: z.object({
|
||||||
|
plugins: z.object({
|
||||||
|
badger: z.object({
|
||||||
|
moduleName: z.string(),
|
||||||
|
version: z.string()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
const traefikFileContents = fs.readFileSync(traefikPath, "utf8");
|
||||||
|
const traefikConfig = yaml.load(traefikFileContents) as any;
|
||||||
|
|
||||||
|
const parsedConfig = schema.safeParse(traefikConfig);
|
||||||
|
|
||||||
|
if (!parsedConfig.success) {
|
||||||
|
throw new Error(fromZodError(parsedConfig.error).toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
traefikConfig.experimental.plugins.badger.version = "v1.1.0";
|
||||||
|
|
||||||
|
const updatedTraefikYaml = yaml.dump(traefikConfig);
|
||||||
|
|
||||||
|
fs.writeFileSync(traefikPath, updatedTraefikYaml, "utf8");
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
"Updated the version of Badger in your Traefik configuration to v1.1.0"
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(
|
||||||
|
"We were unable to update the version of Badger in your Traefik configuration. Please update it manually. Check the release notes for this version for more information."
|
||||||
|
);
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
|
||||||
console.log(`${version} migration complete`);
|
console.log(`${version} migration complete`);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue