Skip to content

Commit e506fcd

Browse files
Merge pull request #824 from JupiterOne/823-cli-api-key
Fix #823 - Do not modify `JUPITERONE_API_KEY` env var in CLI defaults
2 parents 744210a + 3f46d2b commit e506fcd

4 files changed

Lines changed: 61 additions & 19 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ and this project adheres to
99

1010
## Unreleased
1111

12+
### Fixed
13+
14+
- Do not modify the value supplied to `JUPITERONE_API_KEY` when using the
15+
integration CLI
16+
1217
## 8.29.2 - 2022-11-15
1318

1419
### Fixed

packages/integration-sdk-cli/src/__tests__/cli-run.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,3 +275,25 @@ test('does not publish events for source "api" since there is no integrationJobI
275275
expect(log.displayExecutionResults).toHaveBeenCalledTimes(1);
276276
expect(log.displaySynchronizationResults).toHaveBeenCalledTimes(1);
277277
});
278+
279+
test('should use JUPITERONE_API_KEY value in Authorization request header', async () => {
280+
expect.assertions(1);
281+
const job = generateSynchronizationJob();
282+
283+
setupSynchronizerApi({
284+
polly,
285+
job,
286+
baseUrl: 'https://api.us.jupiterone.io',
287+
onSyncJobCreateResponse(req, res) {
288+
expect(req.headers['Authorization']).toEqual('Bearer testing-key');
289+
},
290+
});
291+
292+
await createCli().parseAsync([
293+
'node',
294+
'j1-integration',
295+
'run',
296+
'--integrationInstanceId',
297+
'test',
298+
]);
299+
});

packages/integration-sdk-cli/src/__tests__/util/synchronization.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Polly } from '@pollyjs/core';
1+
import { Polly, Request, Response } from '@pollyjs/core';
22
import {
33
SynchronizationJob,
44
SynchronizationJobStatus,
@@ -8,14 +8,22 @@ interface SetupOptions {
88
baseUrl: string;
99
polly: Polly;
1010
job: SynchronizationJob;
11+
onSyncJobCreateResponse?: (req: Request<{}>, res: Response) => void;
1112
}
1213

13-
export function setupSynchronizerApi({ polly, job, baseUrl }: SetupOptions) {
14+
export function setupSynchronizerApi({
15+
polly,
16+
job,
17+
baseUrl,
18+
onSyncJobCreateResponse,
19+
}: SetupOptions) {
1420
polly.server
1521
.post(`${baseUrl}/persister/synchronization/jobs`)
1622
.intercept((req, res) => {
1723
allowCrossOrigin(req, res);
1824
res.status(200).json({ job });
25+
26+
if (onSyncJobCreateResponse) onSyncJobCreateResponse(req, res);
1927
});
2028

2129
polly.server

packages/integration-sdk-cli/src/commands/options.ts

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
JUPITERONE_DEV_API_BASE_URL,
66
JUPITERONE_PROD_API_BASE_URL,
77
} from '@jupiterone/integration-sdk-runtime';
8-
import { Command, OptionValues } from 'commander';
8+
import { Command, Option, OptionValues } from 'commander';
99
import path from 'path';
1010

1111
export interface PathOptions {
@@ -138,25 +138,32 @@ export interface ApiClientOptions {
138138

139139
export function addApiClientOptionsToCommand(command: Command): Command {
140140
return command
141-
.option(
142-
'--api-base-url <url>',
143-
'specify synchronization API base URL',
144-
JUPITERONE_PROD_API_BASE_URL,
141+
.addOption(
142+
new Option(
143+
'--api-base-url <url>',
144+
'specify synchronization API base URL',
145+
).default(JUPITERONE_PROD_API_BASE_URL),
145146
)
146-
.option(
147-
'-d, --development',
148-
'"true" to target apps.dev.jupiterone.io (JUPITERONE_DEV environment variable)',
149-
!!process.env.JUPITERONE_DEV,
147+
.addOption(
148+
new Option(
149+
'-d, --development',
150+
'"true" to target apps.dev.jupiterone.io',
151+
).default(
152+
!!process.env.JUPITERONE_DEV,
153+
'JUPITERONE_DEV environment variable value',
154+
),
150155
)
151-
.option(
152-
'--account <account>',
153-
'JupiterOne account ID (JUPITERONE_ACCOUNT environment variable)',
154-
process.env.JUPITERONE_ACCOUNT,
156+
.addOption(
157+
new Option('--account <account>', 'JupiterOne account ID').default(
158+
process.env.JUPITERONE_ACCOUNT,
159+
'JUPITERONE_ACCOUNT environment variable value',
160+
),
155161
)
156-
.option(
157-
'--api-key <key>',
158-
'JupiterOne API key (JUPITERONE_API_KEY environment variable)',
159-
process.env.JUPITERONE_API_KEY?.replace(/./, '*'),
162+
.addOption(
163+
new Option('--api-key <key>', 'JupiterOne API key').default(
164+
process.env.JUPITERONE_API_KEY,
165+
'JUPITERONE_API_KEY environment variable value',
166+
),
160167
);
161168
}
162169

0 commit comments

Comments
 (0)