2025-01-20 02:11:12 +01:00
|
|
|
import { SecretBundle } from 'ts/manager.secret/classes.secretbundle.js';
|
2024-06-13 09:36:02 +02:00
|
|
|
import * as plugins from '../plugins.js';
|
2024-08-25 14:29:26 +02:00
|
|
|
import { ServiceManager } from './classes.servicemanager.js';
|
2024-06-13 09:36:02 +02:00
|
|
|
|
2024-10-27 19:50:39 +01:00
|
|
|
export class Service extends plugins.smartdata.SmartDataDbDoc<
|
|
|
|
Service,
|
|
|
|
plugins.servezoneInterfaces.data.IService,
|
|
|
|
ServiceManager
|
|
|
|
> {
|
2025-01-20 02:11:12 +01:00
|
|
|
// STATIC
|
|
|
|
public static async getServiceById(serviceIdArg: string) {
|
|
|
|
const service = await this.getInstance({
|
|
|
|
id: serviceIdArg,
|
|
|
|
});
|
|
|
|
return service;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static async getServices() {
|
|
|
|
const services = await this.getInstances({});
|
|
|
|
return services;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static async createService(serviceDataArg: Partial<plugins.servezoneInterfaces.data.IService['data']>) {
|
|
|
|
const service = new Service();
|
|
|
|
service.id = await Service.getNewId();
|
|
|
|
Object.assign(service, serviceDataArg);
|
|
|
|
await service.save();
|
|
|
|
return service;
|
|
|
|
}
|
|
|
|
|
|
|
|
// INSTANCE
|
2024-06-13 09:36:02 +02:00
|
|
|
@plugins.smartdata.svDb()
|
|
|
|
public id: string;
|
|
|
|
|
|
|
|
@plugins.smartdata.svDb()
|
|
|
|
public data: plugins.servezoneInterfaces.data.IService['data'];
|
2025-01-20 02:11:12 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* a service runs in a specific environment
|
|
|
|
* so -> this method returns the secret bundles as a flat object accordingly.
|
|
|
|
* in other words, it resolves secret groups for the relevant environment
|
|
|
|
* @param environmentArg
|
|
|
|
*/
|
|
|
|
public async getSecretBundlesAsFlatObject(environmentArg: string = 'production') {
|
|
|
|
const secreBundleIds = this.data.additionalSecretBundleIds || [];
|
|
|
|
secreBundleIds.push(this.data.secretBundleId); // put this last, so it overwrites any other secret bundles.
|
|
|
|
let finalFlatObject = {};
|
|
|
|
for (const secretBundleId of secreBundleIds) {
|
|
|
|
const secretBundle = await SecretBundle.getInstance({
|
|
|
|
id: secretBundleId,
|
|
|
|
});
|
|
|
|
const flatObject = await secretBundle.getFlatKeyValueObject(environmentArg);
|
|
|
|
Object.assign(finalFlatObject, flatObject);
|
|
|
|
}
|
|
|
|
return finalFlatObject;
|
|
|
|
}
|
2024-10-27 19:50:39 +01:00
|
|
|
}
|