Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions src/cli/commands/monitor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ import {
PNPM_FEATURE_FLAG,
UV_FEATURE_FLAG,
MAVEN_DVERBOSE_EXHAUSTIVE_DEPS_FF,
INCLUDE_GO_STANDARD_LIBRARY_DEPS_FEATURE_FLAG,
DISABLE_GO_PACKAGE_URLS_IN_CLI_FEATURE_FLAG,
} from '../../../lib/package-managers';
import { normalizeTargetFile } from '../../../lib/normalize-target-file';
import { getOrganizationID } from '../../../lib/organization';
Expand Down Expand Up @@ -201,19 +203,21 @@ export default async function monitor(...args0: MethodArgs): Promise<any> {
);
}

let hasPnpmSupport = false;
let enableMavenDverboseExhaustiveDeps = false;
try {
hasPnpmSupport = (await hasFeatureFlag(
PNPM_FEATURE_FLAG,
options,
)) as boolean;
} catch (err) {
hasPnpmSupport = false;
}

const hasPnpmSupport = await hasFeatureFlagOrDefault(
PNPM_FEATURE_FLAG,
options,
);
const hasUvSupport = await hasFeatureFlagOrDefault(UV_FEATURE_FLAG, options);
const includeGoStandardLibraryDeps = await hasFeatureFlagOrDefault(
INCLUDE_GO_STANDARD_LIBRARY_DEPS_FEATURE_FLAG,
options,
);
const disableGoPackageUrls = await hasFeatureFlagOrDefault(
DISABLE_GO_PACKAGE_URLS_IN_CLI_FEATURE_FLAG,
options,
);

let enableMavenDverboseExhaustiveDeps = false;
try {
const args = options['_doubleDashArgs'] || [];
const verboseEnabled =
Expand Down Expand Up @@ -241,6 +245,12 @@ export default async function monitor(...args0: MethodArgs): Promise<any> {
if (hasUvSupport) {
featureFlags.add(UV_FEATURE_FLAG);
}
if (includeGoStandardLibraryDeps) {
featureFlags.add(INCLUDE_GO_STANDARD_LIBRARY_DEPS_FEATURE_FLAG);
}
if (disableGoPackageUrls) {
featureFlags.add(DISABLE_GO_PACKAGE_URLS_IN_CLI_FEATURE_FLAG);
}

const showMavenScope = await isFeatureFlagSupportedForOrg(
SHOW_MAVEN_BUILD_SCOPE,
Expand Down
4 changes: 4 additions & 0 deletions src/lib/package-managers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ export const PNPM_FEATURE_FLAG = 'enablePnpmCli';
export const UV_FEATURE_FLAG = 'enableUvCLI';
export const MAVEN_DVERBOSE_EXHAUSTIVE_DEPS_FF =
'enableMavenDverboseExhaustiveDeps';
export const INCLUDE_GO_STANDARD_LIBRARY_DEPS_FEATURE_FLAG =
'includeGoStandardLibraryDeps';
export const DISABLE_GO_PACKAGE_URLS_IN_CLI_FEATURE_FLAG =
'disableGoPackageUrlsInCli';

export type SupportedPackageManagers =
| 'rubygems'
Expand Down
26 changes: 11 additions & 15 deletions src/lib/plugins/build-plugin-options.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { Options, TestOptions, MonitorOptions } from '../types';
import { hasFeatureFlagOrDefault } from '../feature-flags';
import {
DISABLE_GO_PACKAGE_URLS_IN_CLI_FEATURE_FLAG,
INCLUDE_GO_STANDARD_LIBRARY_DEPS_FEATURE_FLAG,
} from '../package-managers';

/**
* Returns a shallow clone of the original `options` object with any
* plugin-specific configuration injected.
*/
export async function buildPluginOptions(
options: Options & (TestOptions | MonitorOptions),
featureFlags: Set<string> = new Set<string>(),
): Promise<Options & (TestOptions | MonitorOptions)> {
const pluginOptions: any = { ...options };

Expand All @@ -15,22 +19,14 @@ export async function buildPluginOptions(
options.packageManager === 'golangdep';

if (isGoPackageManager) {
const includeGoStandardLibraryDeps = await hasFeatureFlagOrDefault(
'includeGoStandardLibraryDeps',
options,
false,
);

const disableGoPackageUrls = await hasFeatureFlagOrDefault(
'disableGoPackageUrlsInCli',
options,
false,
);

pluginOptions.configuration = {
...(pluginOptions.configuration || {}),
includeGoStandardLibraryDeps,
includePackageUrls: disableGoPackageUrls ? false : true,
includeGoStandardLibraryDeps: featureFlags.has(
INCLUDE_GO_STANDARD_LIBRARY_DEPS_FEATURE_FLAG,
),
includePackageUrls: !featureFlags.has(
DISABLE_GO_PACKAGE_URLS_IN_CLI_FEATURE_FLAG,
),
// enable fix for replaced modules.
useReplaceName: true,
} as Options['configuration'];
Expand Down
4 changes: 2 additions & 2 deletions src/lib/plugins/get-single-plugin-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { TestOptions, Options, MonitorOptions } from '../types';
import { snykHttpClient } from '../request/snyk-http-client';
import * as types from './types';
import { buildPluginOptions } from './build-plugin-options';
const { SHOW_MAVEN_BUILD_SCOPE, SHOW_NPM_SCOPE } = require('../feature-flags');
import { SHOW_MAVEN_BUILD_SCOPE, SHOW_NPM_SCOPE } from '../feature-flags';

export async function getSinglePluginResult(
root: string,
Expand All @@ -17,7 +17,7 @@ export async function getSinglePluginResult(
const moduleInfo = ModuleInfo(plugin, options.policy);

// Build final options with any ecosystem-specific configurations/flags injected
const pluginOptions = await buildPluginOptions(options);
const pluginOptions = await buildPluginOptions(options, featureFlags);

const inspectRes: pluginApi.InspectResult = await moduleInfo.inspect(
root,
Expand Down
38 changes: 28 additions & 10 deletions src/lib/snyk-test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ const {
SHOW_NPM_SCOPE,
hasFeatureFlag,
isFeatureFlagSupportedForOrg,
hasFeatureFlagOrDefault,
} = require('../feature-flags');
const {
PNPM_FEATURE_FLAG,
MAVEN_DVERBOSE_EXHAUSTIVE_DEPS_FF,
INCLUDE_GO_STANDARD_LIBRARY_DEPS_FEATURE_FLAG,
DISABLE_GO_PACKAGE_URLS_IN_CLI_FEATURE_FLAG,
} = require('../package-managers');
const { getOrganizationID } = require('../organization');

Expand All @@ -37,14 +40,20 @@ async function test(root, options, callback) {
}

async function executeTest(root, options) {
let hasPnpmSupport = false;
let enableMavenDverboseExhaustiveDeps = false;
try {
hasPnpmSupport = await hasFeatureFlag(PNPM_FEATURE_FLAG, options);
} catch (err) {
hasPnpmSupport = false;
}
const hasPnpmSupport = await hasFeatureFlagOrDefault(
PNPM_FEATURE_FLAG,
options,
);
const includeGoStandardLibraryDeps = await hasFeatureFlagOrDefault(
INCLUDE_GO_STANDARD_LIBRARY_DEPS_FEATURE_FLAG,
options,
);
const disableGoPackageUrls = await hasFeatureFlagOrDefault(
DISABLE_GO_PACKAGE_URLS_IN_CLI_FEATURE_FLAG,
options,
);

let enableMavenDverboseExhaustiveDeps = false;
try {
const args = options['_doubleDashArgs'] || [];
const verboseEnabled =
Expand All @@ -66,9 +75,18 @@ async function executeTest(root, options) {
}

try {
const featureFlags = hasPnpmSupport
? new Set([PNPM_FEATURE_FLAG])
: new Set([]);
const featureFlags = new Set();
if (hasPnpmSupport) {
featureFlags.add(PNPM_FEATURE_FLAG);
}

if (includeGoStandardLibraryDeps) {
featureFlags.add(INCLUDE_GO_STANDARD_LIBRARY_DEPS_FEATURE_FLAG);
}

if (disableGoPackageUrls) {
featureFlags.add(DISABLE_GO_PACKAGE_URLS_IN_CLI_FEATURE_FLAG);
}

const showMavenScope = await isFeatureFlagSupportedForOrg(
SHOW_MAVEN_BUILD_SCOPE,
Expand Down
5 changes: 0 additions & 5 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,6 @@ export interface Options {

// Plugin configuration options
configuration?: {
// Used only with the Go plugin. When enabled, includes Go standard library packages in dependency graph.
includeGoStandardLibraryDeps?: boolean;
// Used only with the Go plugin. When enabled, includes PackageURL information in dep-graphs.
// TODO: remove once UNIFY-891 is done.
includePackageUrls?: boolean;
// Used only with the Go plugin.
// TODO: remove once UNIFY-891 is done.
useReplaceName?: boolean;
Expand Down
Loading
Loading