diff --git a/lib/interface/cli/commands/RuntimeEnvironmentBaseImages/get.cmd.js b/lib/interface/cli/commands/RuntimeEnvironmentBaseImages/get.cmd.js new file mode 100644 index 000000000..0c8217191 --- /dev/null +++ b/lib/interface/cli/commands/RuntimeEnvironmentBaseImages/get.cmd.js @@ -0,0 +1,37 @@ +const _ = require('lodash'); +const Command = require('../../Command'); +const RuntimeEnvironmentsImages = require('../../../../logic/entities/RuntimeEnvironmentBaseImages'); +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-environment-base-images [name]', + aliases: ['re-base-images'], + parent: getRoot, + description: 'Get a runtime environment base images list that required by this runtime', + webDocs: { + category: 'Runtime-Environments-Base-Images', + title: 'Get Runtime-Environment-Base-Images', + }, + builder: (yargs) => yargs + .positional('name', { + describe: 'Runtime environment name', + }), + handler: async (argv) => { + const { name } = argv; + if (!name) { + throw new CFError('Runtime Name must be provided'); + } + const runtimeEnvImages = await sdk.runtimeEnvs.getBaseImages({ + name, + }); + Output.print(_.map(runtimeEnvImages, RuntimeEnvironmentsImages.fromResponse)); + }, +}); + + +module.exports = command; 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/logic/entities/RuntimeEnvironmentBaseImages.js b/lib/logic/entities/RuntimeEnvironmentBaseImages.js new file mode 100644 index 000000000..4fab62a09 --- /dev/null +++ b/lib/logic/entities/RuntimeEnvironmentBaseImages.js @@ -0,0 +1,18 @@ +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/openapi.json b/openapi.json index 9d4e8a1b3..026442f1e 100644 --- a/openapi.json +++ b/openapi.json @@ -7436,6 +7436,47 @@ "x-sdk-interface": "runtimeEnvs.get" } }, + "/runtime-environments/{name}/base-images": { + "get": { + "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": [ + "runtimeEnvs" + ], + "operationId": "runtime-envs-get-base-images", + "parameters": [ + { + "in": "path", + "name": "name", + "schema": { + "type": "string" + }, + "required": true + } + ], + "summary": "Get images", + "x-sdk-interface": "runtimeEnvs.getBaseImages" + } + }, "/runtime/testit": { "post": { "responses": { 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,