Skip to content

Commit f6e5200

Browse files
CR-1973 - [vault] (#611)
* Added hashicorp-vault secret-store option Co-authored-by: roi.kramer <[email protected]>
1 parent 4806fb7 commit f6e5200

File tree

4 files changed

+109
-3
lines changed

4 files changed

+109
-3
lines changed

.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module.exports = {
1212
}],
1313
'no-console': 0,
1414
'object-curly-newline': 0,
15+
'no-return-await': 'off',
1516
},
1617
'env': {
1718
'jest': true,

docs/docs.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ const docs = require('../docs');
33
describe('docs generation', () => {
44
jest.setTimeout(20000);
55
it('should generate docs', async () => {
6-
await docs();
6+
return await docs();
77
});
88
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
const Command = require('../../../../../Command');
2+
const CFError = require('cf-errors');
3+
const cmd = require('../base.cmd');
4+
const { sdk } = require('../../../../../../../logic');
5+
6+
function buildAuthObject({ token, username, password, roleId, secretId, loginPath }) {
7+
const mountPoint = loginPath ? { mount_point: loginPath } : {};
8+
if (token) {
9+
return { type: 'token', token, ...mountPoint };
10+
}
11+
12+
if (username && password) {
13+
return { type: 'userpass', username, password, ...mountPoint };
14+
}
15+
16+
if (roleId && secretId) {
17+
return { type: 'approle', role_id: roleId, secret_id: secretId, ...mountPoint };
18+
}
19+
20+
throw new CFError('missing authentication info');
21+
}
22+
23+
const command = new Command({
24+
command: 'hashicorp-vault <name>',
25+
parent: cmd,
26+
description: 'Create a Hashicorp Vault secret-store context',
27+
usage: cmd.usage,
28+
webDocs: {
29+
category: 'Create Secret-Store Context',
30+
subCategory: 'vault',
31+
title: 'vault',
32+
weight: 10,
33+
},
34+
builder(yargs) {
35+
return yargs
36+
.option('api-url', {
37+
alias: 'a',
38+
describe: 'URL of the vault server',
39+
type: 'string',
40+
required: true,
41+
})
42+
.option('token', {
43+
alias: 't',
44+
describe: 'Token',
45+
type: 'string',
46+
conflicts: ['username', 'password', 'roleId', 'secretId'],
47+
})
48+
.option('username', {
49+
describe: 'Username',
50+
alias: 'u',
51+
type: 'string',
52+
conflicts: ['token', 'roleId', 'secretId'],
53+
})
54+
.option('password', {
55+
describe: 'Password',
56+
alias: 'p',
57+
type: 'string',
58+
conflicts: ['token', 'roleId', 'secretId'],
59+
})
60+
.option('role-id', {
61+
describe: 'Role Id',
62+
alias: 'r',
63+
type: 'string',
64+
conflicts: ['token', 'username', 'password'],
65+
})
66+
.option('secret-id', {
67+
describe: 'Secret Id',
68+
alias: 's',
69+
type: 'string',
70+
conflicts: ['token', 'username', 'password'],
71+
})
72+
.option('login-path', {
73+
describe: 'Path for given auth method. Leave out to use the default path for the type.',
74+
type: 'string',
75+
})
76+
.option('behind-firewall', {
77+
describe: 'Set to true to mark this context with behind firewall flag',
78+
type: 'boolean',
79+
default: false,
80+
})
81+
.check(buildAuthObject);
82+
},
83+
async handler(argv) {
84+
const data = {
85+
apiVersion: 'v1',
86+
kind: 'context',
87+
metadata: {
88+
name: argv.name,
89+
},
90+
spec: {
91+
type: 'secret-store.hashicorp-vault',
92+
data: {
93+
sharingPolicy: argv.sharingPolicy,
94+
behindFirewall: argv.behindFirewall,
95+
apiUrl: argv.apiUrl,
96+
auth: buildAuthObject(argv),
97+
},
98+
},
99+
};
100+
await sdk.contexts.create(data);
101+
console.log(`Context: ${data.metadata.name} created`);
102+
},
103+
});
104+
105+
module.exports = command;

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codefresh",
3-
"version": "0.74.0",
3+
"version": "0.74.1",
44
"description": "Codefresh command line utility",
55
"main": "index.js",
66
"preferGlobal": true,
@@ -17,7 +17,7 @@
1717
"postinstall": "node run-check-version.js"
1818
},
1919
"bin": {
20-
"codefresh": "./lib/interface/cli/codefresh"
20+
"codefresh": "lib/interface/cli/codefresh"
2121
},
2222
"repository": "git+https://github.com/codefresh-io/cli.git",
2323
"keywords": [

0 commit comments

Comments
 (0)