Skip to content

Commit 0ea6dff

Browse files
committed
removed apiKey and secret flags from deploy commands
1 parent abc9818 commit 0ea6dff

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

node/src/config/arguments.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const argumentsMap = {
2626
description: 'env0 API Key',
2727
prompt: 'env0 API Key',
2828
secret: true,
29-
group: ['deploy', 'destroy', 'approve', 'cancel', 'configure', 'agents-settings-list-agents']
29+
group: ['configure']
3030
},
3131
[API_SECRET]: {
3232
name: API_SECRET,
@@ -35,7 +35,7 @@ const argumentsMap = {
3535
description: 'env0 API Secret',
3636
prompt: 'env0 API Secret',
3737
secret: true,
38-
group: ['deploy', 'destroy', 'approve', 'cancel', 'configure', 'agents-settings-list-agents']
38+
group: ['configure']
3939
},
4040
[ORGANIZATION_ID]: {
4141
name: ORGANIZATION_ID,
@@ -154,5 +154,10 @@ module.exports = {
154154
argumentsMap[ORGANIZATION_ID],
155155
argumentsMap[PROJECT_ID],
156156
argumentsMap[ENVIRONMENT_NAME]
157+
],
158+
nonCredentialBaseArguments: [
159+
argumentsMap[ORGANIZATION_ID],
160+
argumentsMap[PROJECT_ID],
161+
argumentsMap[ENVIRONMENT_NAME]
157162
]
158163
};

node/src/config/commands.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { argumentsMap, allArguments, baseArguments } = require('./arguments');
1+
const { argumentsMap, allArguments, baseArguments, nonCredentialBaseArguments } = require('./arguments');
22
const { options } = require('./constants');
33
const deploy = require('../commands/deploy');
44
const destroy = require('../commands/destroy');
@@ -16,7 +16,7 @@ const commands = {
1616
handler: deploy,
1717
requiredOptions: BASE_REQUIRED_OPTIONS,
1818
useDeployUtils: true,
19-
options: allArguments,
19+
options: allArguments.filter(option => ![API_KEY, API_SECRET].includes(option.name)),
2020
help: [
2121
{
2222
desc: 'Deploys an environment',
@@ -28,7 +28,7 @@ const commands = {
2828
handler: destroy,
2929
requiredOptions: BASE_REQUIRED_OPTIONS,
3030
useDeployUtils: true,
31-
options: [...baseArguments, argumentsMap[REQUIRES_APPROVAL], argumentsMap[SKIP_STATE_REFRESH]],
31+
options: [...nonCredentialBaseArguments, argumentsMap[REQUIRES_APPROVAL], argumentsMap[SKIP_STATE_REFRESH]],
3232
help: [
3333
{
3434
desc: 'Destroys an environment',
@@ -40,7 +40,7 @@ const commands = {
4040
handler: approve,
4141
requiredOptions: BASE_REQUIRED_OPTIONS,
4242
useDeployUtils: true,
43-
options: baseArguments,
43+
options: nonCredentialBaseArguments,
4444
help: [
4545
{
4646
desc: 'Accepts a deployment that is pending approval',
@@ -64,7 +64,7 @@ const commands = {
6464
handler: agentsSettingsListAgents,
6565
requiredOptions: ORG_REQUIRED_OPTIONS,
6666
useDeployUtils: false,
67-
options: baseArguments,
67+
options: nonCredentialBaseArguments,
6868
help: [
6969
{
7070
desc: 'Lists organization agents',

node/tests/main.spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const runCommand = require('../src/commands/run-command');
22
const run = require('../src/main');
33
const commandLineArgs = require('command-line-args');
44
const { commands } = require('../src/config/commands');
5+
const { options } = require('../src/config/constants');
56
const { version } = require('../package.json');
67
const help = require('../src/commands/help');
78
const configure = require('../src/commands/configure');
@@ -159,6 +160,26 @@ describe('main', () => {
159160
});
160161
});
161162

163+
describe('auth flags exposure', () => {
164+
const { API_KEY, API_SECRET } = options;
165+
166+
const getOptionNames = command => (commands[command].options || []).map(opt => opt.name);
167+
168+
it('should not expose apiKey/apiSecret flags for runtime commands', () => {
169+
['deploy', 'destroy', 'cancel', 'approve', 'agents-settings-list-agents'].forEach(command => {
170+
const names = getOptionNames(command);
171+
expect(names).not.toContain(API_KEY);
172+
expect(names).not.toContain(API_SECRET);
173+
});
174+
});
175+
176+
it('should still expose apiKey/apiSecret flags for configure', () => {
177+
const names = getOptionNames('configure');
178+
expect(names).toContain(API_KEY);
179+
expect(names).toContain(API_SECRET);
180+
});
181+
});
182+
162183
describe('variables parsing', () => {
163184
describe.each`
164185
command

0 commit comments

Comments
 (0)