Skip to content

Commit

Permalink
Merge pull request #1476 from snyk/fix/pass-container-monitor-org
Browse files Browse the repository at this point in the history
fix: pass org as part of container monitor command
  • Loading branch information
ivanstanev committed Oct 16, 2020
2 parents 488e884 + ef3ce4b commit 3b81d54
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/lib/ecosystems/monitor.ts
Expand Up @@ -11,7 +11,7 @@ import { getPlugin } from './plugins';
import { BadResult, GoodResult } from '../../cli/commands/monitor/types';
import { formatMonitorOutput } from '../../cli/commands/monitor/formatters/format-monitor-response';
import { getExtraProjectCount } from '../plugins/get-extra-project-count';
import { MonitorError } from '../errors';
import { AuthFailedError, MonitorError } from '../errors';
import {
Ecosystem,
ScanResult,
Expand Down Expand Up @@ -80,6 +80,8 @@ async function monitorDependencies(
options,
);

const configOrg = config.org ? decodeURIComponent(config.org) : undefined;

const payload = {
method: 'PUT',
url: `${config.API}/monitor-dependencies`,
Expand All @@ -89,6 +91,9 @@ async function monitorDependencies(
authorization: 'token ' + snyk.api,
},
body: monitorDependenciesRequest,
qs: {
org: options.org || configOrg,
},
};
try {
const response = await makeRequest<MonitorDependenciesResponse>(
Expand All @@ -100,8 +105,11 @@ async function monitorDependencies(
scanResult,
});
} catch (error) {
if (error.code === 401) {
throw AuthFailedError();
}
if (error.code >= 400 && error.code < 500) {
throw new Error(error.message);
throw new MonitorError(error.code, error.message);
}
errors.push({
error: 'Could not monitor dependencies in ' + path,
Expand Down
32 changes: 32 additions & 0 deletions test/acceptance/cli-monitor/cli-monitor.acceptance.test.ts
Expand Up @@ -1825,6 +1825,38 @@ if (!isWindows) {
);
});

test('`monitor foo:latest --docker --org=fake-org`', async (t) => {
stubDockerPluginResponse(
{
scanResults: [
{
identity: {
type: 'rpm',
},
target: {
image: 'docker-image|foo',
},
facts: [{ type: 'depGraph', data: {} }],
},
],
},
t,
);

await cli.monitor('foo:latest', {
docker: true,
org: 'fake-org',
});
const req = server.popRequest();
t.deepEqual(
req.query,
{
org: 'fake-org',
},
'sends correct payload',
);
});

test('monitor --json multiple folders', async (t) => {
chdirWorkspaces('fail-on');

Expand Down

0 comments on commit 3b81d54

Please sign in to comment.