Skip to content

Commit

Permalink
chore: snyk-test types + use SupportedProjectTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
orkamara committed Jun 25, 2020
1 parent d2a5578 commit 430745a
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 38 deletions.
2 changes: 0 additions & 2 deletions src/lib/cloud-config-projects.ts

This file was deleted.

5 changes: 5 additions & 0 deletions src/lib/cloud-config/cloud-config-projects.ts
@@ -0,0 +1,5 @@
export type SupportedCloudConfigs = 'k8sconfig' | 'helmconfig';

export const TEST_SUPPORTED_CLOUD_CONFIG_PROJECTS: SupportedCloudConfigs[] = [
'k8sconfig',
];
3 changes: 2 additions & 1 deletion src/lib/snyk-test/legacy.ts
@@ -1,6 +1,7 @@
import * as _ from '@snyk/lodash';
import * as depGraphLib from '@snyk/dep-graph';
import { SupportedPackageManagers } from '../package-managers';
import { SupportedProjectTypes } from '../types';
import { SEVERITIES } from './common';

interface Pkg {
Expand Down Expand Up @@ -279,7 +280,7 @@ export interface RemediationChanges {
function convertTestDepGraphResultToLegacy(
res: TestDepGraphResponse,
depGraph: depGraphLib.DepGraph,
packageManager: string,
packageManager: SupportedProjectTypes | undefined,
severityThreshold?: SEVERITY,
): LegacyVulnApiResult {
const result = res.result;
Expand Down
36 changes: 2 additions & 34 deletions src/lib/snyk-test/run-test.ts
Expand Up @@ -49,44 +49,12 @@ import { getSubProjectCount } from '../plugins/get-sub-project-count';
import { serializeCallGraphWithMetrics } from '../reachable-vulns';
import { validateOptions } from '../options-validator';
import { findAndLoadPolicy } from '../policy';
import { Payload, PayloadBody, DepTreeFromResolveDeps } from './types';

const debug = debugModule('snyk');

export = runTest;

interface DepTreeFromResolveDeps extends DepTree {
numDependencies: number;
pluck: any;
}

interface PayloadBody {
depGraph?: depGraphLib.DepGraph; // missing for legacy endpoint (options.vulnEndpoint)
callGraph?: any;
policy?: string;
targetFile?: string;
targetFileRelativePath?: string;
projectNameOverride?: string;
hasDevDependencies?: boolean;
originalProjectName?: string; // used only for display
foundProjectCount?: number; // used only for display
docker?: any;
displayTargetFile?: string;
target?: GitTarget | ContainerTarget | null;
}

interface Payload {
method: string;
url: string;
json: boolean;
headers: {
'x-is-ci': boolean;
authorization: string;
};
body?: PayloadBody;
qs?: object | null;
modules?: DepTreeFromResolveDeps;
}

async function runTest(
projectType: SupportedProjectTypes | undefined,
root: string,
Expand Down Expand Up @@ -173,7 +141,7 @@ async function runTest(

async function parseRes(
depGraph: depGraphLib.DepGraph | undefined,
pkgManager: string | undefined,
pkgManager: SupportedProjectTypes | undefined,
res: LegacyVulnApiResult,
options: Options & TestOptions,
payload: Payload,
Expand Down
47 changes: 47 additions & 0 deletions src/lib/snyk-test/types.ts
@@ -0,0 +1,47 @@
import * as depGraphLib from '@snyk/dep-graph';
import { GitTarget, ContainerTarget } from '../project-metadata/types';
import { DepTree } from '../types';

interface PayloadBody {
depGraph?: depGraphLib.DepGraph; // missing for legacy endpoint (options.vulnEndpoint)
callGraph?: any;
policy?: string;
targetFile?: string;
targetFileRelativePath?: string;
projectNameOverride?: string;
hasDevDependencies?: boolean;
originalProjectName?: string; // used only for display
foundProjectCount?: number; // used only for display
docker?: any;
displayTargetFile?: string;
target?: GitTarget | ContainerTarget | null;
}

export interface DepTreeFromResolveDeps extends DepTree {
numDependencies: number;
pluck: any;
}

export interface Payload {
method: string;
url: string;
json: boolean;
headers: {
'x-is-ci': boolean;
authorization: string;
};
body?: PayloadBody | CloudConfigPayloadBody;
qs?: object | null;
modules?: DepTreeFromResolveDeps;
}

export interface CloudConfigPayloadBody {
policy: string;
targetFile?: string;
targetFileRelativePath?: string;
originalProjectName?: string; // used only for display
foundProjectCount?: number; // used only for display
displayTargetFile?: string;
target?: GitTarget | ContainerTarget | null;
fileContent: string;
}
2 changes: 1 addition & 1 deletion src/lib/types.ts
@@ -1,5 +1,5 @@
import { SupportedPackageManagers } from './package-managers';
import { SupportedCloudConfigs } from './cloud-config-projects';
import { SupportedCloudConfigs } from './cloud-config/cloud-config-projects';
import { legacyCommon as legacyApi } from '@snyk/cli-interface';
import { SEVERITY } from './snyk-test/legacy';
import { FailOn } from './snyk-test/common';
Expand Down

0 comments on commit 430745a

Please sign in to comment.