fix(switch to unified package for cloudly + api + cli): update

This commit is contained in:
2024-05-28 18:45:34 +02:00
parent 33aa48b0b1
commit 21961fa2d7
40 changed files with 6531 additions and 4719 deletions

View File

@ -1,13 +1,130 @@
import * as plugins from './plugins.js';
export class CloudlyClient {
public clientToken: string;
export type TClientType = 'coreflow' | 'cli' | 'serverconfig';
constructor(clientToken: string) {
this.clientToken = clientToken;
export class CloudlyClient {
private cloudlyUrl: string;
private registerAs: string;
public typedrouter = new plugins.typedrequest.TypedRouter();
public typedsocketClient: plugins.typedsocket.TypedSocket;
// Subjects
public configUpdateSubject = new plugins.smartrx.rxjs.Subject<
plugins.servezoneInterfaces.requests.config.IRequest_Cloudly_Coreflow_PushClusterConfig['request']
>();
public serverActionSubject = new plugins.smartrx.rxjs.Subject<
plugins.servezoneInterfaces.requests.server.IRequest_TriggerServerAction['request']
>();
constructor(registerAsArg: TClientType) {
this.cloudlyUrl = process.env.CLOUDLY_URL || 'https://cloudly.layer.io:443';
this.registerAs = registerAsArg;
console.log(
`creating LoleCloudlyClient: registering as ${this.registerAs} and target url ${this.cloudlyUrl}`
);
this.typedrouter.addTypedHandler<plugins.servezoneInterfaces.requests.config.IRequest_Cloudly_Coreflow_PushClusterConfig>(
new plugins.typedrequest.TypedHandler('pushClusterConfig', async (dataArg) => {
this.configUpdateSubject.next(dataArg);
return {};
})
);
this.typedrouter.addTypedHandler<plugins.servezoneInterfaces.requests.config.IRequest_Cloudly_Coreflow_PushClusterConfig>(
new plugins.typedrequest.TypedHandler('pushClusterConfig', async (dataArg) => {
this.configUpdateSubject.next(dataArg);
return {};
})
);
this.typedrouter.addTypedHandler<plugins.servezoneInterfaces.requests.server.IRequest_TriggerServerAction>(
new plugins.typedrequest.TypedHandler('triggerServerAction', async (dataArg) => {
this.serverActionSubject.next(dataArg);
return {
actionConfirmed: true,
};
})
);
}
public async getClusters() {
public async start() {
this.typedsocketClient = await plugins.typedsocket.TypedSocket.createClient(
this.typedrouter,
this.cloudlyUrl
);
}
public async stop() {
await this.typedsocketClient.stop();
}
public async getIdentityByJumpCode(
jumpCodeArg: string,
tagConnection = false
): Promise<plugins.servezoneInterfaces.data.IClusterIdentifier> {
const identityRequest =
this.typedsocketClient.createTypedRequest<plugins.servezoneInterfaces.requests.identity.IRequest_Any_Cloudly_CoreflowManager_GetIdentityByJumpCode>(
'getIdentityByJumpCode'
);
console.log(`trying to get identity from cloudly with supplied jumpCodeArg: ${jumpCodeArg}`);
const response = await identityRequest.fire({
jumpCode: jumpCodeArg,
});
console.log('got identity response');
const identity = response.clusterIdentifier;
if (tagConnection) {
this.typedsocketClient.addTag('identity', identity);
}
return identity;
}
public async getClusterConfigFromCloudlyByIdentity(
identityArg: plugins.servezoneInterfaces.data.IClusterIdentifier
): Promise<plugins.servezoneInterfaces.data.ICluster> {
const clusterConfigRequest =
this.typedsocketClient.createTypedRequest<plugins.servezoneInterfaces.requests.config.IRequest_Any_Cloudly_GetClusterConfig>(
'getClusterConfig'
);
const response = await clusterConfigRequest.fire({
jwt: '', // TODO: do proper auth here
clusterIdentifier: identityArg,
});
return response.configData;
}
public async getServerConfigFromCloudlyByIdentity(
identityArg: plugins.servezoneInterfaces.data.IClusterIdentifier
): Promise<plugins.servezoneInterfaces.data.IServer> {
const serverConfigRequest =
this.typedsocketClient.createTypedRequest<plugins.servezoneInterfaces.requests.config.IRequest_Any_Cloudly_GetServerConfig>(
'getServerConfig'
);
const response = await serverConfigRequest.fire({
jwt: '', // TODO: do proper auth here
serverId: '' // TODO: get server id here
});
return response.configData;
}
/**
* gets a certificate for a domain used by a service
* @param serviceNameArg
* @param domainNameArg
*/
public async getCertificateForDomainOverHttps(domainNameArg: string): Promise<plugins.tsclass.network.ICert> {
const typedCertificateRequest =
this.typedsocketClient.createTypedRequest<plugins.servezoneInterfaces.requests.certificate.IRequest_Any_Cloudly_GetSslCertificate>(
'getSslCertificate'
);
const typedResponse = await typedCertificateRequest.fire({
authToken: '', // do proper auth here
requiredCertName: domainNameArg,
});
return typedResponse.certificate;
}
}

View File

@ -2,4 +2,5 @@ import * as plugins from './plugins.js';
export class Cluster {
public getServers() {}
}

View File

@ -1,5 +1,29 @@
import * as typedrequest from '@api.global/typedrequest';
// @serve.zone scope
import * as servezoneInterfaces from '@serve.zone/interfaces';
export {
typedrequest
servezoneInterfaces
}
// @push.rocks scope
import * as smartrx from '@push.rocks/smartrx';
export {
smartrx,
}
// @api.global scope
import * as typedrequest from '@api.global/typedrequest';
import * as typedsocket from '@api.global/typedsocket';
export {
typedrequest,
typedsocket
}
// @tsclass scope
import * as tsclass from '@tsclass/tsclass';
export {
tsclass,
}