-
Notifications
You must be signed in to change notification settings - Fork 573
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: change
gen-driftignore
behavior
- Loading branch information
1 parent
0789289
commit 17ee376
Showing
12 changed files
with
308 additions
and
140 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
29 changes: 18 additions & 11 deletions
29
src/cli/commands/gen-driftignore.ts → src/cli/commands/update-exclude-policy.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 |
---|---|---|
@@ -1,36 +1,43 @@ | ||
import { MethodArgs } from '../args'; | ||
import { processCommandArgs } from './process-command-args'; | ||
import * as legacyError from '../../lib/errors/legacy-errors'; | ||
import { runDriftCTL } from '../../lib/iac/drift'; | ||
import * as fs from 'fs'; | ||
import * as snykPolicyLib from 'snyk-policy'; | ||
import { getIacOrgSettings } from './test/iac-local-execution/org-settings/get-iac-org-settings'; | ||
import { UnsupportedEntitlementCommandError } from './test/iac-local-execution/assert-iac-options-flag'; | ||
import config from '../../lib/config'; | ||
import { | ||
parseDriftAnalysisResults, | ||
updateExcludeInPolicy, | ||
} from '../../lib/iac/drift'; | ||
|
||
export default async (...args: MethodArgs): Promise<any> => { | ||
const { options } = processCommandArgs(...args); | ||
|
||
// Ensure that this gen-driftignore command can only be runned when using `snyk iac gen-driftignore` | ||
// Avoid `snyk gen-driftignore` direct usage | ||
// Ensure that this update-exclude-policy command can only be runned when using `snyk iac update-exclude-policy` | ||
// Avoid `snyk update-exclude-policy` direct usage | ||
if (options.iac != true) { | ||
return legacyError('gen-driftignore'); | ||
return legacyError('update-exclude-policy'); | ||
} | ||
|
||
// Ensure that we are allowed to run that command | ||
// by checking the entitlement | ||
const orgPublicId = options.org ?? config.org; | ||
const iacOrgSettings = await getIacOrgSettings(orgPublicId); | ||
if (!iacOrgSettings.entitlements?.iacDrift) { | ||
throw new UnsupportedEntitlementCommandError('gen-driftignore', 'iacDrift'); | ||
throw new UnsupportedEntitlementCommandError( | ||
'update-exclude-policy', | ||
'iacDrift', | ||
); | ||
} | ||
|
||
try { | ||
const ret = await runDriftCTL({ | ||
options: { kind: 'gen-driftignore', ...options }, | ||
stdio: 'inherit', | ||
}); | ||
process.exit(ret.code); | ||
const analysis = parseDriftAnalysisResults(fs.readFileSync(0).toString()); | ||
const policy = await snykPolicyLib.load(); | ||
await updateExcludeInPolicy(policy, analysis, options); | ||
await snykPolicyLib.save(policy); | ||
} catch (e) { | ||
const err = new Error('Error running `iac gen-driftignore` ' + e); | ||
const err = new Error('Error running `iac update-exclude-policy` ' + e); | ||
return Promise.reject(err); | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
{ | ||
"options": { | ||
"deep": true, | ||
"only_managed": false, | ||
"only_unmanaged": false | ||
}, | ||
"summary": { | ||
"total_resources": 6, | ||
"total_changed": 1, | ||
"total_unmanaged": 2, | ||
"total_missing": 2, | ||
"total_managed": 2, | ||
"total_iac_source_count": 3 | ||
}, | ||
"managed": [ | ||
{ | ||
"id": "AKIA5QYBVVD25KFXJHYJ", | ||
"type": "aws_iam_access_key" | ||
}, | ||
{ | ||
"id": "test-managed", | ||
"type": "aws_iam_user" | ||
} | ||
], | ||
"unmanaged": [ | ||
{ | ||
"id": "driftctl", | ||
"type": "aws_s3_bucket_policy" | ||
}, | ||
{ | ||
"id": "driftctl", | ||
"type": "aws_s3_bucket_notification" | ||
} | ||
], | ||
"missing": [ | ||
{ | ||
"id": "test-driftctl2", | ||
"type": "aws_iam_user" | ||
}, | ||
{ | ||
"id": "AKIA5QYBVVD2Y6PBAAPY", | ||
"type": "aws_iam_access_key" | ||
} | ||
], | ||
"differences": [ | ||
{ | ||
"res": { | ||
"id": "AKIA5QYBVVD25KFXJHYJ", | ||
"type": "aws_iam_access_key" | ||
}, | ||
"changelog": [ | ||
{ | ||
"type": "update", | ||
"path": [ | ||
"status" | ||
], | ||
"from": "Active", | ||
"to": "Inactive", | ||
"computed": false | ||
} | ||
] | ||
} | ||
], | ||
"coverage": 33, | ||
"alerts": { | ||
"aws_iam_access_key": [ | ||
{ | ||
"message": "This is an alert" | ||
} | ||
] | ||
}, | ||
"scan_duration": 123, | ||
"provider_name": "AWS", | ||
"provider_version": "2.18.5" | ||
} |
Oops, something went wrong.