Skip to content

Commit 8a21408

Browse files
fix runtime environment modle (#201)
1 parent c213720 commit 8a21408

File tree

4 files changed

+42
-21
lines changed

4 files changed

+42
-21
lines changed

lib/interface/cli/commands/runtimeEnvironments/get.cmd.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ const debug = require('debug')('codefresh:cli:create:pipelines2');
22
const Command = require('../../Command');
33
const _ = require('lodash');
44
const { runtimeEnvironments } = require('../../../../logic/index').api;
5+
const { specifyOutputForSingle } = require('../../helpers/get');
6+
57

68
const getRoot = require('../root/get.cmd');
79

@@ -25,27 +27,32 @@ const command = new Command({
2527
.positional('version', {
2628
describe: 'Runtime environments version',
2729
})
30+
/*
2831
.option('account', {
29-
describe: 'Return a specific account configuration from the current runtime environments by his name',
32+
describe: 'Return a specific account configuration by the given name from the current runtime environments',
3033
})
34+
*/
3135
.option('history', {
3236
describe: 'Return all the history of the specific runtime environments',
3337
type: 'boolean',
3438
});
3539
},
3640
handler: async (argv) => {
3741
const { name, version, history, account } = argv;
38-
let currruntimeEnvironments;
39-
if (account) {
40-
currruntimeEnvironments = await runtimeEnvironments.getRuntimeEvironment(account);
41-
} else {
42-
currruntimeEnvironments = await runtimeEnvironments.getRuntimeEvironmentsByName({
42+
if (history){
43+
const allHistory = await runtimeEnvironments.getRuntimeEvironmentsHistory({
44+
name,
45+
});
46+
console.log(JSON.stringify(allHistory, null, '\t'));
47+
48+
}
49+
else {
50+
const currruntimeEnvironments = await runtimeEnvironments.getRuntimeEvironmentsByName({
4351
name,
4452
version,
45-
history,
4653
});
54+
specifyOutputForSingle(argv.output, currruntimeEnvironments);
4755
}
48-
console.log(JSON.stringify(currruntimeEnvironments, null, '\t'));
4956
},
5057
});
5158

lib/logic/api/runtimeEnvironments.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,27 @@ const { sendHttpRequest } = require('./helper');
33
const RuntimeEnvironments = require('../entities/RuntimeEnvironments');
44

55

6-
const _extractFieldsForRuntimeEnvironmentsEntity = (runtimeEnvironments) => {
7-
return {
8-
id: runtimeEnvironments.id,
9-
name: runtimeEnvironments.name,
10-
version: runtimeEnvironments.version,
11-
userName : runtimeEnvironments.userName,
12-
runtimeEnvironments: runtimeEnvironments.runtimeEnvironments,
13-
history : runtimeEnvironments.history,
14-
};
15-
};
16-
6+
const _extractFieldsForRuntimeEnvironmentEntity = runtimeEnv => _.pick(runtimeEnv, '_id', 'version', 'metadata', 'runtimeEnvironments', 'history');
177

188
const getRuntimeEvironmentsByName = async (option) => {
199
const qs = {
2010
name: option.name,
2111
version: option.version,
22-
history: option.history,
12+
};
13+
const options = {
14+
url: '/api/admin/runtime-environment-manager/runtimeEnvironmentsName',
15+
method: 'GET',
16+
qs,
17+
};
18+
const runtimeEnvironments = await sendHttpRequest(options);
19+
const runtimeObj = new RuntimeEnvironments(_extractFieldsForRuntimeEnvironmentEntity(runtimeEnvironments));
20+
return runtimeObj;
21+
};
22+
23+
const getRuntimeEvironmentsHistory = async (option) => {
24+
const qs = {
25+
name: option.name,
26+
history: true,
2327
};
2428
const options = {
2529
url: '/api/admin/runtime-environment-manager/runtimeEnvironmentsName',
@@ -54,6 +58,7 @@ const replaceByName = async (runtimeEnvironmentName, data) => {
5458

5559
module.exports = {
5660
getRuntimeEvironmentsByName,
61+
getRuntimeEvironmentsHistory,
5762
replaceByName,
5863
getRuntimeEvironment,
5964
};

lib/logic/entities/RuntimeEnvironments.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
const Entity = require('./Entity');
2+
const _ = require('lodash');
23

34
class RuntimeEnvironments extends Entity {
45
constructor(data) {
56
super();
67
this.entityType = 'RuntimeEnvironments';
78
this.info = data;
9+
this.id = _.get(data, '_id');
10+
this.name = _.get(data, 'metadata.name');
11+
this.last_updated_by = _.get(data, 'metadata.userName');
12+
this.defaultColumns = ['id', 'version', 'name', 'last_updated_by'];
13+
this.wideColumns = this.defaultColumns.concat([]);
814
}
915
}
1016

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codefresh",
3-
"version": "0.8.57",
3+
"version": "0.8.58",
44
"description": "Codefresh command line utility",
55
"main": "index.js",
66
"preferGlobal": true,
@@ -71,5 +71,8 @@
7171
"license": "ISC",
7272
"engines": {
7373
"node": ">8.0.0"
74+
},
75+
"yargs": {
76+
"boolean-negation": false
7477
}
7578
}

0 commit comments

Comments
 (0)