diff --git a/src/cli/commands/monitor.ts b/src/cli/commands/monitor.ts index 43bdf260c6..d9d75fd63f 100644 --- a/src/cli/commands/monitor.ts +++ b/src/cli/commands/monitor.ts @@ -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 @@ -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; @@ -75,6 +81,14 @@ async function monitor(...args0: MethodArgs): Promise { 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 { @@ -272,3 +286,17 @@ function formatMonitorOutput( packageManager, })) : strOutput; } + +async function isFeatureFlagSupportedForOrg(featureFlag: string): Promise { + 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; +} diff --git a/src/lib/types.ts b/src/lib/types.ts index 69c7d3788d..41db1fff52 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -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;