Skip to content

Commit

Permalink
feat: add check for for monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
dkontorovskyy committed Jul 21, 2019
1 parent 2caf59b commit b5aba48
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/cli/commands/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import chalk from 'chalk';
import * as pathUtil from 'path';
import * as spinner from '../../lib/spinner';

import * as request from '../../lib/request';
import * as detect from '../../lib/detect';
import * as plugins from '../../lib/plugins';
import {ModuleInfo} from '../../lib/module-info'; // TODO(kyegupov): fix import
Expand All @@ -29,6 +30,11 @@ import {MonitorError} from '../../lib/errors';

const SEPARATOR = '\n-------------------------------------------------------\n';

interface OrgFeatureFlagResponse {
ok: boolean;
userMessage?: string;
}

interface GoodResult {
ok: true;
data: string;
Expand Down Expand Up @@ -75,6 +81,14 @@ async function monitor(...args0: MethodArgs): Promise<any> {

apiTokenExists();

if (options['experimental-dep-graph']) {
const isFFSupported = await isFeatureFlagSupportedForOrg(_.camelCase('experimental-dep-graph'));

if (!isFFSupported.ok) {
throw new Error(isFFSupported.userMessage);
}
}

// Part 1: every argument is a scan target; process them sequentially
for (const path of args as string[]) {
try {
Expand Down Expand Up @@ -272,3 +286,17 @@ function formatMonitorOutput(
packageManager,
})) : strOutput;
}

async function isFeatureFlagSupportedForOrg(featureFlag: string): Promise<OrgFeatureFlagResponse> {
const response = await request({
method: 'GET',
headers: {
Authorization: `token ${snyk.api}`,
},
url: `${config.API}/cli-config/feature-flags/${featureFlag}`,
gzip: true,
json: true,
});

return (response as any).body;
}
1 change: 1 addition & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export interface MonitorOptions {
'all-sub-projects'?: boolean; // Corresponds to multiDepRoot in plugins
'project-name'?: string;
'print-deps'?: boolean;
'experimental-dep-graph'?: boolean;

// An experimental flag to allow monitoring of bigtrees (with degraded deps info and remediation advice).
'prune-repeated-subdependencies'?: boolean;
Expand Down

0 comments on commit b5aba48

Please sign in to comment.