Skip to content

Commit

Permalink
add --enable-federation-control flag to STH
Browse files Browse the repository at this point in the history
  • Loading branch information
patuwwy committed Apr 6, 2023
1 parent 7d0f83f commit ba0327a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
22 changes: 17 additions & 5 deletions packages/host/src/lib/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ export class Host implements IComponent {

this.config.host.id ||= this.getId();
this.logger.updateBaseLog({ id: this.config.host.id });

this.serviceDiscovery.logger.pipe(this.logger);

if (sthConfig.telemetry.environment)
Expand Down Expand Up @@ -556,18 +557,29 @@ export class Host implements IComponent {
* @param {NextCallback} _next Function to call when request is not handled by Instance middleware.
*/
spaceMiddleware(req: ParsedMessage, res: ServerResponse, _next: NextCallback) {
if (!this.config.host.federationControl) {
res.statusCode = 403;
res.end();
return;
}

const url = req.url!.replace(`${this.apiBase}/cpm/api/v1/`, "");

this.logger.info("SPACE REQUEST", req.url, url);

const clientRequest = this.cpmConnector?.makeHttpRequestToCpm(req.method!, url);

clientRequest?.on("response", (response: IncomingMessage) => {
response.pipe(res);
});
if (clientRequest) {
clientRequest?.on("response", (response: IncomingMessage) => {
response.pipe(res);
});

clientRequest?.flushHeaders();
req.pipe(clientRequest!);
clientRequest.flushHeaders();
req.pipe(clientRequest);
} else {
res.statusCode = 404;
res.end();
}
}

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/sth-config/src/config-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ const _defaultConfig: STHConfiguration = {
infoFilePath: "/tmp/sth-id.json",
instancesServerPort: 8001,
hostname: "::",
port: 8000
port: 8000,
federationControl: false
},
instanceRequirements: {
cpuLoad: 10,
Expand Down
4 changes: 3 additions & 1 deletion packages/sth/src/bin/hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const options: OptionValues & STHCommandOptions = program
.option("--k8s-runner-resources-limits-memory <memory>", "Set limits for memory e.g [128974848, 129e6, 129M, 128974848000m, 123Mi]")
.option("--environment-name <name>", "Sets the environment name for telemetry reporting (defaults to SCP_ENV_VALUE env var or 'not-set')")
.option("--no-telemetry", "Disables telemetry", false)
.option("--enable-federation-control", "Enables federation control", false)
.parse(process.argv)
.opts() as STHCommandOptions;

Expand Down Expand Up @@ -105,7 +106,8 @@ const options: OptionValues & STHCommandOptions = program
instancesServerPort: options.instancesServerPort ? parseInt(options.instancesServerPort, 10) : undefined,
port: options.port,
hostname: options.hostname,
id: options.id
id: options.id,
federationControl: options.enableFederationControl
},
runtimeAdapter: getRuntimeAdapterOption(options),
sequencesRoot: resolveFile(options.sequencesRoot),
Expand Down
4 changes: 3 additions & 1 deletion packages/types/src/sth-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export type HostConfig = {
* Host information filepath.
*/
infoFilePath: string;

federationControl: boolean;
}

export type K8SAdapterConfiguration = {
Expand Down Expand Up @@ -243,7 +245,7 @@ export type STHConfiguration = {
instanceLifetimeExtensionDelay: number;
};

telemetry: TelemetryConfig
telemetry: TelemetryConfig;
}

export type PublicSTHConfiguration = Omit<Omit<Omit<STHConfiguration, "sequencesRoot">, "cpmSslCaPath">, "kubernetes"> & {
Expand Down

0 comments on commit ba0327a

Please sign in to comment.