Skip to content

Commit fa87afe

Browse files
Add new cmd to get runtime env images (#823)
1 parent c03b4fa commit fa87afe

File tree

5 files changed

+129
-1
lines changed

5 files changed

+129
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const _ = require('lodash');
2+
const Command = require('../../Command');
3+
const RuntimeEnvironmentsImages = require('../../../../logic/entities/RuntimeEnvironmentBaseImages');
4+
const Output = require('../../../../output/Output');
5+
require('../../defaults');
6+
const CFError = require('cf-errors'); // eslint-disable-line
7+
const getRoot = require('../root/get.cmd');
8+
const { sdk } = require('../../../../logic');
9+
require('../../../../logic/entities/Environment');
10+
11+
const command = new Command({
12+
command: 'runtime-environment-base-images [name]',
13+
aliases: ['re-base-images'],
14+
parent: getRoot,
15+
description: 'Get a runtime environment base images list that required by this runtime',
16+
webDocs: {
17+
category: 'Runtime-Environments-Base-Images',
18+
title: 'Get Runtime-Environment-Base-Images',
19+
},
20+
builder: (yargs) => yargs
21+
.positional('name', {
22+
describe: 'Runtime environment name',
23+
}),
24+
handler: async (argv) => {
25+
const { name } = argv;
26+
if (!name) {
27+
throw new CFError('Runtime Name must be provided');
28+
}
29+
const runtimeEnvImages = await sdk.runtimeEnvs.getBaseImages({
30+
name,
31+
});
32+
Output.print(_.map(runtimeEnvImages, RuntimeEnvironmentsImages.fromResponse));
33+
},
34+
});
35+
36+
37+
module.exports = command;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const getCmd = require('./get.cmd').toCommand();
2+
3+
jest.mock('../../../../logic/entities/RuntimeEnvironments');
4+
5+
const request = require('requestretry');
6+
7+
const DEFAULT_RESPONSE = request.__defaultResponse();
8+
9+
describe('runtime environment commands', () => {
10+
beforeEach(async () => {
11+
request.__reset();
12+
request.mockClear();
13+
await configureSdk(); // eslint-disable-line
14+
});
15+
16+
describe('get', () => {
17+
it('should handle getting base images', async () => {
18+
const argv = { name: 'some name' };
19+
await getCmd.handler(argv);
20+
await verifyResponsesReturned([DEFAULT_RESPONSE]); // eslint-disable-line
21+
});
22+
23+
it('should throw an error for missing name', async () => {
24+
try {
25+
const argv = {};
26+
await getCmd.handler(argv);
27+
} catch (err) {
28+
expect(err.message).toEqual('Runtime Name must be provided');
29+
}
30+
});
31+
});
32+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const Entity = require('./Entity');
2+
3+
class RuntimeEnvironmentBaseImages extends Entity {
4+
constructor(data) {
5+
super();
6+
this.entityType = 'RuntimeEnvironmentBaseImages';
7+
this.component = data.component;
8+
this.image = data.image;
9+
this.defaultColumns = ['component', 'image'];
10+
this.wideColumns = this.defaultColumns.concat([]);
11+
}
12+
13+
static fromResponse(response) {
14+
return new RuntimeEnvironmentBaseImages(response);
15+
}
16+
}
17+
module.exports = RuntimeEnvironmentBaseImages;
18+

openapi.json

+41
Original file line numberDiff line numberDiff line change
@@ -7436,6 +7436,47 @@
74367436
"x-sdk-interface": "runtimeEnvs.get"
74377437
}
74387438
},
7439+
"/runtime-environments/{name}/base-images": {
7440+
"get": {
7441+
"responses": {
7442+
"200": {
7443+
"description": "ok"
7444+
},
7445+
"404": {
7446+
"description": "Runtime Not found",
7447+
"content": {
7448+
"application/json": {
7449+
"schema": {
7450+
"$ref": "#/components/responses/Json"
7451+
},
7452+
"example": {
7453+
"status": 404,
7454+
"code": "101",
7455+
"name": "NOT_FOUND_ERROR",
7456+
"message": "Runtime Environment: \"runtimeEnvironmentName\" not found"
7457+
}
7458+
}
7459+
}
7460+
}
7461+
},
7462+
"tags": [
7463+
"runtimeEnvs"
7464+
],
7465+
"operationId": "runtime-envs-get-base-images",
7466+
"parameters": [
7467+
{
7468+
"in": "path",
7469+
"name": "name",
7470+
"schema": {
7471+
"type": "string"
7472+
},
7473+
"required": true
7474+
}
7475+
],
7476+
"summary": "Get images",
7477+
"x-sdk-interface": "runtimeEnvs.getBaseImages"
7478+
}
7479+
},
74397480
"/runtime/testit": {
74407481
"post": {
74417482
"responses": {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codefresh",
3-
"version": "0.84.3",
3+
"version": "0.84.5",
44
"description": "Codefresh command line utility",
55
"main": "index.js",
66
"preferGlobal": true,

0 commit comments

Comments
 (0)