-
Notifications
You must be signed in to change notification settings - Fork 564
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into chore/cliv2_case_insensitive_env_vars
- Loading branch information
Showing
24 changed files
with
448 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
import { TestConfig } from '../types'; | ||
import { initRules } from './rules'; | ||
import { initPolicyEngine } from './policy-engine'; | ||
import { initLocalCache } from './local-cache'; | ||
|
||
export async function setup(testConfig: TestConfig) { | ||
const policyEnginePath = await initPolicyEngine(testConfig); | ||
const rulesBundlePath = await initRules(testConfig); | ||
return { policyEnginePath, rulesBundlePath }; | ||
return await initLocalCache(testConfig); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { TestConfig } from '../../types'; | ||
import { initRules } from './rules'; | ||
import { initPolicyEngine } from './policy-engine'; | ||
import { createDirIfNotExists } from '../../../../file-utils'; | ||
import { CustomError } from '../../../../../errors'; | ||
import { FailedToInitLocalCacheError } from '../../../../../../cli/commands/test/iac/local-execution/local-cache'; | ||
|
||
export async function initLocalCache(testConfig: TestConfig) { | ||
try { | ||
await createDirIfNotExists(testConfig.iacCachePath); | ||
|
||
const policyEnginePath = await initPolicyEngine(testConfig); | ||
const rulesBundlePath = await initRules(testConfig); | ||
|
||
return { policyEnginePath, rulesBundlePath }; | ||
} catch (err) { | ||
throw err instanceof CustomError ? err : new FailedToInitLocalCacheError(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/lib/iac/test/v2/setup/local-cache/policy-engine/constants/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { formatPolicyEngineFileName } from './utils'; | ||
|
||
/** | ||
* The Policy Engine release version associated with this Snyk CLI version. | ||
*/ | ||
export const releaseVersion = '0.1.0'; | ||
|
||
/** | ||
* The Policy Engine executable's file name. | ||
*/ | ||
export const policyEngineFileName = formatPolicyEngineFileName(releaseVersion); |
19 changes: 19 additions & 0 deletions
19
src/lib/iac/test/v2/setup/local-cache/policy-engine/constants/utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import * as os from 'os'; | ||
|
||
export function formatPolicyEngineFileName(releaseVersion: string) { | ||
let platform = 'Linux'; | ||
switch (os.platform()) { | ||
case 'darwin': | ||
platform = 'Darwin'; | ||
break; | ||
case 'win32': | ||
platform = 'Windows'; | ||
break; | ||
} | ||
|
||
const arch = os.arch() === 'arm64' ? 'arm64' : 'x86_64'; | ||
|
||
const execExt = os.platform() === 'win32' ? '.exe' : ''; | ||
|
||
return `snyk-iac-test_${releaseVersion}_${platform}_${arch}${execExt}`; | ||
} |
13 changes: 13 additions & 0 deletions
13
src/lib/iac/test/v2/setup/local-cache/policy-engine/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { TestConfig } from '../../../types'; | ||
import { InvalidUserPolicyEnginePathError, lookupLocal } from './lookup-local'; | ||
|
||
export async function initPolicyEngine(testConfig: TestConfig) { | ||
const localPolicyEnginePath = await lookupLocal(testConfig); | ||
if (localPolicyEnginePath) { | ||
return localPolicyEnginePath; | ||
} | ||
|
||
// TODO: Download Policy Engine executable | ||
|
||
throw new InvalidUserPolicyEnginePathError('', 'policy engine not found'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 13 additions & 5 deletions
18
src/lib/iac/test/v2/setup/rules.ts → ...ib/iac/test/v2/setup/local-cache/rules.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
export interface TestConfig { | ||
paths: string[]; | ||
cachedBundlePath: string; | ||
cachedPolicyEnginePath: string; | ||
iacCachePath: string; | ||
userBundlePath?: string; | ||
userPolicyEnginePath?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.