Implement shared Factorio credentials

Add config entries to controller and host for the Factorio username and
token to use when talking to the Factorio APIs.  If set an username and
token is not set in factorio.settings then these settings are used,
making it easy to configure one set of credentials for a cluster/host.

For running more public provide your own hardware clusters, there's an
option to disable controller sharing the credential with the hosts so
that each host have to set their own credentials.
This commit is contained in:
Hornwitser committed 2024-09-16 23:23:21 +02:00
1 parent eedf5b8f67
commit 44e5847a1d
7 files changed
+130 -38

No files matched your search

+43
View File
@@ -20,6 +20,9 @@ export interface ControllerConfigFields {
"controller.metrics_timeout": number;
"controller.system_metrics_interval": number;
"controller.proxy_stream_timeout": number;
"controller.factorio_username": string | null;
"controller.factorio_token": string | null;
"controller.share_factorio_credentials_with_hosts": boolean;
"controller.default_mod_pack_id": number | null;
"controller.default_role_id": number | null;
"controller.autosave_interval": number;
@@ -147,6 +150,27 @@ export class ControllerConfig extends classes.Config<ControllerConfigFields> {
type: "number",
initialValue: 15,
},
"controller.factorio_username": {
title: "Factorio Username",
description: "Username to authenticate with Factorio API with.",
type: "string",
optional: true,
},
"controller.factorio_token": {
title: "Factorio Token",
description: "Token to authenticate with Factorio API with.",
type: "string",
credential: ["controller"],
optional: true,
},
"controller.share_factorio_credentials_with_hosts": {
title: "Share Factorio credentials with Hosts",
description:
"If enabled, the Factorio Username and Token will be shared with hosts and " +
"used in the server settings of instances in this cluster.",
type: "boolean",
initialValue: true,
},
"controller.default_mod_pack_id": {
title: "Default Mod Pack",
description: "Mod pack used by default for instances.",
@@ -175,6 +199,8 @@ export interface HostConfigFields {
"host.tls_ca": string | null;
"host.public_address": string;
"host.factorio_port_range": string;
"host.factorio_username": string | null,
"host.factorio_token": string | null,
"host.max_reconnect_delay": number;
}
@@ -245,6 +271,23 @@ export class HostConfig extends classes.Config<HostConfigFields> {
type: "string",
initialValue: "34100-34199",
},
"host.factorio_username": {
title: "Factorio Username",
description:
"Username to authenticate with Factorio API with. If set this will be used in the server settings " +
"of all instances on this host.",
type: "string",
optional: true,
},
"host.factorio_token": {
title: "Factorio Token",
description:
"Token to authenticate with Factorio API with. If set this will be used in the server settings " +
"of all instances on this host.",
type: "string",
credential: ["host"],
optional: true,
},
"host.max_reconnect_delay": {
title: "Max Reconnect Delay",
description: "Maximum delay to wait before attempting to reconnect WebSocket",
@@ -122,6 +122,18 @@ export class HostConfigCreateRequest {
static Response = plainJson(HostConfig.jsonSchema);
}
export class GetFactorioCredentialsRequest {
declare ["constructor"]: typeof GetFactorioCredentialsRequest;
static type = "request" as const;
static src = ["host", "instance"] as const;
static dst = "controller" as const;
static Response = plainJson(Type.Object({
"username": Type.Optional(Type.String()),
"token": Type.Optional(Type.String()),
}));
}
export class LogSetSubscriptionsRequest {
declare ["constructor"]: typeof LogSetSubscriptionsRequest;
static type = "request" as const;
+1
View File
@@ -24,6 +24,7 @@ export const dataClasses: (RequestClass<unknown, unknown> | EventClass<unknown>)
controller.ControllerConfigSetPropRequest,
controller.HostGenerateTokenRequest,
controller.HostConfigCreateRequest,
controller.GetFactorioCredentialsRequest,
controller.LogSetSubscriptionsRequest,
controller.LogQueryRequest,
controller.LogMessageEvent,