Skip to content

Commit

Permalink
Add new cmd to get runtime env images (#823)
Browse files Browse the repository at this point in the history
  • Loading branch information
eti-codefresh authored Jul 3, 2023
1 parent c03b4fa commit fa87afe
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 1 deletion.
37 changes: 37 additions & 0 deletions lib/interface/cli/commands/RuntimeEnvironmentBaseImages/get.cmd.js
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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');
}
});
});
});
18 changes: 18 additions & 0 deletions lib/logic/entities/RuntimeEnvironmentBaseImages.js
Original file line number Diff line number Diff line change
@@ -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;

41 changes: 41 additions & 0 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codefresh",
"version": "0.84.3",
"version": "0.84.5",
"description": "Codefresh command line utility",
"main": "index.js",
"preferGlobal": true,
Expand Down

0 comments on commit fa87afe

Please sign in to comment.