Add config migrations (#693)

Co-authored-by: Danielv123 <danielv@danielv.no>
This commit is contained in:
Cooldude2606andDanielv123 authored and GitHub committed 2024-11-26 23:14:56 +00:00
1 parent 05ca4eb25e
commit 4248e57dcb
7 files changed
+43 -9

No files matched your search

+1 -1
View File
@@ -1115,7 +1115,7 @@ export default class Controller {
}
static calculateControllerUrl(config: lib.ControllerConfig) {
let url = config.get("controller.external_address");
let url = config.get("controller.public_url");
if (!url) {
if (config.get("controller.https_port")) {
url = `https://localhost:${config.get("controller.https_port")}/`;
+11 -1
View File
@@ -187,6 +187,16 @@ export class Config<
declare static fieldDefinitions: ConfigDefs<any>;
declare ["constructor"]: typeof Config;
/**
* Handle migration between clusterio versions
*
* @param config - Input config read and validated from file
* @returns Output config to be loaded into the class
* @protected
*/
static migrations(config: Static<typeof this.jsonSchema>) {
return config;
}
fields: Fields;
_unknownFields: Record<string, FieldValue> = {};
@@ -223,7 +233,7 @@ export class Config<
) as Fields;
if (fields) {
this.update(fields, false, location);
this.update(this.constructor.migrations(fields), false, location);
}
}
+12 -3
View File
@@ -1,7 +1,7 @@
// Core definitions for the configuration system
import * as classes from "./classes";
import type { PluginNodeEnvInfo, PluginWebpackEnvInfo } from "../plugin";
import { Static } from "@sinclair/typebox";
export interface ControllerConfigFields {
"controller.name": string;
@@ -11,7 +11,7 @@ export interface ControllerConfigFields {
"controller.https_port": number | null;
"controller.bind_address": string | null;
"controller.trusted_proxies": string | null;
"controller.external_address": string | null;
"controller.public_url": string | null;
"controller.tls_certificate": string | null;
"controller.tls_private_key": string | null;
"controller.auth_secret": string;
@@ -34,6 +34,15 @@ export interface ControllerConfigFields {
*/
export class ControllerConfig extends classes.Config<ControllerConfigFields> {
declare static fromJSON: (json: classes.ConfigSchema, location: classes.ConfigLocation) => ControllerConfig;
static migrations(config: Static<typeof this.jsonSchema>) {
if (config.hasOwnProperty("controller.external_address")) {
config["controller.public_url"] = config["controller.external_address"];
delete config["controller.external_address"];
}
return config;
}
static fieldDefinitions: classes.ConfigDefs<ControllerConfigFields> = {
"controller.name": {
title: "Name",
@@ -89,7 +98,7 @@ export class ControllerConfig extends classes.Config<ControllerConfigFields> {
type: "string",
optional: true,
},
"controller.external_address": {
"controller.public_url": {
title: "Public URL",
description: "Public facing URL the controller is hosted on, including the protocol.",
type: "string",