831.index.js 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. "use strict";
  2. exports.id = 831;
  3. exports.ids = [831];
  4. exports.modules = {
  5. /***/ 52369:
  6. /***/ ((__unused_webpack_module, exports) => {
  7. Object.defineProperty(exports, "__esModule", ({ value: true }));
  8. exports.processCommandArgs = void 0;
  9. function processCommandArgs(...args) {
  10. let options = {};
  11. if (typeof args[args.length - 1] === 'object') {
  12. options = args.pop();
  13. }
  14. args = args.filter(Boolean);
  15. // For repository scanning, populate with default path (cwd) if no path given
  16. if (args.length === 0 && !options.docker) {
  17. args.unshift(process.cwd());
  18. }
  19. return { options, paths: args };
  20. }
  21. exports.processCommandArgs = processCommandArgs;
  22. /***/ }),
  23. /***/ 87831:
  24. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  25. Object.defineProperty(exports, "__esModule", ({ value: true }));
  26. const process_command_args_1 = __webpack_require__(52369);
  27. const legacyError = __webpack_require__(79407);
  28. const fs = __webpack_require__(35747);
  29. const snykPolicyLib = __webpack_require__(70535);
  30. const get_iac_org_settings_1 = __webpack_require__(11693);
  31. const assert_iac_options_flag_1 = __webpack_require__(33111);
  32. const config_1 = __webpack_require__(25425);
  33. const drift_1 = __webpack_require__(26445);
  34. const analytics = __webpack_require__(82744);
  35. exports.default = async (...args) => {
  36. var _a, _b;
  37. const { options } = process_command_args_1.processCommandArgs(...args);
  38. // Ensure that this update-exclude-policy command can only be runned when using `snyk iac update-exclude-policy`
  39. // Avoid `snyk update-exclude-policy` direct usage
  40. if (options.iac != true) {
  41. return legacyError('update-exclude-policy');
  42. }
  43. // Ensure that we are allowed to run that command
  44. // by checking the entitlement
  45. const orgPublicId = (_a = options.org) !== null && _a !== void 0 ? _a : config_1.default.org;
  46. const iacOrgSettings = await get_iac_org_settings_1.getIacOrgSettings(orgPublicId);
  47. if (!((_b = iacOrgSettings.entitlements) === null || _b === void 0 ? void 0 : _b.iacDrift)) {
  48. throw new assert_iac_options_flag_1.UnsupportedEntitlementCommandError('update-exclude-policy', 'iacDrift');
  49. }
  50. try {
  51. // There's an open bug for this in Windows in the current version of node when called with no stdinput.
  52. // See https://github.com/nodejs/node/issues/19831
  53. // The actual error handling behavior is enough for now but may be improved if needed
  54. const analysis = drift_1.parseDriftAnalysisResults(fs.readFileSync(0).toString());
  55. // Add analytics
  56. analytics.add('is-iac-drift', true);
  57. let policy;
  58. try {
  59. policy = await snykPolicyLib.load();
  60. }
  61. catch (error) {
  62. if (error.code === 'ENOENT') {
  63. // policy file does not exist - create it
  64. policy = await snykPolicyLib.create();
  65. }
  66. else {
  67. throw error;
  68. }
  69. }
  70. await drift_1.updateExcludeInPolicy(policy, analysis, options);
  71. await snykPolicyLib.save(policy);
  72. }
  73. catch (e) {
  74. const err = new Error('Error running `iac update-exclude-policy` ' + e);
  75. return Promise.reject(err);
  76. }
  77. };
  78. /***/ })
  79. };
  80. ;
  81. //# sourceMappingURL=831.index.js.map