snyk 1.771.0 → 1.772.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.
@@ -15208,7 +15208,8 @@ exports.getImageSize = void 0;
15208
15208
  const get_manifest_1 = __webpack_require__(32603);
15209
15209
  async function getImageSize(registryBase, repo, tag, username, password, options = {}) {
15210
15210
  const manifest = await get_manifest_1.getManifest(registryBase, repo, tag, username, password, options);
15211
- return manifest.layers.reduce((size, layerConfig) => size + layerConfig.size, 0);
15211
+ const layers = manifest.layers || [];
15212
+ return layers.reduce((size, layerConfig) => size + layerConfig.size, 0);
15212
15213
  }
15213
15214
  exports.getImageSize = getImageSize;
15214
15215
  //# sourceMappingURL=get-image-size.js.map
@@ -15266,10 +15267,7 @@ const needle_1 = __webpack_require__(48360);
15266
15267
  */
15267
15268
  async function getManifest(registryBase, repo, tag, username, password, options = {}, platform) {
15268
15269
  var _a;
15269
- let accept = `${(_a = options.acceptManifest) !== null && _a !== void 0 ? _a : contentTypes.MANIFEST_V2}`;
15270
- if (shouldAcceptManifestList(tag, platform)) {
15271
- accept += `, ${contentTypes.MANIFEST_LIST_V2}`;
15272
- }
15270
+ const accept = (_a = options.acceptManifest) !== null && _a !== void 0 ? _a : `${contentTypes.MANIFEST_V2}, ${contentTypes.MANIFEST_LIST_V2}`;
15273
15271
  const endpoint = `/${repo}/manifests/${tag}`;
15274
15272
  const manifestResponse = await registry_call_1.registryV2Call(registryBase, endpoint, accept, username, password, options);
15275
15273
  const contentType = manifestResponse.headers["content-type"];
@@ -15298,14 +15296,6 @@ function getManifestByOsAndArch(platformManifest, os, architecture) {
15298
15296
  return platformManifest.find(manifest => manifest.platform.os === os &&
15299
15297
  manifest.platform.architecture === architecture);
15300
15298
  }
15301
- // Accept manifest list content type in case that:
15302
- // - Manifest digest was requested - if it's a manifest list digest, a list is returned and some CRs are strict
15303
- // about the returned content type being different from the requested one (gcr)
15304
- // - Specific platform was requested, therefore we need to get the list in order to find the specific platform
15305
- // (by default the CR will return linux/amd64)
15306
- function shouldAcceptManifestList(tag, platform) {
15307
- return tag.includes(":") || !!platform;
15308
- }
15309
15299
  //# sourceMappingURL=get-manifest.js.map
15310
15300
 
15311
15301
  /***/ }),
@@ -15352,7 +15342,7 @@ exports.getTags = getTags;
15352
15342
  "use strict";
15353
15343
 
15354
15344
  Object.defineProperty(exports, "__esModule", ({ value: true }));
15355
- exports.types = exports.getTags = exports.getRepos = exports.getManifest = exports.getLayer = exports.getImageSize = exports.getImageConfig = exports.getAuthTokenForEndpoint = exports.checkSupport = void 0;
15345
+ exports.types = exports.registryCall = exports.getTags = exports.getRepos = exports.getManifest = exports.getLayer = exports.getImageSize = exports.getImageConfig = exports.getAuthTokenForEndpoint = exports.checkSupport = void 0;
15356
15346
  const check_support_1 = __webpack_require__(87315);
15357
15347
  Object.defineProperty(exports, "checkSupport", ({ enumerable: true, get: function () { return check_support_1.checkSupport; } }));
15358
15348
  const get_auth_token_for_endpoint_1 = __webpack_require__(80290);
@@ -15369,6 +15359,8 @@ const get_repos_1 = __webpack_require__(73905);
15369
15359
  Object.defineProperty(exports, "getRepos", ({ enumerable: true, get: function () { return get_repos_1.getRepos; } }));
15370
15360
  const get_tags_1 = __webpack_require__(80353);
15371
15361
  Object.defineProperty(exports, "getTags", ({ enumerable: true, get: function () { return get_tags_1.getTags; } }));
15362
+ const registry_call_1 = __webpack_require__(15271);
15363
+ Object.defineProperty(exports, "registryCall", ({ enumerable: true, get: function () { return registry_call_1.registryCall; } }));
15372
15364
  const types = __webpack_require__(47235);
15373
15365
  exports.types = types;
15374
15366
  //# sourceMappingURL=index.js.map
@@ -15478,7 +15470,7 @@ class NeedleWrapperException extends Error {
15478
15470
  "use strict";
15479
15471
 
15480
15472
  Object.defineProperty(exports, "__esModule", ({ value: true }));
15481
- exports.buildUnauthenticatedV2RequestConfig = exports.parseChallengeHeaders = exports.getToken = exports.paginatedV2Call = exports.registryV2Call = void 0;
15473
+ exports.buildUnauthenticatedV2RequestConfig = exports.parseChallengeHeaders = exports.getToken = exports.paginatedV2Call = exports.registryCall = exports.registryV2Call = void 0;
15482
15474
  const parseLink = __webpack_require__(28490);
15483
15475
  const url = __webpack_require__(78835);
15484
15476
  const needle_1 = __webpack_require__(48360);
@@ -15515,6 +15507,47 @@ async function registryV2Call(registryBase, endpoint, accept, username, password
15515
15507
  }
15516
15508
  }
15517
15509
  exports.registryV2Call = registryV2Call;
15510
+ /**
15511
+ * WARNING!!!
15512
+ *
15513
+ * This function was created for a very specific usecase (https://snyksec.atlassian.net/browse/MAGMA-1262)
15514
+ * It uses the existing mechanism of obtaining a token for authenticating, but can be used to hit any API endpoint,
15515
+ * and not necessarily a Docker V2 endpoint.
15516
+ * This is clearly an abuse of a library that's named after the v2 API, and this function should be considered a tech debt.
15517
+ * Once it's no longer necessary, it is advised that this function is removed.
15518
+ *
15519
+ */
15520
+ async function registryCall(uri, username, password, reqOptions = {}) {
15521
+ const reqConfig = applyRequestOptions({ uri: `https://${uri}` }, reqOptions);
15522
+ try {
15523
+ return await needle_1.needleWrapper(reqConfig, MAX_RETRIES);
15524
+ }
15525
+ catch (err) {
15526
+ if (err.statusCode === 401) {
15527
+ if (!username || !password) {
15528
+ // Supply and empty username and password if no credentials
15529
+ // are provided. These might be added later by a broker client.
15530
+ username = username ? username : "";
15531
+ password = password ? password : "";
15532
+ }
15533
+ const authConfig = await setAuthConfig("", err, reqConfig, username, password, reqOptions);
15534
+ try {
15535
+ return await needle_1.needleWrapper(authConfig, MAX_RETRIES);
15536
+ }
15537
+ catch (err) {
15538
+ if (err.statusCode === 307 || err.statusCode === 302) {
15539
+ return await handleRedirect(err, reqConfig);
15540
+ }
15541
+ throw err;
15542
+ }
15543
+ }
15544
+ if (err.statusCode === 307 || err.statusCode === 302) {
15545
+ return await handleRedirect(err, reqConfig);
15546
+ }
15547
+ throw err;
15548
+ }
15549
+ }
15550
+ exports.registryCall = registryCall;
15518
15551
  async function paginatedV2Call(registryBase, accept, username, password, endpoint, key, pageSize = 1000, maxPages = Number.MAX_SAFE_INTEGER, reqOptions = {}) {
15519
15552
  const result = [];
15520
15553
  let pageEndpoint = `${endpoint}?n=${pageSize}`;
@@ -15552,12 +15585,22 @@ async function getToken(registryBase, authBase, service, scope, username, passwo
15552
15585
  return body.token || body.access_token;
15553
15586
  }
15554
15587
  exports.getToken = getToken;
15555
- function parseChallengeHeaders(challangeHeaders) {
15556
- const headersMap = challangeHeaders.split(",").reduce((map, entry) => {
15588
+ function parseChallengeHeaders(challengeHeaders) {
15589
+ const headersMap = {};
15590
+ const headerSplit = challengeHeaders.split(",");
15591
+ for (let i = 0; i < headerSplit.length; i++) {
15592
+ const entry = headerSplit[i];
15593
+ if (!entry.includes("=") && i > 0) {
15594
+ // we'll get here in case a value includes a comma. we want to concat what's after the comma to the previous value
15595
+ headerSplit[i - 1] += `,${entry}`;
15596
+ headerSplit.splice(i, 1);
15597
+ i--;
15598
+ }
15599
+ }
15600
+ headerSplit.forEach(entry => {
15557
15601
  const [key, value] = entry.split("=");
15558
- map[key] = JSON.parse(value);
15559
- return map;
15560
- }, {});
15602
+ headersMap[key] = JSON.parse(value);
15603
+ });
15561
15604
  return [headersMap[BEARER_REALM], headersMap.service, headersMap.scope];
15562
15605
  }
15563
15606
  exports.parseChallengeHeaders = parseChallengeHeaders;