Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: snyk/cli
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.949.0
Choose a base ref
...
head repository: snyk/cli
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.950.0
Choose a head ref
  • 5 commits
  • 18 files changed
  • 4 contributors

Commits on Jun 13, 2022

  1. feat: prune across Gradle dep-graph

    See snyk/snyk-gradle-plugin#209
    
    Also includes transitive bumps to call graph packages:
    * snyk/snyk-gradle-plugin#193
    * snyk/snyk-gradle-plugin#194
    gitphill committed Jun 13, 2022

    Verified

    This commit was signed with the committer’s verified signature.
    francescomari Francesco Mari
    Copy the full SHA
    44f75ff View commit details
  2. test: fix gradle test fixture

    See snyk/snyk-gradle-plugin#209 we now prune across the graph, not just on each transitive line.
    gitphill committed Jun 13, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    9d317de View commit details
  3. chore: Locate UPE Binary

    ofekatr committed Jun 13, 2022

    Verified

    This commit was signed with the committer’s verified signature.
    JackuB Jakub Mikulas
    Copy the full SHA
    02eab93 View commit details
  4. Merge pull request #3318 from snyk/feat/prune-across-dep-graph

    feat: prune across Gradle dep-graph
    gitphill authored Jun 13, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    5f60f03 View commit details
  5. Merge pull request #3304 from snyk/chore/locate-upe-bin-cfg-1846

    chore: Locate UPE Executable [CFG-1846]
    ofekatr authored Jun 13, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    b701bff View commit details
83 changes: 9 additions & 74 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -115,7 +115,7 @@
"snyk-cpp-plugin": "2.20.0",
"snyk-docker-plugin": "^4.38.0",
"snyk-go-plugin": "1.18.0",
"snyk-gradle-plugin": "3.18.1",
"snyk-gradle-plugin": "3.19.0",
"snyk-module": "3.1.0",
"snyk-mvn-plugin": "2.29.7",
"snyk-nodejs-lockfile-parser": "1.38.0",
1 change: 1 addition & 0 deletions src/cli/args.ts
Original file line number Diff line number Diff line change
@@ -35,6 +35,7 @@ const DEBUG_DEFAULT_NAMESPACES = [
'snyk-test',
'snyk',
'snyk-code',
'snyk-iac',
'snyk:find-files',
'snyk:run-test',
'snyk:prune',
3 changes: 3 additions & 0 deletions src/cli/commands/test/iac/local-execution/types.ts
Original file line number Diff line number Diff line change
@@ -351,6 +351,9 @@ export enum IaCErrorCodes {

// Rules bundle errors.
InvalidUserRulesBundleError = 1130,

// Unified Policy Engine executable errors.
InvalidUserPolicyEnginePathError = 1140,
}

export interface TestReturnValue {
31 changes: 16 additions & 15 deletions src/cli/commands/test/iac/v2/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import chalk from 'chalk';
import { TestCommandResult } from '../../../types';
import { RulesBundleLocator } from './rules';
import config from '../../../../../lib/config';
import envPaths from 'env-paths';
import * as path from 'path';
import * as pathLib from 'path';
import * as testLib from '../../../../../lib/iac/test/v2';
import { TestConfig } from '../../../../../lib/iac/test/v2';
import config from '../../../../../lib/config';
import { TestCommandResult } from '../../../types';

export async function test(): Promise<TestCommandResult> {
const bundleLocator = createRulesBundleLocator();
const bundlePath = bundleLocator.locateBundle();
const testConfig = prepareTestConfig();

if (bundlePath) {
console.log(`found rules bundle at ${bundlePath}`);
} else {
console.log('no rules bundle found');
}
await testLib.test(testConfig);

let response = '';
response += chalk.bold.green('new flow for UPE integration - TBC...');
@@ -24,9 +20,14 @@ export async function test(): Promise<TestCommandResult> {
);
}

function createRulesBundleLocator(): RulesBundleLocator {
function prepareTestConfig(): TestConfig {
const systemCachePath = config.CACHE_PATH ?? envPaths('snyk').cache;
const cachedBundlePath = path.join(systemCachePath, 'iac', 'bundle.tar.gz');
const userBundlePath = config.IAC_BUNDLE_PATH;
return new RulesBundleLocator(cachedBundlePath, userBundlePath);
const iacCachePath = pathLib.join(systemCachePath, 'iac');

return {
cachedBundlePath: pathLib.join(iacCachePath, 'bundle.tar.gz'),
userBundlePath: config.IAC_BUNDLE_PATH,
cachedPolicyEnginePath: pathLib.join(iacCachePath, 'snyk-iac-test'),
userPolicyEnginePath: config.IAC_POLICY_ENGINE_PATH,
};
}
Empty file.
1 change: 1 addition & 0 deletions src/lib/config.ts
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ interface Config {
DRIFTCTL_PATH?: string;
DRIFTCTL_URL?: string;
IAC_BUNDLE_PATH?: string;
IAC_POLICY_ENGINE_PATH?: string;
IAC_OUTPUT_V2?: boolean;
}

13 changes: 1 addition & 12 deletions src/lib/iac/drift/driftctl.ts
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ import * as child_process from 'child_process';
import * as fs from 'fs';
import * as os from 'os';
import * as crypto from 'crypto';
import { isExe } from '../file-utils';

const debug = debugLib('driftctl');

@@ -424,18 +425,6 @@ function driftctlUrl(): string {
return `${dctlBaseUrl}/${driftctlVersion}/${driftctlFileName()}`;
}

function isExe(dctlPath: string): Promise<boolean> {
return new Promise<boolean>((resolve) => {
fs.access(dctlPath, fs.constants.X_OK, (err) => {
if (err) {
resolve(false);
return;
}
resolve(true);
});
});
}

function createIfNotExists(path: string) {
if (!fs.existsSync(path)) {
fs.mkdirSync(path, { recursive: true });
11 changes: 11 additions & 0 deletions src/lib/iac/file-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as fs from 'fs';
import { promises as fsPromises } from 'fs';

export async function isExe(path: string): Promise<boolean> {
try {
await fsPromises.access(path, fs.constants.X_OK);
return true;
} catch (err) {
return false;
}
}
12 changes: 12 additions & 0 deletions src/lib/iac/test/v2/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { TestConfig } from './types';
import { setup } from './setup';

export { TestConfig } from './types';

export async function test(testConfig: TestConfig) {
await setup(testConfig);

// TODO: Add the rest of the test steps

return;
}
8 changes: 8 additions & 0 deletions src/lib/iac/test/v2/setup/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { TestConfig } from '../types';
import { initRules } from './rules';
import { initPolicyEngine } from './policy-engine';

export async function setup(testConfig: TestConfig) {
await initPolicyEngine(testConfig);
await initRules(testConfig);
}
66 changes: 66 additions & 0 deletions src/lib/iac/test/v2/setup/policy-engine.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import * as createDebugLogger from 'debug';
import { isExe } from '../../../file-utils';
import { CustomError } from '../../../../errors';
import { IaCErrorCodes } from '../../../../../cli/commands/test/iac/local-execution/types';
import { getErrorStringCode } from '../../../../../cli/commands/test/iac/local-execution/error-utils';
import { TestConfig } from '../types';

const debugLogger = createDebugLogger('snyk-iac');

export class InvalidUserPolicyEnginePathError extends CustomError {
constructor(path: string, message?: string, userMessage?: string) {
super(
message ||
'Failed to find a valid Policy Engine executable in the configured path',
);
this.code = IaCErrorCodes.InvalidUserPolicyEnginePathError;
this.strCode = getErrorStringCode(this.code);
this.userMessage =
userMessage ||
`Could not find a valid Policy Engine executable in the configured path: ${path}` +
'\nEnsure the configured path points to a valid Policy Engine executable.';
}
}

export async function lookupLocalPolicyEngine({
cachedPolicyEnginePath,
userPolicyEnginePath,
}: TestConfig): Promise<string | undefined> {
// Lookup in custom path.
if (userPolicyEnginePath) {
debugLogger(
'User configured IaC Policy Engine executable path detected: %s',
userPolicyEnginePath,
);

if (await isExe(userPolicyEnginePath)) {
return userPolicyEnginePath;
} else {
throw new InvalidUserPolicyEnginePathError(userPolicyEnginePath);
}
}
// Lookup in cache.
else {
if (await isExe(cachedPolicyEnginePath)) {
debugLogger(
'Found cached Policy Engine executable: %s',
cachedPolicyEnginePath,
);
return cachedPolicyEnginePath;
} else {
debugLogger(
'Policy Engine executable was not cached: %s',
cachedPolicyEnginePath,
);
}
}
}

export async function initPolicyEngine(testConfig: TestConfig) {
const localPolicyEnginePath = await lookupLocalPolicyEngine(testConfig);
if (localPolicyEnginePath) {
return localPolicyEnginePath;
}

// TODO: Download Policy Engine executable
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
import * as fs from 'fs';
import * as tar from 'tar';
import { CustomError } from '../../../../../lib/errors';
import { getErrorStringCode } from '../local-execution/error-utils';
import { IaCErrorCodes } from '../local-execution/types';
import { CustomError } from '../../../../errors';
import { getErrorStringCode } from '../../../../../cli/commands/test/iac/local-execution/error-utils';
import { IaCErrorCodes } from '../../../../../cli/commands/test/iac/local-execution/types';
import { TestConfig } from '../types';

export async function initRules(testConfig: TestConfig) {
const bundleLocator = new RulesBundleLocator(
testConfig.cachedBundlePath,
testConfig.userBundlePath,
);
const bundlePath = bundleLocator.locateBundle();

if (bundlePath) {
console.log(`found rules bundle at ${bundlePath}`);
} else {
console.log('no rules bundle found');
}
}

export class RulesBundleLocator {
constructor(
6 changes: 6 additions & 0 deletions src/lib/iac/test/v2/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface TestConfig {
cachedBundlePath: string;
cachedPolicyEnginePath: string;
userBundlePath?: string;
userPolicyEnginePath?: string;
}
Loading