Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions lib/interface/cli/commands/root/diff.cmd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const CFError = require('cf-errors');
const Command = require('../../Command');
const { crudFilenameOption } = require('../../helpers/general');
const DEFAULTS = require('../../defaults');
const yargs = require('yargs');

const diff = new Command({
root: true,
command: 'diff',
description: 'Show diff between two resources',
usage: 'Supported resources: runtime-environments',
webDocs: {
description: 'Show diff between two resources',
category: 'Operate On Resources',
title: 'Diff',
weight: 100,
},
builder: (yargs) => {
crudFilenameOption(yargs);
return yargs;
},
handler: async (argv) => {
if (!argv.filename) {
yargs.showHelp();
}

const data = argv.filename;
const entity = data.kind;

switch (entity) {
default:
throw new CFError(`Entity: ${entity} not supported`);
}

},
});

module.exports = diff;
101 changes: 101 additions & 0 deletions lib/interface/cli/commands/runtimeEnvironments/apply.cmd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
const debug = require('debug')('codefresh:cli:create:context');
const Command = require('../../Command');
const CFError = require('cf-errors');
const _ = require('lodash');
const { runtimeEnvironments } = require('../../../../logic').api;
const applyRoot = require('../root/apply.cmd');


const command = new Command({
command: 'runtime-environments [name]',
aliases: ['re','runtime-environment'],
parent: applyRoot,
description: 'apply changes to runtime-environments resource',
usage: 'Use apply to patch an existing context',
webDocs: {
category: 'Runtime-Environments (On Prem)',
title: 'Apply Runtime-Environments',
weight: 90,
},
builder: (yargs) => {
return yargs
.positional('name', {
describe: 'Runtime environments name',
})
.option('default', {
describe: 'Set the chosen runtime environment as default',
})
.option('extends', {
describe: 'Set the runtime environments you want to extends from',
type: Array,
})
.option('namespace', {
alias: 'ns',
describe: 'Set the desire namespace',
})
.option('cluster', {
alias: 'c',
describe: 'Set the desire cluster',
})
.option('description', {
alias: 'd',
describe: 'Description of the new runtime environment',
})
.example('codefresh patch runtime-environments -f ./re.yml', 'Apply changes to a runtime-environment');
},
handler: async (argv) => {
const option = {};
option.body = argv.filename || {};
option.name = _.get(option.body, 'metadata.name') || argv.name;
option.extend = _.get(option.body, 'extends') || argv.extends;
option.description = _.get(option.body, 'description') || argv.description;
option.dockerDaemonCluster = _.get(option.body, 'dockerDaemonScheduler.cluster.clusterProvider.selector') || argv.cluster;
option.dockerDaemonNamespace = _.get(option.body, 'dockerDaemonScheduler.cluster.namespace') || argv.namespace;
option.runtimeSchedulerCluster = _.get(option.body, 'runtimeScheduler.cluster.clusterProvider.selector') || argv.cluster;
option.runtimeSchedulerNamespace = _.get(option.body, 'runtimeScheduler.cluster.namespace') || argv.namespace;
if (!option.name) {
throw new CFError('Must Provide a runtime environment name');
}
if (argv.default) {
try {
await runtimeEnvironments.setDefaultForAccount(option.name);
console.log(`Runtime-Environment: '${option.name}' set as a default.`);
} catch (err) {
throw new CFError(err);
}
}
if (!option.extend) {
throw new CFError('Must specify the runtime you want to extends from');
}
if (!option.dockerDaemonCluster || !option.runtimeSchedulerCluster || option.dockerDaemonNamespace || option.runtimeSchedulerNamespace) {
let extendsFromAccountRe = false;
_.forEach(argv.extends, (runtime) => {
if (!runtime.startsWith('system')) {
extendsFromAccountRe = true;
}
});
if (!extendsFromAccountRe) {
throw new CFError('Must Provide cluster name and namespace or extends from existing account runtime environment');
}
} if (!argv.filename) {
if (option.dockerDaemonCluster) {
_.set(option.body, 'dockerDaemonScheduler.cluster.clusterProvider.selector', option.dockerDaemonCluster);
}
if (option.runtimeSchedulerCluster) {
_.set(option.body, 'runtimeScheduler.cluster.clusterProvider.selector', option.runtimeSchedulerCluster);
}
if (option.dockerDaemonNamespace) {
_.set(option.body, 'dockerDaemonScheduler.cluster.namespace', option.dockerDaemonNamespace);
}
if (option.runtimeSchedulerNamespace) {
_.set(option.body, 'runtimeScheduler.cluster.namespace', option.runtimeSchedulerNamespace);
}
}
await runtimeEnvironments.applyByNameForAccount(option);
console.log(`Runtime-Environment: '${option.name}' patched.`);
},
});


module.exports = command;

38 changes: 38 additions & 0 deletions lib/interface/cli/commands/runtimeEnvironments/delete.cmd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const debug = require('debug')('codefresh:cli:create:pipelines2');
const Command = require('../../Command');
const CFError = require('cf-errors');
const _ = require('lodash');
const { runtimeEnvironments } = require('../../../../logic/index').api;
const deleteRoot = require('../root/delete.cmd');


const command = new Command({
command: 'runtime-environments name',
aliases: ['re', 'runtime-environment'],
parent: deleteRoot,
description: 'Delete a runtime-environment',
webDocs: {
category: 'Runtime-Environments',
title: 'Delete Runtime-Environments',
},
builder: (yargs) => {
return yargs
.positional('name', {
describe: 'Runtime environment name',
})
.option('force', {
describe: 'Delete runtime environment in force mode',
type: 'boolean',
});
},
handler: async (argv) => {
const { name, force } = argv;

await runtimeEnvironments.deleteRuntimeEnvironmentByNameForAccount(name, force);
console.log(`Runtime-Environment '${name}' deleted.`);
},
});


module.exports = command;

67 changes: 67 additions & 0 deletions lib/interface/cli/commands/runtimeEnvironments/diff.cmd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const debug = require('debug')('codefresh:cli:create:pipelines2');
const Command = require('../../Command');
const { runtimeEnvironments } = require('../../../../logic/index').api;
const jsdiff = require('diff');
require('colors');

const diffRoot = require('../root/diff.cmd');


const command = new Command({
command: 'runtime-environments [first-re-name] [first-re-version] [second-re-name] [second-re-version]',
aliases: ['re', 'runtime-environment'],
parent: diffRoot,
description: 'Show diff between two runtime environments configuration',
webDocs: {
category: 'Runtime-Environments (On Prem)',
title: 'Diff Runtime-Environments',
},
builder: (yargs) => {
return yargs
.option('first-name', {
describe: 'First runtime environment name',
})
.option('first-version', {
describe: 'First runtime environment version',
})
.option('second-name', {
describe: 'Second runtime environment name',
})
.option('second-version', {
describe: 'Second runtime environment version',
});
},
handler: async (argv) => {
const firstEnvName = argv['first-name'];
const firstEnvVersion = argv['first-version'];
const secondEnvName = argv['second-name'];
const secondEnvVersion = argv['second-version'];

const firstEnv = await runtimeEnvironments.getRuntimeEvironmentsByNameForAccount({
diff: true,
name: firstEnvName,
version: firstEnvVersion,
});

const secondtEnv = await runtimeEnvironments.getRuntimeEvironmentsByNameForAccount({
diff: true,
name: secondEnvName,
version: secondEnvVersion,
});

const firstEnvJson = JSON.stringify(firstEnv, null, '\t');
const secondEnvJson = JSON.stringify(secondtEnv, null, '\t');

const diff = jsdiff.diffJson(firstEnvJson, secondEnvJson);

diff.forEach((part) => {
const color = part.added ? 'green' : part.removed ? 'red' : 'white';
process.stderr.write(part.value[color]);
});

console.log();
},
});

module.exports = command;

49 changes: 33 additions & 16 deletions lib/interface/cli/commands/runtimeEnvironments/get.cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,74 @@ const debug = require('debug')('codefresh:cli:create:pipelines2');
const Command = require('../../Command');
const _ = require('lodash');
const { runtimeEnvironments } = require('../../../../logic/index').api;
const { specifyOutputForSingle } = require('../../helpers/get');
const { specifyOutputForSingle, specifyOutputForArray } = require('../../helpers/get');
const DEFAULTS = require('../../defaults');



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


const command = new Command({
command: 'runtime-environments [name] [version]',
command: 'runtime-environments [name]',
aliases: ['re', 'runtime-environment'],
parent: getRoot,
description: 'Get a runtime environments configuration',
onPremCommand: true,
webDocs: {
category: 'Runtime-Environments (On Prem)',
category: 'Runtime-Environments',
title: 'Get Runtime-Environments',
},
builder: (yargs) => {
return yargs
.positional('name', {
describe: 'Runtime environments name',
default: 'default',
})
.positional('version', {
.option('version', {
describe: 'Runtime environments version',
})
/*
.option('account', {
describe: 'Return a specific account configuration by the given name from the current runtime environments',
})
*/
.option('history', {
describe: 'Return all the history of the specific runtime environments',
type: 'boolean',
})
.option('limit', {
describe: 'Limit amount of returned results',
default: DEFAULTS.GET_LIMIT_RESULTS,
})
.option('page', {
describe: 'Paginated page',
default: DEFAULTS.GET_PAGINATED_PAGE,
})
.option('extend', {
describe: 'Return an extend runtime environment ',
type: 'boolean',
default: false,
});
},
handler: async (argv) => {
const { name, version, history, account } = argv;
if (history){
const allHistory = await runtimeEnvironments.getRuntimeEvironmentsHistory({
const { name, version, history, extend, limit, page, output } = argv;
const offset = (page - 1) * limit;
if (history) {
const allHistory = await runtimeEnvironments.getRuntimeEvironmentsByNameForAccount({
name,
history,
});
console.log(JSON.stringify(allHistory, null, '\t'));

}
else {
const currruntimeEnvironments = await runtimeEnvironments.getRuntimeEvironmentsByName({
else if (name) {
const currruntimeEnvironments = await runtimeEnvironments.getRuntimeEvironmentsByNameForAccount({
name,
version,
extend,
});
specifyOutputForSingle(argv.output, currruntimeEnvironments);
}
else {
specifyOutputForArray(output, await runtimeEnvironments.getAllRuntimeEnvironmentsForAccount({
limit,
offset,
}));
}
},
});

Expand Down
38 changes: 0 additions & 38 deletions lib/interface/cli/commands/runtimeEnvironments/replace.cmd.js

This file was deleted.

Loading