2024-04-20 10:21:41 +00:00
|
|
|
import * as plugins from './plugins.js';
|
2024-12-14 19:32:17 +00:00
|
|
|
import type { CloudlyApiClient } from './classes.cloudlyapiclient.js';
|
2024-04-20 10:21:41 +00:00
|
|
|
|
2024-12-20 01:13:50 +00:00
|
|
|
export class Service implements plugins.servezoneInterfaces.data.IService {
|
2024-12-14 19:32:17 +00:00
|
|
|
public static async getServices(cloudlyClientRef: CloudlyApiClient) {
|
|
|
|
const getAllServicesTR = cloudlyClientRef.typedsocketClient.createTypedRequest<plugins.servezoneInterfaces.requests.service.IRequest_Any_Cloudly_GetServices>(
|
|
|
|
'getServices'
|
|
|
|
);
|
|
|
|
const response = await getAllServicesTR.fire({
|
|
|
|
identity: cloudlyClientRef.identity,
|
|
|
|
});
|
|
|
|
const resultServices: Service[] = [];
|
|
|
|
for (const service of response.services) {
|
|
|
|
const newService = new Service(cloudlyClientRef);
|
|
|
|
Object.assign(newService, service);
|
|
|
|
resultServices.push(newService);
|
|
|
|
}
|
|
|
|
return resultServices;
|
|
|
|
}
|
2024-04-20 10:21:41 +00:00
|
|
|
|
2024-12-14 19:32:17 +00:00
|
|
|
public static async getServiceById(cloudlyClientRef: CloudlyApiClient, serviceIdArg: string) {
|
|
|
|
const getServiceByIdTR = cloudlyClientRef.typedsocketClient.createTypedRequest<plugins.servezoneInterfaces.requests.service.IRequest_Any_Cloudly_GetServiceById>(
|
|
|
|
'getServiceById'
|
|
|
|
);
|
|
|
|
const response = await getServiceByIdTR.fire({
|
|
|
|
identity: cloudlyClientRef.identity,
|
|
|
|
serviceId: serviceIdArg,
|
|
|
|
});
|
|
|
|
const newService = new Service(cloudlyClientRef);
|
|
|
|
Object.assign(newService, response.service);
|
|
|
|
return newService;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* creates a new service
|
|
|
|
*/
|
|
|
|
public static async createService(cloudlyClientRef: CloudlyApiClient, serviceDataArg: Partial<plugins.servezoneInterfaces.data.IService['data']>) {
|
|
|
|
const createServiceTR = cloudlyClientRef.typedsocketClient.createTypedRequest<plugins.servezoneInterfaces.requests.service.IRequest_Any_Cloudly_CreateService>(
|
|
|
|
'createService'
|
|
|
|
);
|
|
|
|
const response = await createServiceTR.fire({
|
|
|
|
identity: cloudlyClientRef.identity,
|
|
|
|
name: serviceDataArg.name,
|
|
|
|
description: serviceDataArg.description,
|
|
|
|
imageId: serviceDataArg.imageId,
|
|
|
|
imageVersion: serviceDataArg.imageVersion,
|
|
|
|
environment: {},
|
|
|
|
secretBundleId: null,
|
|
|
|
scaleFactor: 1,
|
|
|
|
balancingStrategy: serviceDataArg.balancingStrategy,
|
|
|
|
ports: {
|
|
|
|
web: null,
|
|
|
|
},
|
|
|
|
resources: serviceDataArg.resources,
|
|
|
|
domains: [],
|
|
|
|
});
|
|
|
|
const newService = new Service(cloudlyClientRef);
|
|
|
|
Object.assign(newService, response.service);
|
|
|
|
return newService;
|
|
|
|
}
|
|
|
|
|
|
|
|
// INSTANCE
|
|
|
|
cloudlyClientRef: CloudlyApiClient;
|
|
|
|
|
2024-12-20 01:13:50 +00:00
|
|
|
public id: string;
|
|
|
|
public data: plugins.servezoneInterfaces.data.IService['data'];
|
|
|
|
|
2024-12-14 19:32:17 +00:00
|
|
|
constructor(cloudlyClientRef: CloudlyApiClient) {
|
|
|
|
this.cloudlyClientRef = cloudlyClientRef;
|
|
|
|
}
|
2024-12-20 01:13:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The service has a secret bundle.
|
|
|
|
* This function essentially returns the secret bundle as a flat object.
|
|
|
|
* In other words, it resolves secret groups and
|
|
|
|
*/
|
|
|
|
public async getSecretBundleAsFlatObject(environmentArg: string = 'production') {
|
|
|
|
|
|
|
|
}
|
2024-04-20 10:21:41 +00:00
|
|
|
}
|