snyk 1.778.0 → 1.779.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -53,7 +53,7 @@ const types_1 = __webpack_require__(42258);
53
53
  const analytics = __webpack_require__(82744);
54
54
  const math_utils_1 = __webpack_require__(48537);
55
55
  const file_utils_1 = __webpack_require__(58486);
56
- function addIacAnalytics(formattedResults, ignoredIssuesCount, isLocalCustomRules) {
56
+ function addIacAnalytics(formattedResults, ignoredIssuesCount) {
57
57
  let totalIssuesCount = 0;
58
58
  const customRulesIdsFoundInIssues = {};
59
59
  let issuesFromCustomRulesCount = 0;
@@ -84,9 +84,7 @@ function addIacAnalytics(formattedResults, ignoredIssuesCount, isLocalCustomRule
84
84
  analytics.add('iac-test-count', formattedResults.length);
85
85
  analytics.add('iac-custom-rules-issues-count', issuesFromCustomRulesCount);
86
86
  analytics.add('iac-custom-rules-issues-percentage', math_utils_1.calculatePercentage(issuesFromCustomRulesCount, totalIssuesCount));
87
- if (!isLocalCustomRules) {
88
- analytics.add('iac-custom-rules-checksum', file_utils_1.computeCustomRulesBundleChecksum());
89
- }
87
+ analytics.add('iac-custom-rules-checksum', file_utils_1.computeCustomRulesBundleChecksum());
90
88
  analytics.add('iac-custom-rules-coverage-count', uniqueCustomRulesCount);
91
89
  }
92
90
  exports.addIacAnalytics = addIacAnalytics;
@@ -679,7 +677,6 @@ const analytics_1 = __webpack_require__(22716);
679
677
  const usage_tracking_1 = __webpack_require__(43156);
680
678
  const policy_1 = __webpack_require__(25476);
681
679
  const measurable_methods_1 = __webpack_require__(78272);
682
- const feature_flags_1 = __webpack_require__(63011);
683
680
  const assert_iac_options_flag_1 = __webpack_require__(68590);
684
681
  const user_config_1 = __webpack_require__(28137);
685
682
  const config_1 = __webpack_require__(22541);
@@ -687,26 +684,33 @@ const policy_2 = __webpack_require__(32615);
687
684
  const errors_1 = __webpack_require__(55191);
688
685
  const error_utils_1 = __webpack_require__(23872);
689
686
  const oci_pull_1 = __webpack_require__(5029);
690
- const unsupported_entitlement_error_1 = __webpack_require__(78673);
691
687
  const url_utils_1 = __webpack_require__(80256);
688
+ const chalk_1 = __webpack_require__(32589);
692
689
  // this method executes the local processing engine and then formats the results to adapt with the CLI output.
693
690
  // this flow is the default GA flow for IAC scanning.
694
691
  async function test(pathToScan, options) {
695
- var _a;
692
+ var _a, _b, _c;
696
693
  try {
697
694
  let customRulesPath;
698
695
  const orgPublicId = (_a = options.org) !== null && _a !== void 0 ? _a : config_1.default.org;
699
696
  const iacOrgSettings = await measurable_methods_1.getIacOrgSettings(orgPublicId);
700
697
  if (options.rules) {
701
- await assertRulesFlagAvailable(orgPublicId, iacOrgSettings);
698
+ if (!((_b = iacOrgSettings.entitlements) === null || _b === void 0 ? void 0 : _b.iacCustomRulesEntitlement)) {
699
+ throw new assert_iac_options_flag_1.UnsupportedEntitlementFlagError('rules', 'iacCustomRulesEntitlement');
700
+ }
702
701
  customRulesPath = options.rules;
703
702
  }
704
703
  const isOCIRegistryURLProvided = checkOCIRegistryURLProvided(iacOrgSettings);
704
+ if (isOCIRegistryURLProvided || customRulesPath) {
705
+ console.log(chalk_1.default.hex('#ff9b00')('Using custom rules to generate misconfigurations.'));
706
+ }
705
707
  if (isOCIRegistryURLProvided && customRulesPath) {
706
708
  throw new FailedToExecuteCustomRulesError();
707
709
  }
708
710
  if (isOCIRegistryURLProvided) {
709
- await assertPullAvailable(orgPublicId, iacOrgSettings);
711
+ if (!((_c = iacOrgSettings.entitlements) === null || _c === void 0 ? void 0 : _c.iacCustomRulesEntitlement)) {
712
+ throw new oci_pull_1.UnsupportedEntitlementPullError('iacCustomRulesEntitlement');
713
+ }
710
714
  await pullIaCCustomRules(iacOrgSettings);
711
715
  }
712
716
  else {
@@ -736,7 +740,7 @@ async function test(pathToScan, options) {
736
740
  // If something has gone wrong, err on the side of allowing the user to
737
741
  // run their tests by squashing the error.
738
742
  }
739
- analytics_1.addIacAnalytics(filteredIssues, ignoreCount, !!customRulesPath);
743
+ analytics_1.addIacAnalytics(filteredIssues, ignoreCount);
740
744
  // TODO: add support for proper typing of old TestResult interface.
741
745
  return {
742
746
  results: filteredIssues,
@@ -829,7 +833,7 @@ async function pullIaCCustomRules(iacOrgSettings) {
829
833
  throw new FailedToPullCustomBundleError('There was an authentication error. Incorrect credentials provided.');
830
834
  }
831
835
  else if (err.statusCode === 404) {
832
- throw new FailedToPullCustomBundleError('The remote repository could not be found. Please check the provided URL.');
836
+ throw new FailedToPullCustomBundleError('The remote repository could not be found. Please check the provided registry URL.');
833
837
  }
834
838
  else if (err instanceof oci_pull_1.InvalidManifestSchemaVersionError) {
835
839
  throw new FailedToPullCustomBundleError(err.message);
@@ -846,62 +850,15 @@ async function pullIaCCustomRules(iacOrgSettings) {
846
850
  }
847
851
  }
848
852
  exports.pullIaCCustomRules = pullIaCCustomRules;
849
- /**
850
- * Asserts the custom-rules feature is available for the provided org.
851
- */
852
- async function assertCustomRulesAvailable(orgPublicId, iacOrgSettings) {
853
- var _a;
854
- const isCustomRulesEnabled = !!(await feature_flags_1.isFeatureFlagSupportedForOrg('iacCustomRules', orgPublicId)).ok;
855
- if (!isCustomRulesEnabled) {
856
- throw new errors_1.UnsupportedFeatureFlagError('iacCustomRules');
857
- }
858
- const isEntitledToCustomRules = !!((_a = iacOrgSettings.entitlements) === null || _a === void 0 ? void 0 : _a.iacCustomRulesEntitlement);
859
- if (!isEntitledToCustomRules) {
860
- throw new unsupported_entitlement_error_1.UnsupportedEntitlementError('iacCustomRulesEntitlement');
861
- }
862
- }
863
- /**
864
- * Asserts the --rules flag is available for the provided org.
865
- */
866
- async function assertRulesFlagAvailable(orgPublicId, iacOrgSettings) {
867
- try {
868
- await assertCustomRulesAvailable(orgPublicId, iacOrgSettings);
869
- }
870
- catch (err) {
871
- if (err instanceof unsupported_entitlement_error_1.UnsupportedEntitlementError) {
872
- throw new assert_iac_options_flag_1.UnsupportedEntitlementFlagError('rules', err.entitlement);
873
- }
874
- else if (err instanceof errors_1.UnsupportedFeatureFlagError) {
875
- throw new assert_iac_options_flag_1.FlagError('rules', err.featureFlag);
876
- }
877
- else {
878
- throw err;
879
- }
880
- }
881
- }
882
- /**
883
- * Asserts the feature custom-rules bundles pulling feature is available for the provided org.
884
- */
885
- async function assertPullAvailable(orgPublicId, iacOrgSettings) {
886
- try {
887
- await assertCustomRulesAvailable(orgPublicId, iacOrgSettings);
888
- }
889
- catch (err) {
890
- if (err instanceof unsupported_entitlement_error_1.UnsupportedEntitlementError) {
891
- throw new oci_pull_1.UnsupportedEntitlementPullError(err.entitlement);
892
- }
893
- else if (err instanceof errors_1.UnsupportedFeatureFlagError) {
894
- throw new oci_pull_1.UnsupportedFeatureFlagPullError(err.featureFlag);
895
- }
896
- }
897
- }
898
853
  class FailedToPullCustomBundleError extends errors_1.CustomError {
899
854
  constructor(message) {
900
855
  super(message || 'Could not pull custom bundle');
901
856
  this.code = types_1.IaCErrorCodes.FailedToPullCustomBundleError;
902
857
  this.strCode = error_utils_1.getErrorStringCode(this.code);
903
- this.userMessage = `${message ? message + ' ' : ''}
904
- We were unable to download the custom bundle to the disk. Please ensure access to the remote Registry and validate you have provided all the right parameters.`;
858
+ this.userMessage =
859
+ `${message ? message + ' ' : ''}` +
860
+ '\nWe were unable to download the custom bundle to the disk. Please ensure access to the remote Registry and validate you have provided all the right parameters.' +
861
+ '\nSee documentation on troubleshooting: https://docs.snyk.io/products/snyk-infrastructure-as-code/custom-rules/use-IaC-custom-rules-with-CLI/using-a-remote-custom-rules-bundle#troubleshooting';
905
862
  }
906
863
  }
907
864
  exports.FailedToPullCustomBundleError = FailedToPullCustomBundleError;
@@ -1188,7 +1145,7 @@ exports.pull = measurableOciPull;
1188
1145
  "use strict";
1189
1146
 
1190
1147
  Object.defineProperty(exports, "__esModule", ({ value: true }));
1191
- exports.UnsupportedEntitlementPullError = exports.UnsupportedFeatureFlagPullError = exports.InvalidRemoteRegistryURLError = exports.InvalidManifestSchemaVersionError = exports.FailedToBuildOCIArtifactError = exports.pull = exports.extractOCIRegistryURLComponents = exports.CUSTOM_RULES_TARBALL = void 0;
1148
+ exports.UnsupportedEntitlementPullError = exports.InvalidRemoteRegistryURLError = exports.InvalidManifestSchemaVersionError = exports.FailedToBuildOCIArtifactError = exports.pull = exports.extractOCIRegistryURLComponents = exports.CUSTOM_RULES_TARBALL = void 0;
1192
1149
  const registryClient = __webpack_require__(28310);
1193
1150
  const fs_1 = __webpack_require__(35747);
1194
1151
  const path = __webpack_require__(85622);
@@ -1286,15 +1243,6 @@ class InvalidRemoteRegistryURLError extends errors_1.CustomError {
1286
1243
  }
1287
1244
  }
1288
1245
  exports.InvalidRemoteRegistryURLError = InvalidRemoteRegistryURLError;
1289
- class UnsupportedFeatureFlagPullError extends errors_1.CustomError {
1290
- constructor(featureFlag) {
1291
- super('OCI Pull not supported - Missing the ${featureFlag} feature flag');
1292
- this.code = types_1.IaCErrorCodes.UnsupportedFeatureFlagPullError;
1293
- this.strCode = error_utils_1.getErrorStringCode(this.code);
1294
- this.userMessage = `The custom rules feature is not supported for this org - The feature flag '${featureFlag}' is not currently enabled. It can be enabled via Snyk Preview, if you are on the Enterprise Plan.`;
1295
- }
1296
- }
1297
- exports.UnsupportedFeatureFlagPullError = UnsupportedFeatureFlagPullError;
1298
1246
  class UnsupportedEntitlementPullError extends errors_1.CustomError {
1299
1247
  constructor(entitlement) {
1300
1248
  super(`OCI Pull not supported - Missing the ${entitlement} entitlement`);
@@ -2360,28 +2308,6 @@ FailOnError.ERROR_MESSAGE = 'Invalid fail on argument, please use one of: ' +
2360
2308
  Object.keys(common_1.FAIL_ON).join(' | ');
2361
2309
 
2362
2310
 
2363
- /***/ }),
2364
-
2365
- /***/ 78673:
2366
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
2367
-
2368
- "use strict";
2369
-
2370
- Object.defineProperty(exports, "__esModule", ({ value: true }));
2371
- exports.UnsupportedEntitlementError = void 0;
2372
- const custom_error_1 = __webpack_require__(17188);
2373
- class UnsupportedEntitlementError extends custom_error_1.CustomError {
2374
- constructor(entitlement, userMessage = `This feature is currently not enabled for your org. To enable it, please contact snyk support.`) {
2375
- super('Unsupported feature - Missing the ${entitlementName} entitlement');
2376
- this.entitlement = entitlement;
2377
- this.code = UnsupportedEntitlementError.ERROR_CODE;
2378
- this.userMessage = userMessage;
2379
- }
2380
- }
2381
- exports.UnsupportedEntitlementError = UnsupportedEntitlementError;
2382
- UnsupportedEntitlementError.ERROR_CODE = 403;
2383
-
2384
-
2385
2311
  /***/ }),
2386
2312
 
2387
2313
  /***/ 9401: