Skip to content

Commit 14ab467

Browse files
CR-17813-revert 2 (#811)
1 parent db5f6c8 commit 14ab467

File tree

14 files changed

+59
-262
lines changed

14 files changed

+59
-262
lines changed

codefresh-release.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,13 +445,14 @@ steps:
445445
update_documentation:
446446
stage: documentation
447447
title: "Update documentation http://cli.codefresh.io"
448-
image: codefresh/build-cli
448+
image: docker:18.01
449449
commands:
450-
- "yarn"
450+
- "apk update && apk add git nodejs"
451+
- "npm install"
451452
- "echo cleaning previous public dir and recreating worktree"
452-
- "rm -rf public && git worktree prune && git worktree add -B gh-pages public origin/gh-pages"
453+
- "rm -rf public && git worktree prune && git worktree add -B gh-pages public origin/gh-pages"
453454
- "echo Building public docs"
454-
- "yarn run build-public-docs"
455+
- "npm run build-public-docs"
455456
- "echo Push new docs to gh-pages detached branch"
456457
- 'git config --global user.email "[email protected]" && git config --global user.name "Automated CI"'
457458
- 'cd public && git add --all && git commit -m "Publish new documentation for version ${{PACKAGE_VERSION}}" && git push https://${{GITHUB_TOKEN}}@github.com/codefresh-io/cli.git'

codefresh.yml

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ steps:
328328
type: codefresh-run
329329
arguments:
330330
PIPELINE_ID: 'codefresh-io/cli/release'
331-
TRIGGER_ID: codefresh-io/cli_1
331+
DETACH: true
332332
BRANCH: master
333333
VARIABLE:
334334
- PACKAGE_VERSION=${{PACKAGE_VERSION}}
@@ -342,18 +342,3 @@ steps:
342342
- name: create_manifest_list
343343
on:
344344
- success
345-
346-
build_documentation:
347-
stage: test
348-
title: "build documentation http://cli.codefresh.io"
349-
image: codefresh/build-cli
350-
commands:
351-
- "echo Building public docs"
352-
- "npm run build-public-docs"
353-
environment:
354-
- HUGO_VERSION=0.32.0
355-
when:
356-
steps:
357-
- name: install_dependencies
358-
on:
359-
- success

docs/content/pipelines/Run Pipeline.md

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,44 +15,22 @@ The pipeline will be triggered multiple times according to the array length.
1515

1616
#### Variable yaml file with 2 sets of variables
1717
```yaml
18-
- VARIABLE_A: value_a_for_the_first_build
19-
VARIABLE_B: value_b_for_the_first_build
20-
- VARIABLE_A: value_a_for_the_first_build
21-
VARIABLE_B: value_b_for_the_first_build
18+
- key: value
19+
key2: key1
20+
- key: value
21+
key2: key2
2222
```
2323
2424
#### Variable json file with 2 sets of variables
2525
```json
2626
[
2727
{
28-
"VARIABLE_A": "value_a_for_the_first_build",
29-
"VARIABLE_B": "value_b_for_the_first_build"
28+
"key": "value",
29+
"key2": "key1"
3030
},
3131
{
32-
"VARIABLE_A": "value_a_for_the_first_build",
33-
"VARIABLE_B": "value_b_for_the_first_build"
34-
}
35-
]
36-
```
37-
### Use encrypted variables in Codefresh build runs; supported from CLI version: 0.83.1
38-
#### Variable yaml file with single variable set with encrypted variables
39-
```yaml
40-
- key:
41-
val: value
42-
encrypted: true
43-
key2: val2
44-
45-
```
46-
47-
#### Variable json file single variable set with encrypted variables
48-
```json
49-
[
50-
{
51-
"key": {
52-
"val": "value",
53-
"encrypted": true
54-
},
55-
"key2": "key1"
32+
"key": "value",
33+
"key2": "key2"
5634
}
5735
]
5836
```

lib/interface/cli/commands/annotation/create.cmd.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const command = new Command({
3131
.example('codefresh create annotation image 2dfacdaad466 coverage=75%', 'Annotate entity with a single label')
3232
.example('codefresh create annotation image 2dfacdaad466 coverage=75% tests_passed=true', 'Annotate entity with multiple labels')
3333
// eslint-disable-next-line max-len
34-
.example('codefresh create annotation workflow 643d807b85bbe35931ae2282 ENV=prod tests_passed=true --display ENV', 'Annotate entity with multiple labels and display selection'),
34+
.example('codefresh create annotation image 2dfacdaad466 coverage=75% tests_passed=true --display coverage', 'Annotate entity with multiple labels and display selection'),
3535
handler: async (argv) => {
3636
const { entityType, entityId, labels, display } = argv;
3737

lib/interface/cli/commands/pipeline/pipeline.sdk.spec.js

Lines changed: 6 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
const yaml = require('js-yaml');
2-
const request = require('requestretry');
3-
const fs = require('fs');
4-
const _ = require('lodash');
51
const DEFAULTS = require('../../defaults');
62
const getCmd = require('./get.cmd').toCommand();
73
const deleteCmd = require('./delete.cmd').toCommand();
@@ -14,21 +10,18 @@ jest.mock('../../helpers/validation'); // eslint-disable-line
1410
jest.mock('../../../../../check-version');
1511
jest.mock('../../completion/helpers', () => { // eslint-disable-line
1612
return {
17-
authContextWrapper: (func) => func,
13+
authContextWrapper: func => func,
1814
};
1915
});
2016

21-
jest.mock('../../helpers/general', () => ({
22-
...jest.requireActual('../../helpers/general'),
23-
isCompatibleApiVersion: () => true,
24-
}));
25-
2617
jest.mock('../../../../logic/entities/Pipeline', () => { // eslint-disable-line
2718
return {
28-
fromResponse: (res) => res,
19+
fromResponse: res => res,
2920
};
3021
});
3122

23+
const request = require('requestretry');
24+
3225
const DEFAULT_RESPONSE = request.__defaultResponse();
3326

3427
describe('pipeline', () => {
@@ -64,11 +57,11 @@ describe('pipeline', () => {
6457
});
6558

6659
it('should return default limit', async () => {
67-
expect(_getLimit(undefined, false)).toEqual(DEFAULTS.GET_LIMIT_RESULTS);
60+
expect(_getLimit(undefined,false)).toEqual(DEFAULTS.GET_LIMIT_RESULTS);
6861
});
6962

7063
it('should return `unlimited` value', async () => {
71-
expect(_getLimit(undefined, true)).toEqual(DEFAULTS.GET_ALL_PIPELINES_LIMIT);
64+
expect(_getLimit(undefined,true)).toEqual(DEFAULTS.GET_ALL_PIPELINES_LIMIT);
7265
});
7366
});
7467

@@ -91,69 +84,6 @@ describe('pipeline', () => {
9184
});
9285
});
9386

94-
describe('run', () => {
95-
it('should handle running pipeline with encrypted variables', async () => {
96-
const argv = { name: 'some name',
97-
detach: true,
98-
annotation: [],
99-
variable: [
100-
'secret=secret',
101-
'VAR1=VAL1',
102-
],
103-
encrypted: ['secret'],
104-
};
105-
const pip = new CfPipeline(argv);
106-
await pip.run();
107-
expect(pip.executionRequests[0].options.variables).toEqual([
108-
{
109-
key: 'secret',
110-
value: 'secret',
111-
encrypted: true,
112-
},
113-
{
114-
key: 'VAR1',
115-
value: 'VAL1',
116-
},
117-
]);
118-
await verifyResponsesReturned([DEFAULT_RESPONSE]); // eslint-disable-line
119-
});
120-
121-
it('should handle running pipeline with encrypted variables passing inside json file', async () => {
122-
const rawFile = fs.readFileSync('lib/interface/cli/commands/pipeline/var.json', 'utf8');
123-
124-
const argv = { name: 'some name',
125-
detach: true,
126-
annotation: [],
127-
'var-file': JSON.parse(rawFile),
128-
};
129-
const pip = new CfPipeline(argv);
130-
await pip.run();
131-
expect(pip.executionRequests[0].options.variables).toEqual(
132-
[{ key: 'help6', value: '85858' },
133-
{ key: 'should_be_encrepted', value: '0000' },
134-
{ encrypted: true, key: 'help7', value: 'test' }],
135-
);
136-
await verifyResponsesReturned([DEFAULT_RESPONSE]); // eslint-disable-line
137-
});
138-
139-
it('should handle running pipeline with encrypted variables passing inside yaml file', async () => {
140-
const rawFile = fs.readFileSync('lib/interface/cli/commands/pipeline/var.yml', 'utf8');
141-
142-
const argv = { name: 'some name',
143-
detach: true,
144-
annotation: [],
145-
'var-file': yaml.safeLoad(rawFile),
146-
};
147-
const pip = new CfPipeline(argv);
148-
await pip.run();
149-
expect(pip.executionRequests[0].options.variables).toEqual(
150-
[{ key: 'VAR1', value: 'VAL1' },
151-
{ encrypted: true, key: 'VAR2', value: 'VAL2' }],
152-
);
153-
await verifyResponsesReturned([DEFAULT_RESPONSE]); // eslint-disable-line
154-
});
155-
});
156-
15787
describe('runImpl', () => {
15888
it('should handle running pipeline', async () => {
15989
const argv = { name: 'some name', detach: true };

lib/interface/cli/commands/pipeline/run.base.js

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
const _ = require('lodash');
22
const Promise = require('bluebird');
3-
const CFError = require('cf-errors');
4-
const { prepareKeyValueFromCLIEnvOption,
5-
markEncryptedFlagOnRequestedVariables,
6-
prepareKeyValueObjectsFromEnvFileOption,
7-
prepareKeyValueObjectsFromCLIEnvOption,
8-
isCompatibleApiVersion,
9-
} = require('../../helpers/general');
3+
const { prepareKeyValueFromCLIEnvOption } = require('../../helpers/general');
104
const { validatePipelineYaml } = require('../../helpers/validation');
115
const { printResult } = require('../root/validate.cmd');
6+
const CFError = require('cf-errors');
127
const { sdk } = require('../../../../logic');
13-
const defaults = require('../../defaults');
148

159
class RunBaseCommand {
1610
constructor(argv) {
@@ -61,34 +55,22 @@ class RunBaseCommand {
6155
packName,
6256
},
6357
};
64-
const encryptedVarsSupported = await isCompatibleApiVersion({
65-
supportedVersion: defaults.MIN_API_VERSION_FOR_ENCRYPTED_VARS_SUPPORT_IN_RUN_CMD,
66-
});
58+
6759
if (variablesFromFile) {
6860
_.forEach(variablesFromFile, (variables) => {
6961
const request = _.cloneDeep(executionRequestTemplate);
70-
if (encryptedVarsSupported) {
71-
request.options.variables = prepareKeyValueObjectsFromEnvFileOption(variables);
72-
} else {
73-
request.options.variables = variables;
74-
}
62+
request.options.variables = variables;
7563
this.executionRequests.push(request);
7664
});
7765
} else {
78-
let variables;
79-
if (encryptedVarsSupported) {
80-
const varsArr = prepareKeyValueObjectsFromCLIEnvOption(this.argv.variable);
81-
variables = markEncryptedFlagOnRequestedVariables(varsArr, this.argv.encrypted);
82-
} else {
83-
variables = prepareKeyValueFromCLIEnvOption(this.argv.variable);
84-
}
66+
const variables = prepareKeyValueFromCLIEnvOption(this.argv.variable);
8567
const request = _.cloneDeep(executionRequestTemplate);
8668
request.options.variables = variables;
8769
request.options.contexts = contexts;
8870
this.executionRequests.push(request);
8971
}
9072

91-
const results = await Promise.all(this.executionRequests.map((request) => this.runImpl(request)));
73+
const results = await Promise.all(this.executionRequests.map(request => this.runImpl(request)));
9274
const findMaxReducer = (accumulator, currentValue) => (currentValue > accumulator ? currentValue : accumulator);
9375
const exitCode = results.reduce(findMaxReducer);
9476
await this.postRunRequest();

lib/interface/cli/commands/pipeline/run.cmd.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,6 @@ const run = new Command({
8686
default: [],
8787
alias: 'v',
8888
})
89-
.option('encrypted', {
90-
array: true,
91-
alias: 'e',
92-
describe: 'Variable names to encrypt',
93-
default: [],
94-
})
9589
.option('detach', {
9690
alias: 'd',
9791
describe: 'Run pipeline and print build ID',
@@ -132,7 +126,6 @@ const run = new Command({
132126
.example('codefresh run PIPELINE_ID | PIPELINE_NAME -b=master', 'Defining the source control context using a branch')
133127
.example('codefresh run PIPELINE_ID | PIPELINE_NAME -s=52b992e783d2f84dd0123c70ac8623b4f0f938d1', 'Defining the source control context using a commit')
134128
.example('codefresh run PIPELINE_ID | PIPELINE_NAME -b=master -v key1=value1 -v key2=value2', 'Setting variables through the command')
135-
.example('codefresh run PIPELINE_ID | PIPELINE_NAME -b=master -v key1=value1 -v key2=value2 -e key1', 'Setting variables through the command with encrypted option')
136129
.example('codefresh run PIPELINE_ID | PIPELINE_NAME -b=master --var-file ./var_file.yml', 'Settings variables through a yml file')
137130
.example('codefresh run PIPELINE_ID | PIPELINE_NAME -b=master --context context', 'Inject contexts to the pipeline execution')
138131
.example('codefresh run PIPELINE_ID | PIPELINE_NAME --skip step1 step2 step3', 'Skip specific steps');

lib/interface/cli/commands/pipeline/var.json

Lines changed: 0 additions & 12 deletions
This file was deleted.

lib/interface/cli/commands/pipeline/var.yml

Lines changed: 0 additions & 5 deletions
This file was deleted.

lib/interface/cli/commands/project/apply.cmd.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const _ = require('lodash');
44
const { sdk } = require('../../../../logic');
55

66
const applyRoot = require('../root/apply.cmd');
7-
const { prepareKeyValueObjectsFromCLIEnvOption, ignoreHttpError, markEncryptedFlagOnRequestedVariables } = require('../../helpers/general');
7+
const { prepareKeyValueObjectsFromCLIEnvOption, ignoreHttpError } = require('../../helpers/general');
88

99
const command = new Command({
1010
command: 'project [id|name]',
@@ -61,7 +61,14 @@ const command = new Command({
6161
encrypted,
6262
} = argv;
6363

64-
const requestedProjectVariables = markEncryptedFlagOnRequestedVariables(variables, encrypted);
64+
const variableMap = _.reduce(variables, (acc, v) => _.assign(acc, { [v.key]: v }), {});
65+
_.forEach(encrypted, (varName) => {
66+
const variable = variableMap[varName];
67+
if (!variable) {
68+
throw new CFError(`Variable is not provided: "${varName}"`);
69+
}
70+
variable.encrypted = true;
71+
});
6572

6673
let project = await sdk.projects.get({ id }).catch(ignoreHttpError);
6774
project = project || await sdk.projects.getByName({ name }).catch(ignoreHttpError);
@@ -74,7 +81,7 @@ const command = new Command({
7481
const updatePayload = _.pickBy({
7582
projectName,
7683
tags: tags || existingTags,
77-
variables: requestedProjectVariables || existingVariables,
84+
variables: variables || existingVariables,
7885
}, _.identity);
7986

8087
await sdk.projects.patch({ id: project.id }, updatePayload);

lib/interface/cli/commands/project/create.cmd.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
const Command = require('../../Command');
2+
const CFError = require('cf-errors');
3+
const _ = require('lodash');
24
const { sdk } = require('../../../../logic');
35
const createRoot = require('../root/create.cmd');
46
const { checkOrProjectExists } = require('../../helpers/validation');
5-
const { prepareKeyValueObjectsFromCLIEnvOption, markEncryptedFlagOnRequestedVariables } = require('../../helpers/general');
7+
const { prepareKeyValueObjectsFromCLIEnvOption } = require('../../helpers/general');
68

79
const command = new Command({
810
command: 'project <name>',
@@ -50,10 +52,17 @@ const command = new Command({
5052
encrypted,
5153
} = argv;
5254

53-
const requestedProjectVariables = markEncryptedFlagOnRequestedVariables(variables, encrypted);
55+
const variableMap = _.reduce(variables, (acc, v) => _.assign(acc, { [v.key]: v }), {});
56+
_.forEach(encrypted, (varName) => {
57+
const variable = variableMap[varName];
58+
if (!variable) {
59+
throw new CFError(`Variable is not provided: "${varName}"`);
60+
}
61+
variable.encrypted = true;
62+
});
5463

5564
await checkOrProjectExists(projectName);
56-
await sdk.projects.create({ projectName, tags, variables: requestedProjectVariables });
65+
await sdk.projects.create({ projectName, tags, variables });
5766
console.log(`Project: "${projectName}" created`);
5867
},
5968
});

lib/interface/cli/defaults.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const DEFAULTS = {
1313
MAX_CONSECUTIVE_ERRORS_LIMIT: 10,
1414
CODEFRESH_PATH: path.resolve(homedir(), '.Codefresh'),
1515
ENGINE_IMAGE: process.env.ENGINE_IMAGE || 'codefresh/engine:master',
16-
MIN_API_VERSION_FOR_ENCRYPTED_VARS_SUPPORT_IN_RUN_CMD: '21.221.14',
1716
};
1817

1918
module.exports = DEFAULTS;

0 commit comments

Comments
 (0)