From caf3a095f2fef1e184ecf36b805d772f4e58c998 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Mon, 30 Dec 2024 00:01:26 +0100 Subject: [PATCH] feat(external-registry): Introduce external registry management --- changelog.md | 7 +++ ts/00_commitinfo_data.ts | 2 +- ts/classes.cloudly.ts | 3 ++ ts/manager.cluster/classes.clustermanager.ts | 6 +-- .../classes.externalregistry.ts | 40 +++++++++++++++ .../classes.externalregistrymanager.ts | 51 +++++++++++++++++++ ts/manager.externalregistry/index.ts | 2 + .../classes.externalregistry.ts | 30 ----------- ts_apiclient/classes.externalregistry.ts | 2 +- ts_interfaces/requests/externalregistry.ts | 2 +- ts_web/00_commitinfo_data.ts | 2 +- 11 files changed, 110 insertions(+), 37 deletions(-) create mode 100644 ts/manager.externalregistry/classes.externalregistry.ts create mode 100644 ts/manager.externalregistry/classes.externalregistrymanager.ts create mode 100644 ts/manager.externalregistry/index.ts delete mode 100644 ts/manager.regsitry/classes.externalregistry.ts diff --git a/changelog.md b/changelog.md index 431b528..051dc6b 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,12 @@ # Changelog +## 2024-12-30 - 4.11.0 - feat(external-registry) +Introduce external registry management + +- Added ExternalRegistryManager to handle external registry operations. +- Implemented ability to create, retrieve, and delete external registries. +- Enhanced Cloudly class to include ExternalRegistryManager. + ## 2024-12-29 - 4.10.0 - feat(apiclient) Added support for managing external registries in the API client. diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index f525271..8e95a13 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@serve.zone/cloudly', - version: '4.10.0', + version: '4.11.0', description: 'A comprehensive tool for managing containerized applications across multiple cloud providers using Docker Swarmkit, featuring web, CLI, and API interfaces.' } diff --git a/ts/classes.cloudly.ts b/ts/classes.cloudly.ts index ac04a0a..ecd09ec 100644 --- a/ts/classes.cloudly.ts +++ b/ts/classes.cloudly.ts @@ -20,6 +20,7 @@ import { CloudlyTaskmanager } from './manager.task/taskmanager.js'; import { CloudlySecretManager } from './manager.secret/classes.secretmanager.js'; import { CloudlyServerManager } from './manager.server/classes.servermanager.js'; import { ExternalApiManager } from './manager.status/statusmanager.js'; +import { ExternalRegistryManager } from './manager.externalregistry/index.js'; import { ImageManager } from './manager.image/classes.imagemanager.js'; import { logger } from './logger.js'; import { CloudlyAuthManager } from './manager.auth/classes.authmanager.js'; @@ -54,6 +55,7 @@ export class Cloudly { public clusterManager: ClusterManager; public coreflowManager: CloudlyCoreflowManager; public externalApiManager: ExternalApiManager; + public externalRegistryManager: ExternalRegistryManager; public imageManager: ImageManager; public taskManager: CloudlyTaskmanager; public serverManager: CloudlyServerManager; @@ -80,6 +82,7 @@ export class Cloudly { this.clusterManager = new ClusterManager(this); this.coreflowManager = new CloudlyCoreflowManager(this); this.externalApiManager = new ExternalApiManager(this); + this.externalRegistryManager = new ExternalRegistryManager(this); this.imageManager = new ImageManager(this); this.taskManager = new CloudlyTaskmanager(this); this.secretManager = new CloudlySecretManager(this); diff --git a/ts/manager.cluster/classes.clustermanager.ts b/ts/manager.cluster/classes.clustermanager.ts index be18c35..3448a01 100644 --- a/ts/manager.cluster/classes.clustermanager.ts +++ b/ts/manager.cluster/classes.clustermanager.ts @@ -44,7 +44,7 @@ export class ClusterManager { ); this.typedrouter.addTypedHandler( - new plugins.typedrequest.TypedHandler('getAllClusters', async (dataArg) => { + new plugins.typedrequest.TypedHandler('getClusters', async (dataArg) => { // TODO: do authentication here const clusters = await this.getAllClusters(); return { @@ -57,11 +57,11 @@ export class ClusterManager { // delete cluster this.typedrouter.addTypedHandler( - new plugins.typedrequest.TypedHandler('deleteCluster', async (reqDataArg, toolsArg) => { + new plugins.typedrequest.TypedHandler('deleteClusterById', async (reqDataArg, toolsArg) => { await toolsArg.passGuards([this.cloudlyRef.authManager.adminIdentityGuard], reqDataArg); await this.deleteCluster(reqDataArg.clusterId); return { - success: true, + ok: true, }; }), ); diff --git a/ts/manager.externalregistry/classes.externalregistry.ts b/ts/manager.externalregistry/classes.externalregistry.ts new file mode 100644 index 0000000..0b17e02 --- /dev/null +++ b/ts/manager.externalregistry/classes.externalregistry.ts @@ -0,0 +1,40 @@ +import * as plugins from '../plugins.js'; +import * as paths from '../paths.js'; +import type { Cloudly } from 'ts/classes.cloudly.js'; +import type { ExternalRegistryManager } from './classes.externalregistrymanager.js'; + +export class ExternalRegistry extends plugins.smartdata.SmartDataDbDoc { + // STATIC + public static async getRegistryById(registryIdArg: string) { + const externalRegistry = await this.getInstance({ + id: registryIdArg, + }); + return externalRegistry; + } + + public static async getRegistries() { + const externalRegistries = await this.getInstances({}); + return externalRegistries; + } + + public static async createExternalRegistry(registryDataArg: Partial) { + const externalRegistry = new ExternalRegistry(); + externalRegistry.id = await ExternalRegistry.getNewId(); + Object.assign(externalRegistry, registryDataArg); + await externalRegistry.save(); + return externalRegistry; + } + + // INSTANCE + + @plugins.smartdata.svDb() + public id: string; + + @plugins.smartdata.svDb() + public data: plugins.servezoneInterfaces.data.IExternalRegistry['data']; + + constructor() { + super(); + } + +} diff --git a/ts/manager.externalregistry/classes.externalregistrymanager.ts b/ts/manager.externalregistry/classes.externalregistrymanager.ts new file mode 100644 index 0000000..9c60244 --- /dev/null +++ b/ts/manager.externalregistry/classes.externalregistrymanager.ts @@ -0,0 +1,51 @@ +import * as plugins from '../plugins.js'; +import { Cloudly } from '../classes.cloudly.js'; +import { ExternalRegistry } from './classes.externalregistry.js'; + +export class ExternalRegistryManager { + public cloudlyRef: Cloudly; + public typedrouter = new plugins.typedrequest.TypedRouter(); + public CExternalRegistry = plugins.smartdata.setDefaultManagerForDoc(this, ExternalRegistry); + + get db() { + return this.cloudlyRef.mongodbConnector.smartdataDb; + } + + constructor(cloudlyRef: Cloudly) { + this.cloudlyRef = cloudlyRef; + } + + public async start() { + // lets set up a typedrouter + this.typedrouter.addTypedRouter(this.typedrouter); + + this.typedrouter.addTypedHandler( + new plugins.typedrequest.TypedHandler('getExternalRegistryById', async (dataArg) => { + const registry = await ExternalRegistry.getRegistryById(dataArg.id); + return { + registry: await registry.createSavableObject(), + }; + }) + ); + + this.typedrouter.addTypedHandler( + new plugins.typedrequest.TypedHandler('getExternalRegistries', async (dataArg) => { + const registries = await ExternalRegistry.getRegistries(); + return { + registries: await Promise.all( + registries.map((registry) => registry.createSavableObject()) + ), + }; + }) + ); + + this.typedrouter.addTypedHandler( + new plugins.typedrequest.TypedHandler('createExternalRegistry', async (dataArg) => { + const registry = await ExternalRegistry.createExternalRegistry(dataArg.registryData); + return { + registry: await registry.createSavableObject(), + }; + }) + ); + } +} diff --git a/ts/manager.externalregistry/index.ts b/ts/manager.externalregistry/index.ts new file mode 100644 index 0000000..42e940a --- /dev/null +++ b/ts/manager.externalregistry/index.ts @@ -0,0 +1,2 @@ +export * from './classes.externalregistrymanager.js'; +export * from './classes.externalregistry.js'; diff --git a/ts/manager.regsitry/classes.externalregistry.ts b/ts/manager.regsitry/classes.externalregistry.ts deleted file mode 100644 index 0bae5c5..0000000 --- a/ts/manager.regsitry/classes.externalregistry.ts +++ /dev/null @@ -1,30 +0,0 @@ -import * as plugins from '../plugins.js'; -import * as paths from '../paths.js'; -import type { Cloudly } from 'ts/classes.cloudly.js'; - -export class ExternalRegistry extends plugins.smartdata.SmartDataDbDoc { - // STATIC - public async getRegistryById(registryNameArg: string) { - this - } - - // INSTANCE - public cloudlyRef: Cloudly; - public smartdataDb: plugins.smartdata.SmartdataDb; - - @plugins.smartdata.svDb() - public id: string; - - @plugins.smartdata.svDb() - public data: plugins.servezoneInterfaces.data.IExternalRegistry['data']; - - get db() { - return this.cloudlyRef.mongodbConnector.smartdataDb; - } - - constructor(cloudlyRef: Cloudly) { - super(); - this.cloudlyRef = cloudlyRef; - } - -} diff --git a/ts_apiclient/classes.externalregistry.ts b/ts_apiclient/classes.externalregistry.ts index d957dd2..a4db200 100644 --- a/ts_apiclient/classes.externalregistry.ts +++ b/ts_apiclient/classes.externalregistry.ts @@ -9,7 +9,7 @@ export class ExternalRegistry implements plugins.servezoneInterfaces.data.IExter ); const response = await getRegistryByIdTR.fire({ identity: cloudlyClientRef.identity, - registryName: registryNameArg, + id: registryNameArg, }); const newRegistry = new ExternalRegistry(cloudlyClientRef); Object.assign(newRegistry, response.registry); diff --git a/ts_interfaces/requests/externalregistry.ts b/ts_interfaces/requests/externalregistry.ts index 0878985..e8c9648 100644 --- a/ts_interfaces/requests/externalregistry.ts +++ b/ts_interfaces/requests/externalregistry.ts @@ -9,7 +9,7 @@ export interface IReq_GetRegistryById extends plugins.typedrequestInterfaces.imp method: 'getExternalRegistryById'; request: { identity: userInterfaces.IIdentity; - registryName: string; + id: string; }; response: { registry: data.IExternalRegistry; diff --git a/ts_web/00_commitinfo_data.ts b/ts_web/00_commitinfo_data.ts index f525271..8e95a13 100644 --- a/ts_web/00_commitinfo_data.ts +++ b/ts_web/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@serve.zone/cloudly', - version: '4.10.0', + version: '4.11.0', description: 'A comprehensive tool for managing containerized applications across multiple cloud providers using Docker Swarmkit, featuring web, CLI, and API interfaces.' }