2024-04-20 12:21:41 +02:00
|
|
|
import * as plugins from './plugins.js';
|
|
|
|
|
2024-06-05 14:13:03 +02:00
|
|
|
export type TClientType = 'api' | 'ci' | 'coreflow' | 'cli' | 'serverconfig';
|
2024-05-28 18:45:34 +02:00
|
|
|
|
2024-06-02 21:39:31 +02:00
|
|
|
import { Image } from './classes.image.js';
|
2024-12-14 20:32:17 +01:00
|
|
|
import { Service } from './classes.service.js';
|
2024-12-22 20:03:11 +01:00
|
|
|
import { Cluster } from './classes.cluster.js';
|
|
|
|
import { SecretBundle } from './classes.secretbundle.js';
|
|
|
|
import { SecretGroup } from './classes.secretgroup.js';
|
2024-12-29 13:40:51 +01:00
|
|
|
import { ExternalRegistry } from './classes.externalregistry.js';
|
2024-06-02 21:39:31 +02:00
|
|
|
|
2024-06-05 14:13:03 +02:00
|
|
|
export class CloudlyApiClient {
|
2024-05-28 18:45:34 +02:00
|
|
|
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']
|
|
|
|
>();
|
|
|
|
|
2024-11-18 17:48:26 +01:00
|
|
|
constructor(optionsArg: {
|
2024-06-05 14:13:03 +02:00
|
|
|
registerAs: TClientType;
|
|
|
|
cloudlyUrl?: string;
|
|
|
|
}) {
|
|
|
|
this.registerAs = optionsArg.registerAs;
|
|
|
|
this.cloudlyUrl =
|
|
|
|
optionsArg?.cloudlyUrl || process.env.CLOUDLY_URL || 'https://cloudly.layer.io:443';
|
2024-05-28 18:45:34 +02:00
|
|
|
|
|
|
|
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.server.IRequest_TriggerServerAction>(
|
|
|
|
new plugins.typedrequest.TypedHandler('triggerServerAction', async (dataArg) => {
|
|
|
|
this.serverActionSubject.next(dataArg);
|
|
|
|
return {
|
|
|
|
actionConfirmed: true,
|
|
|
|
};
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2025-09-10 19:06:16 +00:00
|
|
|
// Helper: resolve HTTP typedrequest endpoint
|
|
|
|
private get httpEndpoint() {
|
|
|
|
const base = (this.cloudlyUrl || '').replace(/\/$/, '');
|
|
|
|
return `${base}/typedrequest`;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Helper: choose transport (WS if available, else HTTP)
|
|
|
|
private createWsRequest<T extends plugins.typedRequestInterfaces.ITypedRequest>(operation: string) {
|
|
|
|
return this.typedsocketClient?.createTypedRequest<T>(operation);
|
|
|
|
}
|
|
|
|
|
|
|
|
private createHttpRequest<T extends plugins.typedRequestInterfaces.ITypedRequest>(operation: string) {
|
|
|
|
return new plugins.typedrequest.TypedRequest<T>(this.httpEndpoint, operation);
|
|
|
|
}
|
|
|
|
|
2024-05-28 18:45:34 +02:00
|
|
|
public async start() {
|
|
|
|
this.typedsocketClient = await plugins.typedsocket.TypedSocket.createClient(
|
|
|
|
this.typedrouter,
|
|
|
|
this.cloudlyUrl
|
|
|
|
);
|
2024-06-05 14:13:03 +02:00
|
|
|
console.log(
|
2024-10-16 14:35:38 +02:00
|
|
|
`CloudlyClient connected to cloudly at ${this.cloudlyUrl}. Remember to get an identity.`
|
2024-06-05 14:13:03 +02:00
|
|
|
);
|
2024-05-28 18:45:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public async stop() {
|
|
|
|
await this.typedsocketClient.stop();
|
|
|
|
}
|
|
|
|
|
2024-08-25 14:29:26 +02:00
|
|
|
public identity: plugins.servezoneInterfaces.data.IIdentity;
|
2024-10-16 14:35:38 +02:00
|
|
|
public async getIdentityByToken(
|
|
|
|
token: string,
|
2024-08-25 14:29:26 +02:00
|
|
|
optionsArg?: {
|
|
|
|
tagConnection?: boolean;
|
|
|
|
statefullIdentity?: boolean;
|
|
|
|
}
|
|
|
|
): Promise<plugins.servezoneInterfaces.data.IIdentity> {
|
|
|
|
optionsArg = Object.assign({}, {
|
|
|
|
tagConnection: false,
|
|
|
|
statefullIdentity: true,
|
|
|
|
}, optionsArg);
|
|
|
|
|
2024-05-28 18:45:34 +02:00
|
|
|
const identityRequest =
|
2024-10-16 14:35:38 +02:00
|
|
|
this.typedsocketClient.createTypedRequest<plugins.servezoneInterfaces.requests.identity.IRequest_Any_Cloudly_CoreflowManager_GetIdentityByToken>(
|
|
|
|
'getIdentityByToken'
|
2024-05-28 18:45:34 +02:00
|
|
|
);
|
2024-10-16 14:35:38 +02:00
|
|
|
console.log(`trying to get identity from cloudly with supplied jumpCodeArg: ${token}`);
|
2024-05-28 18:45:34 +02:00
|
|
|
const response = await identityRequest.fire({
|
2024-10-16 14:35:38 +02:00
|
|
|
token: token,
|
2024-05-28 18:45:34 +02:00
|
|
|
});
|
|
|
|
console.log('got identity response');
|
2024-08-25 14:29:26 +02:00
|
|
|
const identity = response.identity;
|
2024-05-28 18:45:34 +02:00
|
|
|
|
2024-08-25 14:29:26 +02:00
|
|
|
if (optionsArg.tagConnection) {
|
2024-05-28 18:45:34 +02:00
|
|
|
this.typedsocketClient.addTag('identity', identity);
|
|
|
|
}
|
|
|
|
|
2024-08-25 14:29:26 +02:00
|
|
|
if (optionsArg.statefullIdentity) {
|
2024-06-02 21:39:31 +02:00
|
|
|
this.identity = identity;
|
|
|
|
}
|
|
|
|
|
2024-05-28 18:45:34 +02:00
|
|
|
return identity;
|
|
|
|
}
|
|
|
|
|
2024-08-25 14:29:26 +02:00
|
|
|
/**
|
|
|
|
* will use statefull identity by default
|
|
|
|
*/
|
2024-05-28 18:45:34 +02:00
|
|
|
public async getClusterConfigFromCloudlyByIdentity(
|
2024-08-25 14:29:26 +02:00
|
|
|
identityArg: plugins.servezoneInterfaces.data.IIdentity = this.identity
|
2024-05-28 18:45:34 +02:00
|
|
|
): Promise<plugins.servezoneInterfaces.data.ICluster> {
|
|
|
|
const clusterConfigRequest =
|
|
|
|
this.typedsocketClient.createTypedRequest<plugins.servezoneInterfaces.requests.config.IRequest_Any_Cloudly_GetClusterConfig>(
|
|
|
|
'getClusterConfig'
|
|
|
|
);
|
|
|
|
const response = await clusterConfigRequest.fire({
|
2024-08-25 14:29:26 +02:00
|
|
|
identity: identityArg,
|
2024-05-28 18:45:34 +02:00
|
|
|
});
|
|
|
|
return response.configData;
|
|
|
|
}
|
2024-04-20 12:21:41 +02:00
|
|
|
|
2024-08-25 14:29:26 +02:00
|
|
|
/**
|
|
|
|
* will use statefull identity by default
|
|
|
|
*/
|
2024-05-28 18:45:34 +02:00
|
|
|
public async getServerConfigFromCloudlyByIdentity(
|
2024-08-25 14:29:26 +02:00
|
|
|
identityArg: plugins.servezoneInterfaces.data.IIdentity = this.identity
|
2024-05-28 18:45:34 +02:00
|
|
|
): Promise<plugins.servezoneInterfaces.data.IServer> {
|
|
|
|
const serverConfigRequest =
|
|
|
|
this.typedsocketClient.createTypedRequest<plugins.servezoneInterfaces.requests.config.IRequest_Any_Cloudly_GetServerConfig>(
|
|
|
|
'getServerConfig'
|
|
|
|
);
|
|
|
|
const response = await serverConfigRequest.fire({
|
2024-08-25 14:29:26 +02:00
|
|
|
identity: identityArg,
|
2024-06-05 14:13:03 +02:00
|
|
|
serverId: '', // TODO: get server id here
|
2024-05-28 18:45:34 +02:00
|
|
|
});
|
|
|
|
return response.configData;
|
2024-04-20 12:21:41 +02:00
|
|
|
}
|
|
|
|
|
2024-05-28 18:45:34 +02:00
|
|
|
/**
|
|
|
|
* gets a certificate for a domain used by a service
|
|
|
|
*/
|
2024-08-25 14:29:26 +02:00
|
|
|
public async getCertificateForDomain(optionsArg: {
|
|
|
|
domainName: string;
|
|
|
|
type: plugins.servezoneInterfaces.requests.certificate.IRequest_Any_Cloudly_GetCertificateForDomain['request']['type'];
|
|
|
|
identity?: plugins.servezoneInterfaces.data.IIdentity;
|
|
|
|
}): Promise<plugins.tsclass.network.ICert> {
|
|
|
|
optionsArg.identity = optionsArg.identity || this.identity;
|
|
|
|
if (!optionsArg.identity) {
|
|
|
|
throw new Error('identity is required. Either provide one or login first.');
|
|
|
|
}
|
2024-05-28 18:45:34 +02:00
|
|
|
const typedCertificateRequest =
|
2024-08-25 14:29:26 +02:00
|
|
|
this.typedsocketClient.createTypedRequest<plugins.servezoneInterfaces.requests.certificate.IRequest_Any_Cloudly_GetCertificateForDomain>(
|
|
|
|
'getCertificateForDomain'
|
2024-05-28 18:45:34 +02:00
|
|
|
);
|
|
|
|
const typedResponse = await typedCertificateRequest.fire({
|
2024-08-25 14:29:26 +02:00
|
|
|
identity: this.identity, // do proper auth here
|
|
|
|
domainName: optionsArg.domainName,
|
|
|
|
type: optionsArg.type,
|
2024-05-28 18:45:34 +02:00
|
|
|
});
|
|
|
|
return typedResponse.certificate;
|
2024-04-20 12:21:41 +02:00
|
|
|
}
|
2024-06-02 21:39:31 +02:00
|
|
|
|
2024-12-29 13:40:51 +01:00
|
|
|
public externalRegistry = {
|
|
|
|
// ExternalRegistry
|
|
|
|
getRegistryById: async (registryNameArg: string) => {
|
|
|
|
return ExternalRegistry.getExternalRegistryById(this, registryNameArg);
|
|
|
|
},
|
|
|
|
getRegistries: async () => {
|
|
|
|
return ExternalRegistry.getExternalRegistries(this);
|
|
|
|
},
|
|
|
|
createRegistry: async (optionsArg: Parameters<typeof ExternalRegistry.createExternalRegistry>[1]) => {
|
|
|
|
return ExternalRegistry.createExternalRegistry(this, optionsArg);
|
2025-09-10 19:06:16 +00:00
|
|
|
},
|
|
|
|
verifyRegistry: async (registryId: string): Promise<{ success: boolean; message: string; registry?: ExternalRegistry }> => {
|
|
|
|
const op = 'verifyExternalRegistry';
|
|
|
|
const wsReq = this.createWsRequest<plugins.servezoneInterfaces.requests.externalRegistry.IReq_VerifyRegistry>(op);
|
|
|
|
const payload = { identity: this.identity, registryId } as any;
|
|
|
|
const resp = wsReq ? await wsReq.fire(payload) : await this.createHttpRequest<plugins.servezoneInterfaces.requests.externalRegistry.IReq_VerifyRegistry>(op).fire(payload);
|
|
|
|
let registryInstance: ExternalRegistry | undefined;
|
|
|
|
if (resp.registry) {
|
|
|
|
registryInstance = new ExternalRegistry(this);
|
|
|
|
Object.assign(registryInstance, resp.registry);
|
|
|
|
}
|
|
|
|
return { success: resp.success, message: resp.message, registry: registryInstance };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Auth helpers
|
|
|
|
public async loginWithUsernameAndPassword(username: string, password: string): Promise<plugins.servezoneInterfaces.data.IIdentity> {
|
|
|
|
const op = 'adminLoginWithUsernameAndPassword';
|
|
|
|
// Login endpoint is exposed via HTTP typedrequest
|
|
|
|
const httpReq = this.createHttpRequest<plugins.servezoneInterfaces.requests.admin.IReq_Admin_LoginWithUsernameAndPassword>(op);
|
|
|
|
const response = await httpReq.fire({ username, password });
|
|
|
|
this.identity = response.identity;
|
|
|
|
// If WS connection is available, tag it with identity for server-side guards
|
|
|
|
if (this.typedsocketClient) {
|
|
|
|
try { this.typedsocketClient.addTag('identity', this.identity); } catch {}
|
2024-12-29 13:40:51 +01:00
|
|
|
}
|
2025-09-10 19:06:16 +00:00
|
|
|
return this.identity;
|
2024-12-29 13:40:51 +01:00
|
|
|
}
|
|
|
|
|
2024-12-22 19:55:56 +01:00
|
|
|
public image = {
|
2024-10-16 14:35:38 +02:00
|
|
|
// Images
|
2024-11-18 19:52:15 +01:00
|
|
|
getImageById: async (imageIdArg: string) => {
|
|
|
|
return Image.getImageById(this, imageIdArg);
|
|
|
|
},
|
2024-10-16 14:35:38 +02:00
|
|
|
getImages: async () => {
|
|
|
|
return Image.getImages(this);
|
|
|
|
},
|
|
|
|
createImage: async (optionsArg: Parameters<typeof Image.createImage>[1]) => {
|
|
|
|
return Image.createImage(this, optionsArg);
|
2025-09-10 19:06:16 +00:00
|
|
|
},
|
|
|
|
deleteImage: async (imageId: string): Promise<void> => {
|
|
|
|
const op = 'deleteImage';
|
|
|
|
const payload = { identity: this.identity, imageId } as any;
|
|
|
|
const wsReq = this.createWsRequest<plugins.servezoneInterfaces.requests.image.IRequest_DeleteImage>(op);
|
|
|
|
if (wsReq) { await wsReq.fire(payload); return; }
|
|
|
|
await this.createHttpRequest<plugins.servezoneInterfaces.requests.image.IRequest_DeleteImage>(op).fire(payload);
|
2024-10-16 14:35:38 +02:00
|
|
|
}
|
2024-06-02 21:39:31 +02:00
|
|
|
}
|
2024-12-14 20:32:17 +01:00
|
|
|
|
|
|
|
public services = {
|
|
|
|
// Services
|
|
|
|
getServiceById: async (serviceIdArg: string) => {
|
|
|
|
return Service.getServiceById(this, serviceIdArg);
|
|
|
|
},
|
|
|
|
getServices: async () => {
|
|
|
|
return Service.getServices(this);
|
|
|
|
},
|
|
|
|
createService: async (optionsArg: Parameters<typeof Service.createService>[1]) => {
|
|
|
|
return Service.createService(this, optionsArg);
|
2025-09-10 19:06:16 +00:00
|
|
|
},
|
|
|
|
updateService: async (serviceId: string, serviceData: plugins.servezoneInterfaces.data.IService['data']): Promise<{ service: plugins.servezoneInterfaces.data.IService }> => {
|
|
|
|
const op = 'updateService';
|
|
|
|
const payload = { identity: this.identity, serviceId, serviceData } as any;
|
|
|
|
const wsReq = this.createWsRequest<plugins.servezoneInterfaces.requests.service.IRequest_Any_Cloudly_UpdateService>(op);
|
|
|
|
if (wsReq) return wsReq.fire(payload);
|
|
|
|
return this.createHttpRequest<plugins.servezoneInterfaces.requests.service.IRequest_Any_Cloudly_UpdateService>(op).fire(payload);
|
|
|
|
},
|
|
|
|
deleteService: async (serviceId: string): Promise<void> => {
|
|
|
|
const op = 'deleteServiceById';
|
|
|
|
const payload = { identity: this.identity, serviceId } as any;
|
|
|
|
const wsReq = this.createWsRequest<plugins.servezoneInterfaces.requests.service.IRequest_Any_Cloudly_DeleteServiceById>(op);
|
|
|
|
if (wsReq) { await wsReq.fire(payload); return; }
|
|
|
|
await this.createHttpRequest<plugins.servezoneInterfaces.requests.service.IRequest_Any_Cloudly_DeleteServiceById>(op).fire(payload);
|
2024-12-14 20:32:17 +01:00
|
|
|
}
|
|
|
|
}
|
2024-12-22 20:03:11 +01:00
|
|
|
|
|
|
|
public cluster = {
|
|
|
|
// Clusters
|
|
|
|
getClusterById: async (clusterIdArg: string) => {
|
|
|
|
return Cluster.getClusterById(this, clusterIdArg);
|
|
|
|
},
|
|
|
|
getClusters: async () => {
|
|
|
|
return Cluster.getClusters(this);
|
|
|
|
},
|
|
|
|
createCluster: async (optionsArg: Parameters<typeof Cluster.createCluster>[1]) => {
|
|
|
|
return Cluster.createCluster(this, optionsArg);
|
2025-09-10 20:23:12 +00:00
|
|
|
},
|
|
|
|
createClusterAdvanced: async (clusterName: string, setupMode?: 'manual' | 'hetzner' | 'aws' | 'digitalocean') => {
|
|
|
|
const op = 'createCluster';
|
|
|
|
const payload: any = { identity: this.identity, clusterName };
|
|
|
|
if (setupMode) payload.setupMode = setupMode;
|
|
|
|
const wsReq = this.createWsRequest<plugins.servezoneInterfaces.requests.cluster.IRequest_CreateCluster>(op);
|
|
|
|
if (wsReq) return wsReq.fire(payload);
|
|
|
|
return this.createHttpRequest<plugins.servezoneInterfaces.requests.cluster.IRequest_CreateCluster>(op).fire(payload);
|
2024-12-22 20:03:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public secretbundle = {
|
|
|
|
// SecretBundles
|
|
|
|
getSecretBundleById: async (secretBundleIdArg: string) => {
|
|
|
|
return SecretBundle.getSecretBundleById(this, secretBundleIdArg);
|
|
|
|
},
|
|
|
|
getSecretBundles: async () => {
|
|
|
|
return SecretBundle.getSecretBundles(this);
|
|
|
|
},
|
|
|
|
createSecretBundle: async (optionsArg: Parameters<typeof SecretBundle.createSecretBundle>[1]) => {
|
|
|
|
return SecretBundle.createSecretBundle(this, optionsArg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public secretgroup = {
|
|
|
|
// SecretGroups
|
|
|
|
getSecretGroupById: async (secretGroupIdArg: string) => {
|
|
|
|
return SecretGroup.getSecretGroupById(this, secretGroupIdArg);
|
|
|
|
},
|
|
|
|
getSecretGroups: async () => {
|
|
|
|
return SecretGroup.getSecretGroups(this);
|
|
|
|
},
|
|
|
|
createSecretGroup: async (optionsArg: Parameters<typeof SecretGroup.createSecretGroup>[1]) => {
|
|
|
|
return SecretGroup.createSecretGroup(this, optionsArg);
|
|
|
|
}
|
|
|
|
}
|
2025-09-10 19:06:16 +00:00
|
|
|
|
|
|
|
// Settings API
|
|
|
|
public settings = {
|
|
|
|
getSettings: async (): Promise<{
|
|
|
|
settings: plugins.servezoneInterfaces.data.ICloudlySettingsMasked
|
|
|
|
}> => {
|
|
|
|
const op = 'getSettings';
|
|
|
|
const wsReq = this.createWsRequest<plugins.servezoneInterfaces.requests.settings.IRequest_GetSettings>(op);
|
|
|
|
if (wsReq) {
|
|
|
|
return wsReq.fire({ identity: this.identity });
|
|
|
|
}
|
|
|
|
const httpReq = this.createHttpRequest<plugins.servezoneInterfaces.requests.settings.IRequest_GetSettings>(op);
|
|
|
|
return httpReq.fire({ identity: this.identity });
|
|
|
|
},
|
|
|
|
updateSettings: async (updates: Partial<plugins.servezoneInterfaces.data.ICloudlySettings>): Promise<{
|
|
|
|
success: boolean;
|
|
|
|
message: string;
|
|
|
|
}> => {
|
|
|
|
const op = 'updateSettings';
|
|
|
|
const wsReq = this.createWsRequest<plugins.servezoneInterfaces.requests.settings.IRequest_UpdateSettings>(op);
|
|
|
|
if (wsReq) {
|
|
|
|
return wsReq.fire({ identity: this.identity, updates });
|
|
|
|
}
|
|
|
|
const httpReq = this.createHttpRequest<plugins.servezoneInterfaces.requests.settings.IRequest_UpdateSettings>(op);
|
|
|
|
return httpReq.fire({ identity: this.identity, updates });
|
|
|
|
},
|
|
|
|
testProviderConnection: async (provider: string): Promise<{
|
|
|
|
connectionValid: boolean;
|
|
|
|
message: string;
|
|
|
|
}> => {
|
|
|
|
const op = 'testProviderConnection';
|
|
|
|
const wsReq = this.createWsRequest<plugins.servezoneInterfaces.requests.settings.IRequest_TestProviderConnection>(op);
|
|
|
|
if (wsReq) {
|
|
|
|
return wsReq.fire({ identity: this.identity, provider: provider as any });
|
|
|
|
}
|
|
|
|
const httpReq = this.createHttpRequest<plugins.servezoneInterfaces.requests.settings.IRequest_TestProviderConnection>(op);
|
|
|
|
return httpReq.fire({ identity: this.identity, provider: provider as any });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Task API
|
|
|
|
public tasks = {
|
|
|
|
getTasks: async (): Promise<{
|
|
|
|
tasks: Array<{
|
|
|
|
name: string;
|
|
|
|
description: string;
|
|
|
|
category: 'maintenance' | 'deployment' | 'backup' | 'monitoring' | 'cleanup' | 'system' | 'security';
|
|
|
|
schedule?: string;
|
|
|
|
lastRun?: number;
|
|
|
|
enabled: boolean;
|
|
|
|
}>
|
|
|
|
}> => {
|
|
|
|
const op = 'getTasks';
|
|
|
|
const wsReq = this.createWsRequest<plugins.servezoneInterfaces.requests.task.IRequest_Any_Cloudly_GetTasks>(op);
|
|
|
|
if (wsReq) {
|
|
|
|
return wsReq.fire({ identity: this.identity });
|
|
|
|
}
|
|
|
|
const httpReq = this.createHttpRequest<plugins.servezoneInterfaces.requests.task.IRequest_Any_Cloudly_GetTasks>(op);
|
|
|
|
return httpReq.fire({ identity: this.identity });
|
|
|
|
},
|
|
|
|
getTaskExecutions: async (filter?: any): Promise<{
|
|
|
|
executions: plugins.servezoneInterfaces.data.ITaskExecution[];
|
|
|
|
}> => {
|
|
|
|
const op = 'getTaskExecutions';
|
|
|
|
const wsReq = this.createWsRequest<plugins.servezoneInterfaces.requests.task.IRequest_Any_Cloudly_GetTaskExecutions>(op);
|
|
|
|
if (wsReq) {
|
|
|
|
return wsReq.fire({ identity: this.identity, filter });
|
|
|
|
}
|
|
|
|
const httpReq = this.createHttpRequest<plugins.servezoneInterfaces.requests.task.IRequest_Any_Cloudly_GetTaskExecutions>(op);
|
|
|
|
return httpReq.fire({ identity: this.identity, filter });
|
|
|
|
},
|
|
|
|
getTaskExecutionById: async (executionId: string): Promise<{
|
|
|
|
execution: plugins.servezoneInterfaces.data.ITaskExecution
|
|
|
|
}> => {
|
|
|
|
const op = 'getTaskExecutionById';
|
|
|
|
const wsReq = this.createWsRequest<plugins.servezoneInterfaces.requests.task.IRequest_Any_Cloudly_GetTaskExecutionById>(op);
|
|
|
|
if (wsReq) {
|
|
|
|
return wsReq.fire({ identity: this.identity, executionId });
|
|
|
|
}
|
|
|
|
const httpReq = this.createHttpRequest<plugins.servezoneInterfaces.requests.task.IRequest_Any_Cloudly_GetTaskExecutionById>(op);
|
|
|
|
return httpReq.fire({ identity: this.identity, executionId });
|
|
|
|
},
|
|
|
|
triggerTask: async (taskName: string, userId?: string): Promise<{
|
|
|
|
execution: plugins.servezoneInterfaces.data.ITaskExecution
|
|
|
|
}> => {
|
|
|
|
const op = 'triggerTask';
|
|
|
|
const wsReq = this.createWsRequest<plugins.servezoneInterfaces.requests.task.IRequest_Any_Cloudly_TriggerTask>(op);
|
|
|
|
if (wsReq) {
|
|
|
|
return wsReq.fire({ identity: this.identity, taskName, userId });
|
|
|
|
}
|
|
|
|
const httpReq = this.createHttpRequest<plugins.servezoneInterfaces.requests.task.IRequest_Any_Cloudly_TriggerTask>(op);
|
|
|
|
return httpReq.fire({ identity: this.identity, taskName, userId });
|
|
|
|
},
|
|
|
|
cancelTask: async (executionId: string): Promise<{ success: boolean }> => {
|
|
|
|
const op = 'cancelTask';
|
|
|
|
const wsReq = this.createWsRequest<plugins.servezoneInterfaces.requests.task.IRequest_Any_Cloudly_CancelTask>(op);
|
|
|
|
if (wsReq) {
|
|
|
|
return wsReq.fire({ identity: this.identity, executionId });
|
|
|
|
}
|
|
|
|
const httpReq = this.createHttpRequest<plugins.servezoneInterfaces.requests.task.IRequest_Any_Cloudly_CancelTask>(op);
|
|
|
|
return httpReq.fire({ identity: this.identity, executionId });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Domain API
|
|
|
|
public domains = {
|
|
|
|
getDomains: async (): Promise<{ domains: plugins.servezoneInterfaces.data.IDomain[] }> => {
|
|
|
|
const op = 'getDomains';
|
|
|
|
const wsReq = this.createWsRequest<plugins.servezoneInterfaces.requests.domain.IRequest_Any_Cloudly_GetDomains>(op);
|
|
|
|
if (wsReq) return wsReq.fire({ identity: this.identity });
|
|
|
|
return this.createHttpRequest<plugins.servezoneInterfaces.requests.domain.IRequest_Any_Cloudly_GetDomains>(op).fire({ identity: this.identity });
|
|
|
|
},
|
|
|
|
getDomainById: async (domainId: string): Promise<{ domain: plugins.servezoneInterfaces.data.IDomain }> => {
|
|
|
|
const op = 'getDomainById';
|
|
|
|
const payload = { identity: this.identity, domainId } as any;
|
|
|
|
const wsReq = this.createWsRequest<plugins.servezoneInterfaces.requests.domain.IRequest_Any_Cloudly_GetDomainById>(op);
|
|
|
|
if (wsReq) return wsReq.fire(payload);
|
|
|
|
return this.createHttpRequest<plugins.servezoneInterfaces.requests.domain.IRequest_Any_Cloudly_GetDomainById>(op).fire(payload);
|
|
|
|
},
|
|
|
|
createDomain: async (domainData: plugins.servezoneInterfaces.data.IDomain['data']): Promise<{ domain: plugins.servezoneInterfaces.data.IDomain }> => {
|
|
|
|
const op = 'createDomain';
|
|
|
|
const payload = { identity: this.identity, domainData } as any;
|
|
|
|
const wsReq = this.createWsRequest<plugins.servezoneInterfaces.requests.domain.IRequest_Any_Cloudly_CreateDomain>(op);
|
|
|
|
if (wsReq) return wsReq.fire(payload);
|
|
|
|
return this.createHttpRequest<plugins.servezoneInterfaces.requests.domain.IRequest_Any_Cloudly_CreateDomain>(op).fire(payload);
|
|
|
|
},
|
|
|
|
updateDomain: async (domainId: string, domainData: Partial<plugins.servezoneInterfaces.data.IDomain['data']>): Promise<{ domain: plugins.servezoneInterfaces.data.IDomain }> => {
|
|
|
|
const op = 'updateDomain';
|
|
|
|
const payload = { identity: this.identity, domainId, domainData } as any;
|
|
|
|
const wsReq = this.createWsRequest<plugins.servezoneInterfaces.requests.domain.IRequest_Any_Cloudly_UpdateDomain>(op);
|
|
|
|
if (wsReq) return wsReq.fire(payload);
|
|
|
|
return this.createHttpRequest<plugins.servezoneInterfaces.requests.domain.IRequest_Any_Cloudly_UpdateDomain>(op).fire(payload);
|
|
|
|
},
|
|
|
|
deleteDomain: async (domainId: string): Promise<{ success: boolean }> => {
|
|
|
|
const op = 'deleteDomain';
|
|
|
|
const payload = { identity: this.identity, domainId } as any;
|
|
|
|
const wsReq = this.createWsRequest<plugins.servezoneInterfaces.requests.domain.IRequest_Any_Cloudly_DeleteDomain>(op);
|
|
|
|
if (wsReq) return wsReq.fire(payload);
|
|
|
|
return this.createHttpRequest<plugins.servezoneInterfaces.requests.domain.IRequest_Any_Cloudly_DeleteDomain>(op).fire(payload);
|
|
|
|
},
|
|
|
|
verifyDomain: async (domainId: string, verificationMethod?: 'dns' | 'http' | 'email' | 'manual'): Promise<{ domain: plugins.servezoneInterfaces.data.IDomain; verificationResult: any }> => {
|
|
|
|
const op = 'verifyDomain';
|
|
|
|
const payload = { identity: this.identity, domainId, verificationMethod } as any;
|
|
|
|
const wsReq = this.createWsRequest<plugins.servezoneInterfaces.requests.domain.IRequest_Any_Cloudly_VerifyDomain>(op);
|
|
|
|
if (wsReq) return wsReq.fire(payload);
|
|
|
|
return this.createHttpRequest<plugins.servezoneInterfaces.requests.domain.IRequest_Any_Cloudly_VerifyDomain>(op).fire(payload);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
// DNS API
|
|
|
|
public dns = {
|
|
|
|
getDnsEntries: async (zone?: string): Promise<{ dnsEntries: plugins.servezoneInterfaces.data.IDnsEntry[] }> => {
|
|
|
|
const op = 'getDnsEntries';
|
|
|
|
const payload = { identity: this.identity, zone } as any;
|
|
|
|
const wsReq = this.createWsRequest<plugins.servezoneInterfaces.requests.dns.IRequest_Any_Cloudly_GetDnsEntries>(op);
|
|
|
|
if (wsReq) return wsReq.fire(payload);
|
|
|
|
return this.createHttpRequest<plugins.servezoneInterfaces.requests.dns.IRequest_Any_Cloudly_GetDnsEntries>(op).fire(payload);
|
|
|
|
},
|
|
|
|
getDnsEntryById: async (dnsEntryId: string): Promise<{ dnsEntry: plugins.servezoneInterfaces.data.IDnsEntry }> => {
|
|
|
|
const op = 'getDnsEntryById';
|
|
|
|
const payload = { identity: this.identity, dnsEntryId } as any;
|
|
|
|
const wsReq = this.createWsRequest<plugins.servezoneInterfaces.requests.dns.IRequest_Any_Cloudly_GetDnsEntryById>(op);
|
|
|
|
if (wsReq) return wsReq.fire(payload);
|
|
|
|
return this.createHttpRequest<plugins.servezoneInterfaces.requests.dns.IRequest_Any_Cloudly_GetDnsEntryById>(op).fire(payload);
|
|
|
|
},
|
|
|
|
createDnsEntry: async (dnsEntryData: plugins.servezoneInterfaces.data.IDnsEntry['data']): Promise<{ dnsEntry: plugins.servezoneInterfaces.data.IDnsEntry }> => {
|
|
|
|
const op = 'createDnsEntry';
|
|
|
|
const payload = { identity: this.identity, dnsEntryData } as any;
|
|
|
|
const wsReq = this.createWsRequest<plugins.servezoneInterfaces.requests.dns.IRequest_Any_Cloudly_CreateDnsEntry>(op);
|
|
|
|
if (wsReq) return wsReq.fire(payload);
|
|
|
|
return this.createHttpRequest<plugins.servezoneInterfaces.requests.dns.IRequest_Any_Cloudly_CreateDnsEntry>(op).fire(payload);
|
|
|
|
},
|
|
|
|
updateDnsEntry: async (dnsEntryId: string, dnsEntryData: plugins.servezoneInterfaces.data.IDnsEntry['data']): Promise<{ dnsEntry: plugins.servezoneInterfaces.data.IDnsEntry }> => {
|
|
|
|
const op = 'updateDnsEntry';
|
|
|
|
const payload = { identity: this.identity, dnsEntryId, dnsEntryData } as any;
|
|
|
|
const wsReq = this.createWsRequest<plugins.servezoneInterfaces.requests.dns.IRequest_Any_Cloudly_UpdateDnsEntry>(op);
|
|
|
|
if (wsReq) return wsReq.fire(payload);
|
|
|
|
return this.createHttpRequest<plugins.servezoneInterfaces.requests.dns.IRequest_Any_Cloudly_UpdateDnsEntry>(op).fire(payload);
|
|
|
|
},
|
|
|
|
deleteDnsEntry: async (dnsEntryId: string): Promise<{ success: boolean }> => {
|
|
|
|
const op = 'deleteDnsEntry';
|
|
|
|
const payload = { identity: this.identity, dnsEntryId } as any;
|
|
|
|
const wsReq = this.createWsRequest<plugins.servezoneInterfaces.requests.dns.IRequest_Any_Cloudly_DeleteDnsEntry>(op);
|
|
|
|
if (wsReq) return wsReq.fire(payload);
|
|
|
|
return this.createHttpRequest<plugins.servezoneInterfaces.requests.dns.IRequest_Any_Cloudly_DeleteDnsEntry>(op).fire(payload);
|
|
|
|
},
|
|
|
|
getDnsZones: async (): Promise<{ zones: string[] }> => {
|
|
|
|
const op = 'getDnsZones';
|
|
|
|
const payload = { identity: this.identity } as any;
|
|
|
|
const wsReq = this.createWsRequest<plugins.servezoneInterfaces.requests.dns.IRequest_Any_Cloudly_GetDnsZones>(op);
|
|
|
|
if (wsReq) return wsReq.fire(payload);
|
|
|
|
return this.createHttpRequest<plugins.servezoneInterfaces.requests.dns.IRequest_Any_Cloudly_GetDnsZones>(op).fire(payload);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
// Deployment API
|
|
|
|
public deployments = {
|
|
|
|
getDeployments: async (): Promise<{ deployments: plugins.servezoneInterfaces.data.IDeployment[] }> => {
|
|
|
|
const op = 'getDeployments';
|
|
|
|
const payload = { identity: this.identity } as any;
|
|
|
|
const wsReq = this.createWsRequest<plugins.servezoneInterfaces.requests.deployment.IReq_Any_Cloudly_GetDeployments>(op);
|
|
|
|
if (wsReq) return wsReq.fire(payload);
|
|
|
|
return this.createHttpRequest<plugins.servezoneInterfaces.requests.deployment.IReq_Any_Cloudly_GetDeployments>(op).fire(payload);
|
|
|
|
},
|
|
|
|
getDeploymentById: async (deploymentId: string): Promise<{ deployment: plugins.servezoneInterfaces.data.IDeployment }> => {
|
|
|
|
const op = 'getDeploymentById';
|
|
|
|
const payload = { identity: this.identity, deploymentId } as any;
|
|
|
|
const wsReq = this.createWsRequest<plugins.servezoneInterfaces.requests.deployment.IReq_Any_Cloudly_GetDeploymentById>(op);
|
|
|
|
if (wsReq) return wsReq.fire(payload);
|
|
|
|
return this.createHttpRequest<plugins.servezoneInterfaces.requests.deployment.IReq_Any_Cloudly_GetDeploymentById>(op).fire(payload);
|
|
|
|
},
|
|
|
|
createDeployment: async (deploymentData: Partial<plugins.servezoneInterfaces.data.IDeployment>): Promise<{ deployment: plugins.servezoneInterfaces.data.IDeployment }> => {
|
|
|
|
const op = 'createDeployment';
|
|
|
|
const payload = { identity: this.identity, deploymentData } as any;
|
|
|
|
const wsReq = this.createWsRequest<plugins.servezoneInterfaces.requests.deployment.IReq_Any_Cloudly_CreateDeployment>(op);
|
|
|
|
if (wsReq) return wsReq.fire(payload);
|
|
|
|
return this.createHttpRequest<plugins.servezoneInterfaces.requests.deployment.IReq_Any_Cloudly_CreateDeployment>(op).fire(payload);
|
|
|
|
},
|
|
|
|
updateDeployment: async (deploymentId: string, deploymentData: Partial<plugins.servezoneInterfaces.data.IDeployment>): Promise<{ deployment: plugins.servezoneInterfaces.data.IDeployment }> => {
|
|
|
|
const op = 'updateDeployment';
|
|
|
|
const payload = { identity: this.identity, deploymentId, deploymentData } as any;
|
|
|
|
const wsReq = this.createWsRequest<plugins.servezoneInterfaces.requests.deployment.IReq_Any_Cloudly_UpdateDeployment>(op);
|
|
|
|
if (wsReq) return wsReq.fire(payload);
|
|
|
|
return this.createHttpRequest<plugins.servezoneInterfaces.requests.deployment.IReq_Any_Cloudly_UpdateDeployment>(op).fire(payload);
|
|
|
|
},
|
|
|
|
deleteDeployment: async (deploymentId: string): Promise<{ success: boolean }> => {
|
|
|
|
const op = 'deleteDeploymentById';
|
|
|
|
const payload = { identity: this.identity, deploymentId } as any;
|
|
|
|
const wsReq = this.createWsRequest<plugins.servezoneInterfaces.requests.deployment.IReq_Any_Cloudly_DeleteDeploymentById>(op);
|
|
|
|
if (wsReq) return wsReq.fire(payload);
|
|
|
|
return this.createHttpRequest<plugins.servezoneInterfaces.requests.deployment.IReq_Any_Cloudly_DeleteDeploymentById>(op).fire(payload);
|
|
|
|
},
|
|
|
|
restartDeployment: async (deploymentId: string): Promise<{ success: boolean; deployment: plugins.servezoneInterfaces.data.IDeployment }> => {
|
|
|
|
const op = 'restartDeployment';
|
|
|
|
const payload = { identity: this.identity, deploymentId } as any;
|
|
|
|
const wsReq = this.createWsRequest<plugins.servezoneInterfaces.requests.deployment.IReq_Any_Cloudly_RestartDeployment>(op);
|
|
|
|
if (wsReq) return wsReq.fire(payload);
|
|
|
|
return this.createHttpRequest<plugins.servezoneInterfaces.requests.deployment.IReq_Any_Cloudly_RestartDeployment>(op).fire(payload);
|
|
|
|
},
|
|
|
|
scaleDeployment: async (deploymentId: string, replicas: number): Promise<{ success: boolean; deployment: plugins.servezoneInterfaces.data.IDeployment }> => {
|
|
|
|
const op = 'scaleDeployment';
|
|
|
|
const payload = { identity: this.identity, deploymentId, replicas } as any;
|
|
|
|
const wsReq = this.createWsRequest<plugins.servezoneInterfaces.requests.deployment.IReq_Any_Cloudly_ScaleDeployment>(op);
|
|
|
|
if (wsReq) return wsReq.fire(payload);
|
|
|
|
return this.createHttpRequest<plugins.servezoneInterfaces.requests.deployment.IReq_Any_Cloudly_ScaleDeployment>(op).fire(payload);
|
|
|
|
},
|
|
|
|
};
|
2024-04-20 12:21:41 +02:00
|
|
|
}
|