snyk 1.1038.0 → 1.1040.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.
@@ -2275,6 +2275,7 @@ const keys = [
2275
2275
  'var-file',
2276
2276
  'detectionDepth',
2277
2277
  'cloud-context',
2278
+ 'snyk-cloud-environment',
2278
2279
  // PolicyOptions
2279
2280
  'ignore-policy',
2280
2281
  'policy-path',
@@ -2379,6 +2380,7 @@ async function prepareTestConfig(paths, options) {
2379
2380
  const scan = (_a = options.scan) !== null && _a !== void 0 ? _a : 'resource-changes';
2380
2381
  const varFile = options['var-file'];
2381
2382
  const cloudContext = index_1.getFlag(options, 'cloud-context');
2383
+ const snykCloudEnvironment = index_1.getFlag(options, 'snyk-cloud-environment');
2382
2384
  const insecure = options.insecure;
2383
2385
  return {
2384
2386
  paths,
@@ -2395,6 +2397,7 @@ async function prepareTestConfig(paths, options) {
2395
2397
  varFile,
2396
2398
  depthDetection,
2397
2399
  cloudContext,
2400
+ snykCloudEnvironment,
2398
2401
  insecure,
2399
2402
  org,
2400
2403
  };
@@ -3093,6 +3096,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
3093
3096
  exports.formatSnykIacTestTestData = exports.formatTestData = void 0;
3094
3097
  const constants_1 = __webpack_require__(68620);
3095
3098
  const legacy_1 = __webpack_require__(34013);
3099
+ const utils_1 = __webpack_require__(9176);
3096
3100
  function formatTestData({ oldFormattedResults, iacOutputMeta: iacTestMeta, ignoresCount, }) {
3097
3101
  const resultsBySeverity = formatScanResultsNewOutput(oldFormattedResults);
3098
3102
  return {
@@ -3158,9 +3162,7 @@ function formatSnykIacTestTestData(snykIacTestScanResult, projectName, orgName)
3158
3162
  let contextSuppressedIssueCount;
3159
3163
  const suppressedResults = (_a = snykIacTestScanResult === null || snykIacTestScanResult === void 0 ? void 0 : snykIacTestScanResult.scanAnalytics) === null || _a === void 0 ? void 0 : _a.suppressedResults;
3160
3164
  if (suppressedResults) {
3161
- contextSuppressedIssueCount = Object.values(suppressedResults).reduce(function (count, resourcesForRuleId) {
3162
- return (count += resourcesForRuleId.length);
3163
- }, 0);
3165
+ contextSuppressedIssueCount = utils_1.countSuppressedIssues(suppressedResults);
3164
3166
  }
3165
3167
  return {
3166
3168
  resultsBySeverity,
@@ -3552,7 +3554,7 @@ exports.shouldLogUserMessages = shouldLogUserMessages;
3552
3554
  "use strict";
3553
3555
 
3554
3556
  Object.defineProperty(exports, "__esModule", ({ value: true }));
3555
- exports.maxLineWidth = exports.contentPadding = exports.colors = void 0;
3557
+ exports.countSuppressedIssues = exports.maxLineWidth = exports.contentPadding = exports.colors = void 0;
3556
3558
  const chalk_1 = __webpack_require__(32589);
3557
3559
  exports.colors = {
3558
3560
  severities: {
@@ -3571,6 +3573,11 @@ exports.contentPadding = ' '.repeat(2);
3571
3573
  exports.maxLineWidth = process.stdout.columns
3572
3574
  ? Math.min(process.stdout.columns, 80)
3573
3575
  : 80;
3576
+ exports.countSuppressedIssues = (suppressedIssues) => {
3577
+ return Object.values(suppressedIssues).reduce(function (count, resourcesForRuleId) {
3578
+ return (count += resourcesForRuleId.length);
3579
+ }, 0);
3580
+ };
3574
3581
 
3575
3582
 
3576
3583
  /***/ }),
@@ -4326,6 +4333,39 @@ function getWorkingDirectoryForPath(p) {
4326
4333
  exports.getWorkingDirectoryForPath = getWorkingDirectoryForPath;
4327
4334
 
4328
4335
 
4336
+ /***/ }),
4337
+
4338
+ /***/ 64321:
4339
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
4340
+
4341
+ "use strict";
4342
+
4343
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
4344
+ exports.getIacCloudContext = void 0;
4345
+ const utils_1 = __webpack_require__(9176);
4346
+ function getIacCloudContext(testConfig, testOutput) {
4347
+ var _a, _b;
4348
+ let iacCloudContext;
4349
+ if (testConfig.cloudContext) {
4350
+ iacCloudContext = 'cloud-context';
4351
+ }
4352
+ else if (testConfig.snykCloudEnvironment) {
4353
+ iacCloudContext = 'snyk-cloud-environment';
4354
+ }
4355
+ let iacCloudContextSuppressedIssuesCount = 0;
4356
+ const suppressedIssues = (_b = (_a = testOutput.results) === null || _a === void 0 ? void 0 : _a.scanAnalytics) === null || _b === void 0 ? void 0 : _b.suppressedResults;
4357
+ if (suppressedIssues) {
4358
+ iacCloudContextSuppressedIssuesCount = utils_1.countSuppressedIssues(suppressedIssues);
4359
+ }
4360
+ return {
4361
+ iacCloudContext,
4362
+ iacCloudContextCloudProvider: testConfig.cloudContext,
4363
+ iacCloudContextSuppressedIssuesCount,
4364
+ };
4365
+ }
4366
+ exports.getIacCloudContext = getIacCloudContext;
4367
+
4368
+
4329
4369
  /***/ }),
4330
4370
 
4331
4371
  /***/ 55098:
@@ -4411,8 +4451,9 @@ exports.addIacAnalytics = void 0;
4411
4451
  const constants_1 = __webpack_require__(64895);
4412
4452
  const analytics = __webpack_require__(82744);
4413
4453
  const iac_type_1 = __webpack_require__(55098);
4414
- function addIacAnalytics(testOutput) {
4415
- const iacAnalytics = computeIacAnalytics(testOutput);
4454
+ const iac_cloud_context_1 = __webpack_require__(64321);
4455
+ function addIacAnalytics(testConfig, testOutput) {
4456
+ const iacAnalytics = computeIacAnalytics(testConfig, testOutput);
4416
4457
  analytics.add('iac-type', iacAnalytics.iacType);
4417
4458
  analytics.add('packageManager', iacAnalytics.packageManager);
4418
4459
  analytics.add('iac-issues-count', iacAnalytics.iacIssuesCount);
@@ -4421,11 +4462,18 @@ function addIacAnalytics(testOutput) {
4421
4462
  analytics.add('iac-resources-count', iacAnalytics.iacResourcesCount);
4422
4463
  analytics.add('iac-error-codes', iacAnalytics.iacErrorCodes);
4423
4464
  analytics.add('iac-test-binary-version', iacAnalytics.iacTestBinaryVersion);
4465
+ // cloud context analytics
4466
+ if (iacAnalytics.iacCloudContext) {
4467
+ analytics.add('iac-cloud-context', iacAnalytics.iacCloudContext);
4468
+ analytics.add('iac-cloud-context-cloud-provider', iacAnalytics.iacCloudContextCloudProvider);
4469
+ analytics.add('iac-cloud-context-suppressed-issues-count', iacAnalytics.iacCloudContextSuppressedIssuesCount);
4470
+ }
4424
4471
  }
4425
4472
  exports.addIacAnalytics = addIacAnalytics;
4426
- function computeIacAnalytics(testOutput) {
4473
+ function computeIacAnalytics(testConfig, testOutput) {
4427
4474
  var _a, _b, _c, _d, _e, _f;
4428
4475
  const iacType = iac_type_1.getIacType(testOutput);
4476
+ const iacCloudContext = iac_cloud_context_1.getIacCloudContext(testConfig, testOutput);
4429
4477
  return {
4430
4478
  iacType,
4431
4479
  packageManager: Object.keys(iacType),
@@ -4435,6 +4483,8 @@ function computeIacAnalytics(testOutput) {
4435
4483
  iacResourcesCount: ((_e = (_d = testOutput.results) === null || _d === void 0 ? void 0 : _d.resources) === null || _e === void 0 ? void 0 : _e.length) || 0,
4436
4484
  iacErrorCodes: [...new Set((_f = testOutput.errors) === null || _f === void 0 ? void 0 : _f.map((error) => error.code))] || [],
4437
4485
  iacTestBinaryVersion: constants_1.policyEngineReleaseVersion,
4486
+ // iacRulesBundleVersion = ''; // TODO: Add when we have the rules bundle version
4487
+ ...iacCloudContext,
4438
4488
  };
4439
4489
  }
4440
4490
 
@@ -4523,8 +4573,8 @@ const local_cache_1 = __webpack_require__(68081);
4523
4573
  const analytics_1 = __webpack_require__(26507);
4524
4574
  async function test(testConfig) {
4525
4575
  const { policyEnginePath, rulesBundlePath } = await local_cache_1.initLocalCache(testConfig);
4526
- const testOutput = scan_1.scan(testConfig, policyEnginePath, rulesBundlePath);
4527
- analytics_1.addIacAnalytics(testOutput);
4576
+ const testOutput = await scan_1.scan(testConfig, policyEnginePath, rulesBundlePath);
4577
+ analytics_1.addIacAnalytics(testConfig, testOutput);
4528
4578
  return testOutput;
4529
4579
  }
4530
4580
  exports.test = test;
@@ -4772,12 +4822,12 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
4772
4822
  exports.getChecksum = exports.formatPolicyEngineFileName = exports.policyEngineVersion = void 0;
4773
4823
  const os = __webpack_require__(12087);
4774
4824
  const policyEngineChecksums = `
4775
- 057406a372f29f765b41b32f67414224595caf5ce4aa17619ee6e12e95cd6050 snyk-iac-test_0.34.1_Windows_arm64.exe
4776
- 1a37bb164198051ede0f45e3fcfabf3de4932c2ac4ef9f271514d921b287cb96 snyk-iac-test_0.34.1_Linux_x86_64
4777
- 316c911299558c66e38c38f5205fbac10cee2cffa3f34e20bb4785950964a957 snyk-iac-test_0.34.1_Darwin_arm64
4778
- 7e8ea9c57f4a846f39ffb3843db4c2dc9f164669a3ae8084c68b425039160264 snyk-iac-test_0.34.1_Windows_x86_64.exe
4779
- dcd933804997898aa40744d6e42a97b6990243a55f1396dcc9a6d6e1db5b534c snyk-iac-test_0.34.1_Linux_arm64
4780
- f15d4093f0f0d2ae573a61add594ad7481c2f57474543203d3e3e419ba04cd3b snyk-iac-test_0.34.1_Darwin_x86_64
4825
+ 04fe9c50afad4ab91815281930f142d17e4047d0187564fffa81d2a04e292915 snyk-iac-test_0.35.1_Windows_x86_64.exe
4826
+ 2876226d01d3b8c906bc1835d8f03ebb7b809b8a3bbce3e743d3301df86664b5 snyk-iac-test_0.35.1_Linux_x86_64
4827
+ 36dbb048fc79669a7ae4924079a44248eeed83a5e785fa3877bb275d28f7be42 snyk-iac-test_0.35.1_Darwin_arm64
4828
+ 4d08c4fe6027685681171903669372323f6018083bcc67ce804fd4a939ed4859 snyk-iac-test_0.35.1_Windows_arm64.exe
4829
+ 4da012c52785749e24695d8b7f70782697afb06cc0125b6e3d062ba19d65b479 snyk-iac-test_0.35.1_Linux_arm64
4830
+ d6e017549e2806df32ecd61052d5f7489cca213a437af68d7e982b6200f8f81a snyk-iac-test_0.35.1_Darwin_x86_64
4781
4831
  `;
4782
4832
  exports.policyEngineVersion = getPolicyEngineVersion();
4783
4833
  function formatPolicyEngineFileName(releaseVersion) {
@@ -5459,28 +5509,29 @@ const analytics_1 = __webpack_require__(82744);
5459
5509
  const env_paths_1 = __webpack_require__(21766);
5460
5510
  const debug = newDebug('snyk-iac');
5461
5511
  exports.systemCachePath = (_a = config_1.default.CACHE_PATH) !== null && _a !== void 0 ? _a : env_paths_1.default('snyk').cache;
5462
- function scan(options, policyEnginePath, rulesBundlePath) {
5463
- const { tempOutput: outputPath, tempDir: tempDirPath, tempPolicy: tempPolicyPath, } = createTemporaryFiles(options);
5512
+ async function scan(options, policyEnginePath, rulesBundlePath) {
5513
+ const { tempOutput: outputPath, tempDir: tempDirPath, tempPolicy: tempPolicyPath, } = await createTemporaryFiles(options);
5464
5514
  try {
5465
- return scanWithConfig(options, policyEnginePath, rulesBundlePath, outputPath, tempPolicyPath);
5515
+ return await scanWithConfig(options, policyEnginePath, rulesBundlePath, outputPath, tempPolicyPath);
5466
5516
  }
5467
5517
  finally {
5468
- deleteTemporaryFiles(tempDirPath);
5518
+ await deleteTemporaryFiles(tempDirPath);
5469
5519
  }
5470
5520
  }
5471
5521
  exports.scan = scan;
5472
- function scanWithConfig(options, policyEnginePath, rulesBundlePath, outputPath, policyPath) {
5522
+ async function scanWithConfig(options, policyEnginePath, rulesBundlePath, outputPath, policyPath) {
5473
5523
  const env = { ...process.env };
5474
- env['SNYK_API_URL'] = getApiUrl();
5475
- env['SNYK_API_TOKEN'] = getApiToken();
5524
+ env['SNYK_IAC_TEST_API_REST_URL'] =
5525
+ process.env['SNYK_IAC_TEST_API_REST_URL'] || getApiUrl();
5526
+ env['SNYK_IAC_TEST_API_REST_TOKEN'] =
5527
+ process.env['SNYK_IAC_TEST_API_REST_TOKEN'] || getApiToken();
5528
+ env['SNYK_IAC_TEST_API_V1_URL'] =
5529
+ process.env['SNYK_IAC_TEST_API_V1_URL'] || getApiUrl();
5530
+ env['SNYK_IAC_TEST_API_V1_TOKEN'] =
5531
+ process.env['SNYK_IAC_TEST_API_V1_TOKEN'] || getApiToken();
5476
5532
  const args = processFlags(options, rulesBundlePath, outputPath, policyPath);
5477
5533
  args.push(...options.paths);
5478
- const child = childProcess.spawnSync(policyEnginePath, args, {
5479
- encoding: 'utf-8',
5480
- stdio: 'pipe',
5481
- env: env,
5482
- maxBuffer: 1024 * 1024 * 10,
5483
- });
5534
+ const child = await spawn(policyEnginePath, args, env);
5484
5535
  debug('policy engine standard error:\n%s', '\n' + child.stderr);
5485
5536
  if (child.status && child.status !== 0) {
5486
5537
  throw new ScanError(`invalid exit status: ${child.status}`);
@@ -5488,15 +5539,13 @@ function scanWithConfig(options, policyEnginePath, rulesBundlePath, outputPath,
5488
5539
  if (child.error) {
5489
5540
  throw new ScanError(`spawning process: ${child.error}`);
5490
5541
  }
5491
- let snykIacTestOutput, parsedSnykIacTestOutput;
5492
5542
  try {
5493
- snykIacTestOutput = fs.readFileSync(outputPath, 'utf-8');
5494
- parsedSnykIacTestOutput = JSON.parse(snykIacTestOutput);
5543
+ const output = await readFile(outputPath);
5544
+ return results_1.mapSnykIacTestOutputToTestOutput(JSON.parse(output));
5495
5545
  }
5496
5546
  catch (e) {
5497
5547
  throw new ScanError(`invalid output encoding: ${e}`);
5498
5548
  }
5499
- return results_1.mapSnykIacTestOutputToTestOutput(parsedSnykIacTestOutput);
5500
5549
  }
5501
5550
  function processFlags(options, rulesBundlePath, outputPath, policyPath) {
5502
5551
  const flags = [
@@ -5535,6 +5584,9 @@ function processFlags(options, rulesBundlePath, outputPath, policyPath) {
5535
5584
  if (options.cloudContext) {
5536
5585
  flags.push('-cloud-context', options.cloudContext);
5537
5586
  }
5587
+ if (options.snykCloudEnvironment) {
5588
+ flags.push('-snyk-cloud-environment', options.snykCloudEnvironment);
5589
+ }
5538
5590
  if (options.insecure) {
5539
5591
  flags.push('-http-tls-skip-verify');
5540
5592
  }
@@ -5543,33 +5595,123 @@ function processFlags(options, rulesBundlePath, outputPath, policyPath) {
5543
5595
  }
5544
5596
  return flags;
5545
5597
  }
5546
- function createTemporaryFiles(options) {
5598
+ async function createTemporaryFiles(options) {
5547
5599
  try {
5548
- const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'snyk-'));
5600
+ const tempDir = await mkdtemp(path.join(os.tmpdir(), 'snyk-'));
5549
5601
  const tempOutput = path.join(tempDir, 'output.json');
5550
5602
  const tempPolicy = path.join(tempDir, '.snyk');
5551
- fs.writeFileSync(tempOutput, '');
5552
- fs.writeFileSync(tempPolicy, options.policy || '');
5603
+ await writeFile(tempPolicy, options.policy || '');
5553
5604
  return { tempOutput, tempDir, tempPolicy };
5554
5605
  }
5555
5606
  catch (e) {
5556
5607
  throw new ScanError(`unable to create config/output file: ${e}`);
5557
5608
  }
5558
5609
  }
5559
- function deleteTemporaryFiles(tempDirPath) {
5610
+ async function deleteTemporaryFiles(tempDirPath) {
5560
5611
  try {
5561
- rimraf.sync(tempDirPath);
5612
+ await remove(tempDirPath);
5562
5613
  }
5563
5614
  catch (e) {
5564
5615
  debug('unable to delete temporary directory', e);
5565
5616
  }
5566
5617
  }
5618
+ async function mkdtemp(path) {
5619
+ return new Promise((resolve, reject) => {
5620
+ fs.mkdtemp(path, (err, folder) => {
5621
+ if (err) {
5622
+ reject(err);
5623
+ }
5624
+ else {
5625
+ resolve(folder);
5626
+ }
5627
+ });
5628
+ });
5629
+ }
5630
+ async function writeFile(path, content) {
5631
+ return new Promise((resolve, reject) => {
5632
+ fs.writeFile(path, content, (err) => {
5633
+ if (err) {
5634
+ reject(err);
5635
+ }
5636
+ else {
5637
+ resolve();
5638
+ }
5639
+ });
5640
+ });
5641
+ }
5642
+ async function readFile(path) {
5643
+ return new Promise((resolve, reject) => {
5644
+ fs.readFile(path, 'utf-8', (err, content) => {
5645
+ if (err) {
5646
+ reject(err);
5647
+ }
5648
+ else {
5649
+ resolve(content);
5650
+ }
5651
+ });
5652
+ });
5653
+ }
5654
+ async function remove(path) {
5655
+ return new Promise((resolve, reject) => {
5656
+ rimraf(path, (err) => {
5657
+ if (err) {
5658
+ reject(err);
5659
+ }
5660
+ else {
5661
+ resolve();
5662
+ }
5663
+ });
5664
+ });
5665
+ }
5567
5666
  function getApiUrl() {
5568
5667
  return config_1.default.API_REST_URL;
5569
5668
  }
5570
5669
  function getApiToken() {
5571
5670
  return api_token_1.api() || '';
5572
5671
  }
5672
+ async function spawn(path, args, env) {
5673
+ return new Promise((resolve) => {
5674
+ const child = childProcess.spawn(path, args, {
5675
+ stdio: 'pipe',
5676
+ env: env,
5677
+ });
5678
+ const stdout = [];
5679
+ child.stdout.on('data', (data) => {
5680
+ stdout.push(Buffer.from(data));
5681
+ });
5682
+ const stderr = [];
5683
+ child.stderr.on('data', (data) => {
5684
+ stderr.push(Buffer.from(data));
5685
+ });
5686
+ // If 'error' is emitted, 'exit' might or might not be emitted, too. The
5687
+ // 'returned' flag prevents the promise from being resolved twice if an
5688
+ // error occurs.
5689
+ let returned = false;
5690
+ child.on('exit', (status) => {
5691
+ if (returned) {
5692
+ return;
5693
+ }
5694
+ returned = true;
5695
+ resolve({
5696
+ stdout: Buffer.concat(stdout),
5697
+ stderr: Buffer.concat(stderr),
5698
+ status,
5699
+ });
5700
+ });
5701
+ child.on('error', (error) => {
5702
+ if (returned) {
5703
+ return;
5704
+ }
5705
+ returned = true;
5706
+ resolve({
5707
+ stdout: Buffer.concat(stdout),
5708
+ stderr: Buffer.concat(stderr),
5709
+ status: null,
5710
+ error,
5711
+ });
5712
+ });
5713
+ });
5714
+ }
5573
5715
  class ScanError extends errors_1.CustomError {
5574
5716
  constructor(message) {
5575
5717
  super(message);