From 89bd767bea4f2ba8006113fb0b570f3a28d69c94 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Sun, 29 Dec 2024 13:19:46 +0100 Subject: [PATCH] feat(apiclient): Add external registry management capabilities to Cloudly API client. --- changelog.md | 6 ++ ts/00_commitinfo_data.ts | 2 +- ts_apiclient/classes.externalregistry.ts | 84 ++++++++++++++++++++++ ts_interfaces/requests/externalregistry.ts | 73 +++++++++++++++++++ ts_interfaces/requests/index.ts | 2 + ts_web/00_commitinfo_data.ts | 2 +- 6 files changed, 167 insertions(+), 2 deletions(-) create mode 100644 ts_apiclient/classes.externalregistry.ts create mode 100644 ts_interfaces/requests/externalregistry.ts diff --git a/changelog.md b/changelog.md index 8b83da3..7179ac0 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,11 @@ # Changelog +## 2024-12-29 - 4.9.0 - feat(apiclient) +Add external registry management capabilities to Cloudly API client. + +- Introduce ExternalRegistry class with methods for getting, creating, and updating external registries. +- Expand requests module to handle external registry management, including creation and deletion. + ## 2024-12-28 - 4.8.1 - fix(interfaces) Fix image location schema in IImage interface diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index dc5bbb4..00c57fc 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.8.1', + version: '4.9.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_apiclient/classes.externalregistry.ts b/ts_apiclient/classes.externalregistry.ts new file mode 100644 index 0000000..4806375 --- /dev/null +++ b/ts_apiclient/classes.externalregistry.ts @@ -0,0 +1,84 @@ +import * as plugins from './plugins.js'; +import type { CloudlyApiClient } from './classes.cloudlyapiclient.js'; + +export class ExternalRegistry implements plugins.servezoneInterfaces.data.IExternalRegistry { + // STATIC + public static async getRegistryById(cloudlyClientRef: CloudlyApiClient, registryNameArg: string) { + const getRegistryByIdTR = cloudlyClientRef.typedsocketClient.createTypedRequest( + 'getExternalRegistryById' + ); + const response = await getRegistryByIdTR.fire({ + identity: cloudlyClientRef.identity, + registryName: registryNameArg, + }); + const newRegistry = new ExternalRegistry(cloudlyClientRef); + Object.assign(newRegistry, response.registry); + return newRegistry; + } + + public static async getRegistries(cloudlyClientRef: CloudlyApiClient) { + const getRegistriesTR = cloudlyClientRef.typedsocketClient.createTypedRequest( + 'getExternalRegistries' + ); + const response = await getRegistriesTR.fire({ + identity: cloudlyClientRef.identity, + }); + const registryConfigs: ExternalRegistry[] = []; + for (const registryConfig of response.registries) { + const newRegistry = new ExternalRegistry(cloudlyClientRef); + Object.assign(newRegistry, registryConfig); + registryConfigs.push(newRegistry); + } + return registryConfigs; + } + + public static async createRegistry(cloudlyClientRef: CloudlyApiClient, registryNameArg: string, registryDataArg: Partial) { + const createRegistryTR = cloudlyClientRef.typedsocketClient.createTypedRequest( + 'createExternalRegistry' + ); + const response = await createRegistryTR.fire({ + identity: cloudlyClientRef.identity, + registryName: registryNameArg, + registryData: registryDataArg as plugins.servezoneInterfaces.data.IExternalRegistry['data'], + }); + const newRegistry = new ExternalRegistry(cloudlyClientRef); + Object.assign(newRegistry, response.registry); + return newRegistry; + } + + // INSTANCE + public id: string; + public data: plugins.servezoneInterfaces.data.IExternalRegistry['data']; + public cloudlyClientRef: CloudlyApiClient; + + constructor(cloudlyClientRef: CloudlyApiClient) { + this.cloudlyClientRef = cloudlyClientRef; + } + + public async update() { + const updateRegistryTR = this.cloudlyClientRef.typedsocketClient.createTypedRequest( + 'updateExternalRegistry' + ); + const response = await updateRegistryTR.fire({ + identity: this.cloudlyClientRef.identity, + registryData: this.data, + }); + + const resultRegistryData = response.resultRegistry.data; + plugins.smartexpect.expect(resultRegistryData).toEqual(this.data); + + return this; + } + + public async delete(cloudlyClientRef: CloudlyApiClient, registryIdArg: string) { + const deleteRegistryTR = cloudlyClientRef.typedsocketClient.createTypedRequest( + 'deleteExternalRegistryById' + ); + const response = await deleteRegistryTR.fire({ + identity: cloudlyClientRef.identity, + registryId: this.id, + }); + plugins.smartexpect.expect(response.ok).toBeTrue(); + return null; + } +} diff --git a/ts_interfaces/requests/externalregistry.ts b/ts_interfaces/requests/externalregistry.ts new file mode 100644 index 0000000..2c7f879 --- /dev/null +++ b/ts_interfaces/requests/externalregistry.ts @@ -0,0 +1,73 @@ +import * as plugins from '../plugins.js'; +import * as data from '../data/index.js'; +import * as userInterfaces from '../data/user.js'; + +export interface IReq_GetRegistryById extends plugins.typedrequestInterfaces.implementsTR< + plugins.typedrequestInterfaces.ITypedRequest, + IReq_GetRegistryById +> { + method: 'getExternalRegistryById'; + request: { + identity: userInterfaces.IIdentity; + registryName: string; + }; + response: { + registry: data.IExternalRegistry; + }; +} + +export interface IReq_GetRegistries extends plugins.typedrequestInterfaces.implementsTR< + plugins.typedrequestInterfaces.ITypedRequest, + IReq_GetRegistries +> { + method: 'getExternalRegistries'; + request: { + identity: userInterfaces.IIdentity; + }; + response: { + registries: data.IExternalRegistry[]; + }; +} + +export interface IReq_CreateRegistry extends plugins.typedrequestInterfaces.implementsTR< + plugins.typedrequestInterfaces.ITypedRequest, + IReq_CreateRegistry +> { + method: 'createExternalRegistry'; + request: { + identity: userInterfaces.IIdentity; + registryName: string; + registryData: data.IExternalRegistry['data']; + }; + response: { + registry: data.IExternalRegistry; + }; +} + +export interface IReq_UpdateRegistry extends plugins.typedrequestInterfaces.implementsTR< + plugins.typedrequestInterfaces.ITypedRequest, + IReq_UpdateRegistry +> { + method: 'updateExternalRegistry'; + request: { + identity: userInterfaces.IIdentity; + registryData: data.IExternalRegistry['data']; + }; + response: { + resultRegistry: data.IExternalRegistry; + }; +} + +export interface IReq_DeleteRegistryById extends plugins.typedrequestInterfaces.implementsTR< + plugins.typedrequestInterfaces.ITypedRequest, + IReq_DeleteRegistryById +> { + method: 'deleteExternalRegistryById'; + request: { + identity: userInterfaces.IIdentity; + registryId: string; + }; + response: { + ok: boolean; + }; +} \ No newline at end of file diff --git a/ts_interfaces/requests/index.ts b/ts_interfaces/requests/index.ts index 96d0a4f..d303a36 100644 --- a/ts_interfaces/requests/index.ts +++ b/ts_interfaces/requests/index.ts @@ -4,6 +4,7 @@ import * as adminRequests from './admin.js'; import * as certificateRequests from './certificate.js'; import * as clusterRequests from './cluster.js'; import * as configRequests from './config.js'; +import * as externalRegistryRequests from './externalregistry.js'; import * as identityRequests from './identity.js'; import * as imageRequests from './image.js'; import * as informRequests from './inform.js'; @@ -22,6 +23,7 @@ export { certificateRequests as certificate, clusterRequests as cluster, configRequests as config, + externalRegistryRequests as externalRegistry, identityRequests as identity, imageRequests as image, informRequests as inform, diff --git a/ts_web/00_commitinfo_data.ts b/ts_web/00_commitinfo_data.ts index dc5bbb4..00c57fc 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.8.1', + version: '4.9.0', description: 'A comprehensive tool for managing containerized applications across multiple cloud providers using Docker Swarmkit, featuring web, CLI, and API interfaces.' }