feat: expose dcrouter gateway settings
This commit is contained in:
@@ -2,6 +2,8 @@ import * as plugins from '../../plugins.ts';
|
||||
import type { OpsServer } from '../classes.opsserver.ts';
|
||||
import * as interfaces from '../../../ts_interfaces/index.ts';
|
||||
import { requireAdminIdentity } from '../helpers/guards.ts';
|
||||
import { logger } from '../../logging.ts';
|
||||
import { getErrorMessage } from '../../utils/error.ts';
|
||||
|
||||
export class SettingsHandler {
|
||||
public typedrouter = new plugins.typedrequest.TypedRouter();
|
||||
@@ -65,6 +67,12 @@ export class SettingsHandler {
|
||||
}
|
||||
}
|
||||
|
||||
if (this.hasExternalGatewaySetting(updates)) {
|
||||
this.refreshExternalGateway().catch((error) => {
|
||||
logger.warn(`External gateway settings refresh failed: ${getErrorMessage(error)}`);
|
||||
});
|
||||
}
|
||||
|
||||
const settings = await this.getSettingsObject();
|
||||
return { settings };
|
||||
},
|
||||
@@ -93,4 +101,28 @@ export class SettingsHandler {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
private hasExternalGatewaySetting(settings: Partial<interfaces.data.ISettings>): boolean {
|
||||
return [
|
||||
'dcrouterGatewayUrl',
|
||||
'dcrouterGatewayApiToken',
|
||||
'dcrouterWorkHosterId',
|
||||
'dcrouterTargetHost',
|
||||
'dcrouterTargetPort',
|
||||
].some((key) => Object.prototype.hasOwnProperty.call(settings, key));
|
||||
}
|
||||
|
||||
private async refreshExternalGateway(): Promise<void> {
|
||||
const onebox = this.opsServerRef.oneboxRef;
|
||||
await onebox.externalGateway.syncDomains();
|
||||
|
||||
const services = onebox.database.getAllServices().filter((service) => service.domain);
|
||||
await Promise.all(services.map(async (service) => {
|
||||
try {
|
||||
await onebox.externalGateway.syncServiceRoute(service);
|
||||
} catch (error) {
|
||||
logger.warn(`Failed to sync external gateway route for ${service.domain}: ${getErrorMessage(error)}`);
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user