54 lines
1.7 KiB
TypeScript
54 lines
1.7 KiB
TypeScript
|
// This file contains logic to connect to a servezone cloudly instance
|
||
|
// The connection is done using websockets to have an always open channel
|
||
|
// that is bidirectional
|
||
|
|
||
|
import * as plugins from './coreflow.plugins.js';
|
||
|
import { Coreflow } from './coreflow.classes.coreflow.js';
|
||
|
|
||
|
export class CloudlyConnector {
|
||
|
public coreflowRef: Coreflow;
|
||
|
public cloudlyClient: plugins.servezoneApi.CloudlyClient;
|
||
|
public coreflowJumpCode: string;
|
||
|
public identity: plugins.servezoneInterfaces.data.IClusterIdentifier;
|
||
|
|
||
|
constructor(coreflowRefArg: Coreflow) {
|
||
|
this.coreflowRef = coreflowRefArg;
|
||
|
}
|
||
|
|
||
|
public async start() {
|
||
|
this.cloudlyClient = new plugins.servezoneApi.CloudlyClient('coreflow');
|
||
|
await this.cloudlyClient.start();
|
||
|
this.coreflowJumpCode = await this.coreflowRef.serviceQenv.getEnvVarOnDemand('JUMPCODE');
|
||
|
|
||
|
// get identity and tag connection (second parameter is true -> tags the connection)
|
||
|
this.identity = await this.cloudlyClient.getIdentityByJumpCode(this.coreflowJumpCode, true);
|
||
|
}
|
||
|
|
||
|
public async stop() {
|
||
|
await this.cloudlyClient.stop();
|
||
|
}
|
||
|
|
||
|
public async getConfigFromCloudly(): Promise<plugins.servezoneInterfaces.data.IClusterConfig> {
|
||
|
const config = await this.cloudlyClient.getClusterConfigFromCloudlyByIdentity(
|
||
|
this.identity
|
||
|
);
|
||
|
return config;
|
||
|
}
|
||
|
|
||
|
public async triggerConfigEvent() {
|
||
|
const config = await this.getConfigFromCloudly();
|
||
|
this.cloudlyClient.configUpdateSubject.next({
|
||
|
configData: config,
|
||
|
});
|
||
|
}
|
||
|
|
||
|
public async getCertificateForDomainFromCloudly(
|
||
|
domainNameArg: string
|
||
|
): Promise<plugins.tsclass.network.ICert> {
|
||
|
const certificate = await this.cloudlyClient.getCertificateForDomainOverHttps(
|
||
|
domainNameArg
|
||
|
);
|
||
|
return certificate;
|
||
|
}
|
||
|
}
|