From 55b2872ffc7fec04e23056925808c8782a19de7d Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Wed, 5 Jun 2024 14:13:03 +0200 Subject: [PATCH] fix(structure): improve structure, prepare better CI integration --- test/test.apiclient.ts | 24 ++++++++++++++ test/test.ts | 19 ++++++------ ts/00_commitinfo_data.ts | 2 +- ts/index.ts | 2 ++ ...yclient.ts => classes.cloudlyapiclient.ts} | 31 ++++++++++--------- ts_apiclient/classes.image.ts | 8 ++--- ts_apiclient/index.ts | 2 +- ts_web/00_commitinfo_data.ts | 2 +- 8 files changed, 58 insertions(+), 32 deletions(-) create mode 100644 test/test.apiclient.ts rename ts_apiclient/{classes.cloudlyclient.ts => classes.cloudlyapiclient.ts} (83%) diff --git a/test/test.apiclient.ts b/test/test.apiclient.ts new file mode 100644 index 0000000..d754585 --- /dev/null +++ b/test/test.apiclient.ts @@ -0,0 +1,24 @@ +import { tap, expect } from '@push.rocks/tapbundle'; + +import * as cloudlyApiClient from '../ts_apiclient/index.js'; + +let testClient: cloudlyApiClient.CloudlyApiClient; + +tap.test('should create a new cloudlyApiClient', async () => { + testClient = new cloudlyApiClient.CloudlyApiClient({ + registerAs: 'api', + cloudlyUrl: 'http://localhost:3000', + }); + await testClient.start(); + expect(testClient).toBeTruthy(); +}); + +tap.test('should trigger a server action', async () => { + +}) + +tap.test('should stop the apiclient', async () => { + await testClient.stop(); +}) + +export default tap.start(); \ No newline at end of file diff --git a/test/test.ts b/test/test.ts index 42cfba5..b849031 100644 --- a/test/test.ts +++ b/test/test.ts @@ -10,20 +10,19 @@ import * as cloudly from '../ts/index.js'; let testCloudly: cloudly.Cloudly; tap.test('first test', async () => { const cloudlyConfig: cloudly.ICloudlyConfig = { - cfToken: testQenv.getEnvVarOnDemand('CF_TOKEN'), + cfToken: await testQenv.getEnvVarOnDemand('CF_TOKEN'), environment: 'integration', - letsEncryptEmail: testQenv.getEnvVarOnDemand('LETSENCRYPT_EMAIL'), - publicUrl: testQenv.getEnvVarOnDemand('SERVEZONE_URL'), - publicPort: testQenv.getEnvVarOnDemand('SERVEZONE_PORT'), + letsEncryptEmail: await testQenv.getEnvVarOnDemand('LETSENCRYPT_EMAIL'), + publicUrl: await testQenv.getEnvVarOnDemand('SERVEZONE_URL'), + publicPort: await testQenv.getEnvVarOnDemand('SERVEZONE_PORT'), mongoDescriptor: { - mongoDbName: testQenv.getEnvVarOnDemand('MONGODB_DATABASE'), - mongoDbUser: testQenv.getEnvVarOnDemand('MONGODB_USER'), - mongoDbPass: testQenv.getEnvVarOnDemand('MONGODB_PASSWORD'), - mongoDbUrl: testQenv.getEnvVarOnDemand('MONGODB_URL'), + mongoDbName: await testQenv.getEnvVarOnDemand('MONGODB_DATABASE'), + mongoDbUser: await testQenv.getEnvVarOnDemand('MONGODB_USER'), + mongoDbPass: await testQenv.getEnvVarOnDemand('MONGODB_PASSWORD'), + mongoDbUrl: await testQenv.getEnvVarOnDemand('MONGODB_URL'), }, - digitalOceanToken: testQenv.getEnvVarOnDemand('DIGITALOCEAN_TOKEN'), }; - testCloudly = new cloudly.Cloudly(cloudlyConfig); + testCloudly = new cloudly.Cloudly(); expect(testCloudly).toBeInstanceOf(cloudly.Cloudly); }); diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index d1c4fef..cf8c986 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: '1.1.2', + version: '1.1.3', description: 'A cloud manager leveraging Docker Swarmkit for multi-cloud operations including DigitalOcean, Hetzner Cloud, and Cloudflare, with integration support and robust configuration management system.' } diff --git a/ts/index.ts b/ts/index.ts index 85efeb1..ad86157 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -26,3 +26,5 @@ const runCli = async () => { }; export { runCli, Cloudly }; +type ICloudlyConfig = plugins.servezoneInterfaces.data.ICloudlyConfig; +export { type ICloudlyConfig } diff --git a/ts_apiclient/classes.cloudlyclient.ts b/ts_apiclient/classes.cloudlyapiclient.ts similarity index 83% rename from ts_apiclient/classes.cloudlyclient.ts rename to ts_apiclient/classes.cloudlyapiclient.ts index 4032666..91a166f 100644 --- a/ts_apiclient/classes.cloudlyclient.ts +++ b/ts_apiclient/classes.cloudlyapiclient.ts @@ -1,10 +1,10 @@ import * as plugins from './plugins.js'; -export type TClientType = 'coreflow' | 'cli' | 'serverconfig'; +export type TClientType = 'api' | 'ci' | 'coreflow' | 'cli' | 'serverconfig'; import { Image } from './classes.image.js'; -export class CloudlyClient { +export class CloudlyApiClient { private cloudlyUrl: string; private registerAs: string; @@ -20,9 +20,13 @@ export class CloudlyClient { plugins.servezoneInterfaces.requests.server.IRequest_TriggerServerAction['request'] >(); - constructor(registerAsArg: TClientType) { - this.cloudlyUrl = process.env.CLOUDLY_URL || 'https://cloudly.layer.io:443'; - this.registerAs = registerAsArg; + constructor(optionsArg?: { + registerAs: TClientType; + cloudlyUrl?: string; + }) { + this.registerAs = optionsArg.registerAs; + this.cloudlyUrl = + optionsArg?.cloudlyUrl || process.env.CLOUDLY_URL || 'https://cloudly.layer.io:443'; console.log( `creating LoleCloudlyClient: registering as ${this.registerAs} and target url ${this.cloudlyUrl}` @@ -35,13 +39,6 @@ export class CloudlyClient { }) ); - this.typedrouter.addTypedHandler( - new plugins.typedrequest.TypedHandler('pushClusterConfig', async (dataArg) => { - this.configUpdateSubject.next(dataArg); - return {}; - }) - ); - this.typedrouter.addTypedHandler( new plugins.typedrequest.TypedHandler('triggerServerAction', async (dataArg) => { this.serverActionSubject.next(dataArg); @@ -57,7 +54,9 @@ export class CloudlyClient { this.typedrouter, this.cloudlyUrl ); - console.log(`CloudlyCluent connected to cloudly at ${this.cloudlyUrl}. Remember to get an identity.`) + console.log( + `CloudlyCluent connected to cloudly at ${this.cloudlyUrl}. Remember to get an identity.` + ); } public async stop() { @@ -115,7 +114,7 @@ export class CloudlyClient { ); const response = await serverConfigRequest.fire({ jwt: '', // TODO: do proper auth here - serverId: '' // TODO: get server id here + serverId: '', // TODO: get server id here }); return response.configData; } @@ -125,7 +124,9 @@ export class CloudlyClient { * @param serviceNameArg * @param domainNameArg */ - public async getCertificateForDomainOverHttps(domainNameArg: string): Promise { + public async getCertificateForDomainOverHttps( + domainNameArg: string + ): Promise { const typedCertificateRequest = this.typedsocketClient.createTypedRequest( 'getSslCertificate' diff --git a/ts_apiclient/classes.image.ts b/ts_apiclient/classes.image.ts index 689a466..8c6a726 100644 --- a/ts_apiclient/classes.image.ts +++ b/ts_apiclient/classes.image.ts @@ -1,8 +1,8 @@ -import type { CloudlyClient } from './classes.cloudlyclient.js'; +import type { CloudlyApiClient } from './classes.cloudlyapiclient.js'; import * as plugins from './plugins.js'; export class Image implements plugins.servezoneInterfaces.data.IImage { - public static async getImages(cloudlyClientRef: CloudlyClient) { + public static async getImages(cloudlyClientRef: CloudlyApiClient) { const getAllImagesTR = cloudlyClientRef.typedsocketClient.createTypedRequest( 'getAllImages' ); @@ -19,12 +19,12 @@ export class Image implements plugins.servezoneInterfaces.data.IImage { } // INSTANCE - cloudlyClientRef: CloudlyClient; + cloudlyClientRef: CloudlyApiClient; id: plugins.servezoneInterfaces.data.IImage['id']; data: plugins.servezoneInterfaces.data.IImage['data']; - constructor(cloudlyClientRef: CloudlyClient) { + constructor(cloudlyClientRef: CloudlyApiClient) { this.cloudlyClientRef = cloudlyClientRef; } diff --git a/ts_apiclient/index.ts b/ts_apiclient/index.ts index 4cffc19..8e3529d 100644 --- a/ts_apiclient/index.ts +++ b/ts_apiclient/index.ts @@ -1 +1 @@ -export * from './classes.cloudlyclient.js'; \ No newline at end of file +export * from './classes.cloudlyapiclient.js'; \ No newline at end of file diff --git a/ts_web/00_commitinfo_data.ts b/ts_web/00_commitinfo_data.ts index d1c4fef..cf8c986 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: '1.1.2', + version: '1.1.3', description: 'A cloud manager leveraging Docker Swarmkit for multi-cloud operations including DigitalOcean, Hetzner Cloud, and Cloudflare, with integration support and robust configuration management system.' }