From fb4a768df53d6c3fa34d05419a9110100cefc82a Mon Sep 17 00:00:00 2001 From: eti-codefresh Date: Sat, 17 Jun 2023 23:00:35 +0300 Subject: [PATCH 01/17] CR-16812 add new cmd to get runtime env images --- .../runtimeEnvironments/get-images.cmd.js | 36 +++++++++++++++++++ .../entities/RuntimeEnvironmentsImages.js | 17 +++++++++ openapi.json | 25 +++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 lib/interface/cli/commands/runtimeEnvironments/get-images.cmd.js create mode 100644 lib/logic/entities/RuntimeEnvironmentsImages.js diff --git a/lib/interface/cli/commands/runtimeEnvironments/get-images.cmd.js b/lib/interface/cli/commands/runtimeEnvironments/get-images.cmd.js new file mode 100644 index 000000000..aaa9ac37e --- /dev/null +++ b/lib/interface/cli/commands/runtimeEnvironments/get-images.cmd.js @@ -0,0 +1,36 @@ +const _ = require('lodash'); +const Command = require('../../Command'); +const RuntimeEnvironmentsImages = require('../../../../logic/entities/RuntimeEnvironmentsImages'); +const Output = require('../../../../output/Output'); +require('../../defaults'); +const CFError = require('cf-errors'); // eslint-disable-line +const getRoot = require('../root/get.cmd'); +const { sdk } = require('../../../../logic'); +require('../../../../logic/entities/Environment'); + +const command = new Command({ + command: 'runtime-environments-images [name]', + aliases: ['re-images'], + parent: getRoot, + description: 'Get a runtime environments images list that required by this runtime', // todo: edit description + webDocs: { + category: 'Runtime-Environments', + title: 'Get Runtime-Environments-Images', + }, + builder: (yargs) => yargs + .positional('name', { + describe: 'Runtime environments name', + }), + handler: async (argv) => { + const { name } = argv; + if (!name) { + throw new CFError('Runtime Name must be provided'); + } + const runtimeEnvImages = await sdk.runtimeEnvs.getImages({ + name, + }); + Output.print(_.map(runtimeEnvImages, RuntimeEnvironmentsImages.fromResponse)); + }, +}); + +module.exports = command; diff --git a/lib/logic/entities/RuntimeEnvironmentsImages.js b/lib/logic/entities/RuntimeEnvironmentsImages.js new file mode 100644 index 000000000..b3f3a40ca --- /dev/null +++ b/lib/logic/entities/RuntimeEnvironmentsImages.js @@ -0,0 +1,17 @@ +const Entity = require('./Entity'); + +class RuntimeEnvironmentsImages extends Entity { + constructor(data) { + super(); + this.entityType = 'RuntimeEnvironmentsImages'; + this.name = data.name; + this.image = data.image; + this.defaultColumns = ['name', 'image']; + this.wideColumns = this.defaultColumns.concat([]); + } + + static fromResponse(response) { + return new RuntimeEnvironmentsImages(response); + } +} +module.exports = RuntimeEnvironmentsImages; diff --git a/openapi.json b/openapi.json index 9d4e8a1b3..9f591af86 100644 --- a/openapi.json +++ b/openapi.json @@ -7436,6 +7436,31 @@ "x-sdk-interface": "runtimeEnvs.get" } }, + "/runtime-environments/{name}/images": { + "get": { + "responses": { + "200": { + "description": "ok" + } + }, + "tags": [ + "runtimeEnvs" + ], + "operationId": "runtime-envs-get-images", + "parameters": [ + { + "in": "path", + "name": "name", + "schema": { + "type": "string" + }, + "required": true + } + ], + "summary": "Get images", + "x-sdk-interface": "runtimeEnvs.getImages" + } + }, "/runtime/testit": { "post": { "responses": { From ce04379b81f18a5d7037e3a62ab43fe8cd08b3d6 Mon Sep 17 00:00:00 2001 From: eti-codefresh Date: Sat, 17 Jun 2023 23:01:02 +0300 Subject: [PATCH 02/17] remove to do --- .../cli/commands/runtimeEnvironments/get-images.cmd.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/interface/cli/commands/runtimeEnvironments/get-images.cmd.js b/lib/interface/cli/commands/runtimeEnvironments/get-images.cmd.js index aaa9ac37e..be4d66238 100644 --- a/lib/interface/cli/commands/runtimeEnvironments/get-images.cmd.js +++ b/lib/interface/cli/commands/runtimeEnvironments/get-images.cmd.js @@ -12,7 +12,7 @@ const command = new Command({ command: 'runtime-environments-images [name]', aliases: ['re-images'], parent: getRoot, - description: 'Get a runtime environments images list that required by this runtime', // todo: edit description + description: 'Get a runtime environments images list that required by this runtime', webDocs: { category: 'Runtime-Environments', title: 'Get Runtime-Environments-Images', From adeab0a10fb16ac58182583dbad3d9c9a17f8795 Mon Sep 17 00:00:00 2001 From: eti-codefresh Date: Sun, 18 Jun 2023 09:45:31 +0300 Subject: [PATCH 03/17] bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bbd84faf2..22f85ee60 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "codefresh", - "version": "0.84.3", + "version": "0.84.5", "description": "Codefresh command line utility", "main": "index.js", "preferGlobal": true, From 1825b76cab77e07de88588051849447a3737496e Mon Sep 17 00:00:00 2001 From: eti-codefresh Date: Sun, 18 Jun 2023 10:34:49 +0300 Subject: [PATCH 04/17] rename --- .../cli/commands/runtimeEnvironments/get-images.cmd.js | 10 +++++----- lib/logic/entities/RuntimeEnvironmentsImages.js | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/interface/cli/commands/runtimeEnvironments/get-images.cmd.js b/lib/interface/cli/commands/runtimeEnvironments/get-images.cmd.js index be4d66238..6862f0cd1 100644 --- a/lib/interface/cli/commands/runtimeEnvironments/get-images.cmd.js +++ b/lib/interface/cli/commands/runtimeEnvironments/get-images.cmd.js @@ -9,17 +9,17 @@ const { sdk } = require('../../../../logic'); require('../../../../logic/entities/Environment'); const command = new Command({ - command: 'runtime-environments-images [name]', + command: 'runtime-environment-images [name]', aliases: ['re-images'], parent: getRoot, - description: 'Get a runtime environments images list that required by this runtime', + description: 'Get a runtime environment images list that required by this runtime', webDocs: { - category: 'Runtime-Environments', - title: 'Get Runtime-Environments-Images', + category: 'Runtime-Environment', + title: 'Get Runtime-Environment-Images', }, builder: (yargs) => yargs .positional('name', { - describe: 'Runtime environments name', + describe: 'Runtime environment name', }), handler: async (argv) => { const { name } = argv; diff --git a/lib/logic/entities/RuntimeEnvironmentsImages.js b/lib/logic/entities/RuntimeEnvironmentsImages.js index b3f3a40ca..5aa065a21 100644 --- a/lib/logic/entities/RuntimeEnvironmentsImages.js +++ b/lib/logic/entities/RuntimeEnvironmentsImages.js @@ -1,9 +1,9 @@ const Entity = require('./Entity'); -class RuntimeEnvironmentsImages extends Entity { +class RuntimeEnvironmentImages extends Entity { constructor(data) { super(); - this.entityType = 'RuntimeEnvironmentsImages'; + this.entityType = 'RuntimeEnvironmentImages'; this.name = data.name; this.image = data.image; this.defaultColumns = ['name', 'image']; @@ -11,7 +11,7 @@ class RuntimeEnvironmentsImages extends Entity { } static fromResponse(response) { - return new RuntimeEnvironmentsImages(response); + return new RuntimeEnvironmentImages(response); } } -module.exports = RuntimeEnvironmentsImages; +module.exports = RuntimeEnvironmentImages; From 80b865e567ed468529f5c360d88ad6b34d863273 Mon Sep 17 00:00:00 2001 From: eti-codefresh Date: Sun, 18 Jun 2023 11:30:02 +0300 Subject: [PATCH 05/17] rename --- .../cli/commands/runtimeEnvironments/get-images.cmd.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/interface/cli/commands/runtimeEnvironments/get-images.cmd.js b/lib/interface/cli/commands/runtimeEnvironments/get-images.cmd.js index 6862f0cd1..074f05c80 100644 --- a/lib/interface/cli/commands/runtimeEnvironments/get-images.cmd.js +++ b/lib/interface/cli/commands/runtimeEnvironments/get-images.cmd.js @@ -14,7 +14,7 @@ const command = new Command({ parent: getRoot, description: 'Get a runtime environment images list that required by this runtime', webDocs: { - category: 'Runtime-Environment', + category: 'Runtime-Environments', title: 'Get Runtime-Environment-Images', }, builder: (yargs) => yargs From 6360162637a20928c6b99ed276e8fc38264bdfa2 Mon Sep 17 00:00:00 2001 From: eti-codefresh Date: Sun, 18 Jun 2023 17:09:23 +0300 Subject: [PATCH 06/17] add 404 response --- openapi.json | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/openapi.json b/openapi.json index 9f591af86..1c99e5194 100644 --- a/openapi.json +++ b/openapi.json @@ -7441,6 +7441,22 @@ "responses": { "200": { "description": "ok" + }, + "404": { + "description": "Runtime Not found", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/responses/Json" + }, + "example": { + "status": 404, + "code": "101", + "name": "NOT_FOUND_ERROR", + "message": "Runtime Environment: \"runtimeEnvironmentName\" not found" + } + } + } } }, "tags": [ From 5c03d4dc9dc02bafa646e0eaa4c6564b5b529139 Mon Sep 17 00:00:00 2001 From: eti-codefresh Date: Tue, 27 Jun 2023 18:22:14 +0300 Subject: [PATCH 07/17] refactor names --- ...get-images.cmd.js => get-base-images.cmd.js} | 12 ++++++------ .../entities/RuntimeEnvironmentBaseImages.js | 17 +++++++++++++++++ lib/logic/entities/RuntimeEnvironmentsImages.js | 17 ----------------- openapi.json | 6 +++--- 4 files changed, 26 insertions(+), 26 deletions(-) rename lib/interface/cli/commands/runtimeEnvironments/{get-images.cmd.js => get-base-images.cmd.js} (73%) create mode 100644 lib/logic/entities/RuntimeEnvironmentBaseImages.js delete mode 100644 lib/logic/entities/RuntimeEnvironmentsImages.js diff --git a/lib/interface/cli/commands/runtimeEnvironments/get-images.cmd.js b/lib/interface/cli/commands/runtimeEnvironments/get-base-images.cmd.js similarity index 73% rename from lib/interface/cli/commands/runtimeEnvironments/get-images.cmd.js rename to lib/interface/cli/commands/runtimeEnvironments/get-base-images.cmd.js index 074f05c80..60640cce8 100644 --- a/lib/interface/cli/commands/runtimeEnvironments/get-images.cmd.js +++ b/lib/interface/cli/commands/runtimeEnvironments/get-base-images.cmd.js @@ -1,6 +1,6 @@ const _ = require('lodash'); const Command = require('../../Command'); -const RuntimeEnvironmentsImages = require('../../../../logic/entities/RuntimeEnvironmentsImages'); +const RuntimeEnvironmentsImages = require('../../../../logic/entities/RuntimeEnvironmentBaseImages'); const Output = require('../../../../output/Output'); require('../../defaults'); const CFError = require('cf-errors'); // eslint-disable-line @@ -9,13 +9,13 @@ const { sdk } = require('../../../../logic'); require('../../../../logic/entities/Environment'); const command = new Command({ - command: 'runtime-environment-images [name]', - aliases: ['re-images'], + command: 'runtime-environment-base-images [name]', + aliases: ['re-base-images'], parent: getRoot, - description: 'Get a runtime environment images list that required by this runtime', + description: 'Get a runtime environment base images list that required by this runtime', webDocs: { category: 'Runtime-Environments', - title: 'Get Runtime-Environment-Images', + title: 'Get Runtime-Environment-Base-Images', }, builder: (yargs) => yargs .positional('name', { @@ -26,7 +26,7 @@ const command = new Command({ if (!name) { throw new CFError('Runtime Name must be provided'); } - const runtimeEnvImages = await sdk.runtimeEnvs.getImages({ + const runtimeEnvImages = await sdk.runtimeEnvs.getBaseImages({ name, }); Output.print(_.map(runtimeEnvImages, RuntimeEnvironmentsImages.fromResponse)); diff --git a/lib/logic/entities/RuntimeEnvironmentBaseImages.js b/lib/logic/entities/RuntimeEnvironmentBaseImages.js new file mode 100644 index 000000000..70619fe11 --- /dev/null +++ b/lib/logic/entities/RuntimeEnvironmentBaseImages.js @@ -0,0 +1,17 @@ +const Entity = require('./Entity'); + +class RuntimeEnvironmentBaseImages extends Entity { + constructor(data) { + super(); + this.entityType = 'RuntimeEnvironmentBaseImages'; + this.component = data.component; + this.image = data.image; + this.defaultColumns = ['component', 'image']; + this.wideColumns = this.defaultColumns.concat([]); + } + + static fromResponse(response) { + return new RuntimeEnvironmentBaseImages(response); + } +} +module.exports = RuntimeEnvironmentBaseImages; diff --git a/lib/logic/entities/RuntimeEnvironmentsImages.js b/lib/logic/entities/RuntimeEnvironmentsImages.js deleted file mode 100644 index 5aa065a21..000000000 --- a/lib/logic/entities/RuntimeEnvironmentsImages.js +++ /dev/null @@ -1,17 +0,0 @@ -const Entity = require('./Entity'); - -class RuntimeEnvironmentImages extends Entity { - constructor(data) { - super(); - this.entityType = 'RuntimeEnvironmentImages'; - this.name = data.name; - this.image = data.image; - this.defaultColumns = ['name', 'image']; - this.wideColumns = this.defaultColumns.concat([]); - } - - static fromResponse(response) { - return new RuntimeEnvironmentImages(response); - } -} -module.exports = RuntimeEnvironmentImages; diff --git a/openapi.json b/openapi.json index 1c99e5194..026442f1e 100644 --- a/openapi.json +++ b/openapi.json @@ -7436,7 +7436,7 @@ "x-sdk-interface": "runtimeEnvs.get" } }, - "/runtime-environments/{name}/images": { + "/runtime-environments/{name}/base-images": { "get": { "responses": { "200": { @@ -7462,7 +7462,7 @@ "tags": [ "runtimeEnvs" ], - "operationId": "runtime-envs-get-images", + "operationId": "runtime-envs-get-base-images", "parameters": [ { "in": "path", @@ -7474,7 +7474,7 @@ } ], "summary": "Get images", - "x-sdk-interface": "runtimeEnvs.getImages" + "x-sdk-interface": "runtimeEnvs.getBaseImages" } }, "/runtime/testit": { From b1b2f15374b89500066698eacda7d751ae48317e Mon Sep 17 00:00:00 2001 From: eti-codefresh Date: Tue, 27 Jun 2023 21:27:45 +0300 Subject: [PATCH 08/17] Empty commit From e1bf696ff9d3283af81a541c136eb91ef6a475ca Mon Sep 17 00:00:00 2001 From: eti-codefresh Date: Wed, 28 Jun 2023 17:50:08 +0300 Subject: [PATCH 09/17] add tests --- .../runtimeEnvironments.sdk.spec.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/interface/cli/commands/runtimeEnvironments/runtimeEnvironments.sdk.spec.js b/lib/interface/cli/commands/runtimeEnvironments/runtimeEnvironments.sdk.spec.js index cf02f6292..18004662f 100644 --- a/lib/interface/cli/commands/runtimeEnvironments/runtimeEnvironments.sdk.spec.js +++ b/lib/interface/cli/commands/runtimeEnvironments/runtimeEnvironments.sdk.spec.js @@ -1,6 +1,7 @@ const getCmd = require('./get.cmd').toCommand(); const applyCmd = require('./apply.cmd').toCommand(); const diffCmd = require('./diff.cmd').toCommand(); +const getBaseImagesCmd = require('./get-base-images.cmd').toCommand(); jest.mock('../../../../logic/entities/RuntimeEnvironments'); @@ -38,6 +39,21 @@ describe('runtime environment commands', () => { await getCmd.handler(argv); await verifyResponsesReturned([response]); // eslint-disable-line }); + + it('should handle getting base images', async () => { + const argv = { name: 'some name' }; + await getBaseImagesCmd.handler(argv); + await verifyResponsesReturned([DEFAULT_RESPONSE]); // eslint-disable-line + }); + + it('should throw an error for missing name', async () => { + try { + const argv = {}; + await getBaseImagesCmd.handler(argv); + } catch (err) { + expect(err.message).toEqual('Runtime Name must be provided'); + } + }); }); describe('apply', () => { From dd1e86c7ce8646d0ad8a631407f1dc5bbaa7d4a6 Mon Sep 17 00:00:00 2001 From: eti-codefresh Date: Thu, 29 Jun 2023 11:28:11 +0300 Subject: [PATCH 10/17] Empty commit From ff1fca67c6c01ac751d4246c22cfa35e7110445f Mon Sep 17 00:00:00 2001 From: eti-codefresh Date: Thu, 29 Jun 2023 17:29:54 +0300 Subject: [PATCH 11/17] Empty commit From 6d221731bd0ef7ce32d5d6c3f9b85de30b43491d Mon Sep 17 00:00:00 2001 From: eti-codefresh Date: Thu, 29 Jun 2023 18:27:30 +0300 Subject: [PATCH 12/17] Empty commit From 702d70f57523a2c9d8c3556bd2dbdab6b9d67c41 Mon Sep 17 00:00:00 2001 From: eti-codefresh Date: Mon, 3 Jul 2023 07:43:50 +0300 Subject: [PATCH 13/17] Empty commit From 120ad1e9c963adaf818530ac6143a995fc271b07 Mon Sep 17 00:00:00 2001 From: eti-codefresh Date: Mon, 3 Jul 2023 11:19:48 +0300 Subject: [PATCH 14/17] Empty commit From 94de00aaf304ba7763926115d92043f04a1e427b Mon Sep 17 00:00:00 2001 From: eti-codefresh Date: Mon, 3 Jul 2023 13:09:58 +0300 Subject: [PATCH 15/17] Add new cmd to get runtime env images --- .../cli/commands/runtimeEnvironments/get-base-images.cmd.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/interface/cli/commands/runtimeEnvironments/get-base-images.cmd.js b/lib/interface/cli/commands/runtimeEnvironments/get-base-images.cmd.js index 60640cce8..4308d30f8 100644 --- a/lib/interface/cli/commands/runtimeEnvironments/get-base-images.cmd.js +++ b/lib/interface/cli/commands/runtimeEnvironments/get-base-images.cmd.js @@ -33,4 +33,5 @@ const command = new Command({ }, }); + module.exports = command; From c5c875158bcb704ea99f6cdd8a0d2ce827208c7e Mon Sep 17 00:00:00 2001 From: eti-codefresh Date: Mon, 3 Jul 2023 14:19:04 +0300 Subject: [PATCH 16/17] create new entity for Runtime-Environments-Base-Images --- .../get.cmd.js} | 2 +- .../runtimeEnvironmentsBaseImages.sdk.spec.js | 32 +++++++++++++++++++ .../runtimeEnvironments.sdk.spec.js | 16 ---------- 3 files changed, 33 insertions(+), 17 deletions(-) rename lib/interface/cli/commands/{runtimeEnvironments/get-base-images.cmd.js => RuntimeEnvironmentBaseImages/get.cmd.js} (95%) create mode 100644 lib/interface/cli/commands/RuntimeEnvironmentBaseImages/runtimeEnvironmentsBaseImages.sdk.spec.js diff --git a/lib/interface/cli/commands/runtimeEnvironments/get-base-images.cmd.js b/lib/interface/cli/commands/RuntimeEnvironmentBaseImages/get.cmd.js similarity index 95% rename from lib/interface/cli/commands/runtimeEnvironments/get-base-images.cmd.js rename to lib/interface/cli/commands/RuntimeEnvironmentBaseImages/get.cmd.js index 4308d30f8..0c8217191 100644 --- a/lib/interface/cli/commands/runtimeEnvironments/get-base-images.cmd.js +++ b/lib/interface/cli/commands/RuntimeEnvironmentBaseImages/get.cmd.js @@ -14,7 +14,7 @@ const command = new Command({ parent: getRoot, description: 'Get a runtime environment base images list that required by this runtime', webDocs: { - category: 'Runtime-Environments', + category: 'Runtime-Environments-Base-Images', title: 'Get Runtime-Environment-Base-Images', }, builder: (yargs) => yargs diff --git a/lib/interface/cli/commands/RuntimeEnvironmentBaseImages/runtimeEnvironmentsBaseImages.sdk.spec.js b/lib/interface/cli/commands/RuntimeEnvironmentBaseImages/runtimeEnvironmentsBaseImages.sdk.spec.js new file mode 100644 index 000000000..ca1beb746 --- /dev/null +++ b/lib/interface/cli/commands/RuntimeEnvironmentBaseImages/runtimeEnvironmentsBaseImages.sdk.spec.js @@ -0,0 +1,32 @@ +const getCmd = require('./get.cmd').toCommand(); + +jest.mock('../../../../logic/entities/RuntimeEnvironments'); + +const request = require('requestretry'); + +const DEFAULT_RESPONSE = request.__defaultResponse(); + +describe('runtime environment commands', () => { + beforeEach(async () => { + request.__reset(); + request.mockClear(); + await configureSdk(); // eslint-disable-line + }); + + describe('get', () => { + it('should handle getting base images', async () => { + const argv = { name: 'some name' }; + await getCmd.handler(argv); + await verifyResponsesReturned([DEFAULT_RESPONSE]); // eslint-disable-line + }); + + it('should throw an error for missing name', async () => { + try { + const argv = {}; + await getCmd.handler(argv); + } catch (err) { + expect(err.message).toEqual('Runtime Name must be provided'); + } + }); + }); +}); diff --git a/lib/interface/cli/commands/runtimeEnvironments/runtimeEnvironments.sdk.spec.js b/lib/interface/cli/commands/runtimeEnvironments/runtimeEnvironments.sdk.spec.js index 18004662f..cf02f6292 100644 --- a/lib/interface/cli/commands/runtimeEnvironments/runtimeEnvironments.sdk.spec.js +++ b/lib/interface/cli/commands/runtimeEnvironments/runtimeEnvironments.sdk.spec.js @@ -1,7 +1,6 @@ const getCmd = require('./get.cmd').toCommand(); const applyCmd = require('./apply.cmd').toCommand(); const diffCmd = require('./diff.cmd').toCommand(); -const getBaseImagesCmd = require('./get-base-images.cmd').toCommand(); jest.mock('../../../../logic/entities/RuntimeEnvironments'); @@ -39,21 +38,6 @@ describe('runtime environment commands', () => { await getCmd.handler(argv); await verifyResponsesReturned([response]); // eslint-disable-line }); - - it('should handle getting base images', async () => { - const argv = { name: 'some name' }; - await getBaseImagesCmd.handler(argv); - await verifyResponsesReturned([DEFAULT_RESPONSE]); // eslint-disable-line - }); - - it('should throw an error for missing name', async () => { - try { - const argv = {}; - await getBaseImagesCmd.handler(argv); - } catch (err) { - expect(err.message).toEqual('Runtime Name must be provided'); - } - }); }); describe('apply', () => { From 7b565a6cd82710fb06e79788c560fe19c1f60e0e Mon Sep 17 00:00:00 2001 From: eti-codefresh Date: Mon, 3 Jul 2023 14:55:39 +0300 Subject: [PATCH 17/17] Empty commit