519.index.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. "use strict";
  2. exports.id = 519;
  3. exports.ids = [519];
  4. exports.modules = {
  5. /***/ 41519:
  6. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7. Object.defineProperty(exports, "__esModule", ({ value: true }));
  8. exports.addIacDriftAnalytics = exports.performanceAnalyticsObject = exports.addIacAnalytics = void 0;
  9. const types_1 = __webpack_require__(94820);
  10. const analytics = __webpack_require__(82744);
  11. const file_utils_1 = __webpack_require__(45281);
  12. const driftctl_1 = __webpack_require__(3659);
  13. function addIacAnalytics(formattedResults, opts) {
  14. let totalIssuesCount = 0;
  15. const customRulesIdsFoundInIssues = {};
  16. let issuesFromCustomRulesCount = 0;
  17. const projectTypeAnalytics = {};
  18. const packageManagers = Array();
  19. formattedResults.forEach((res) => {
  20. var _a;
  21. totalIssuesCount =
  22. (totalIssuesCount || 0) + res.result.cloudConfigResults.length;
  23. const projectType = res.packageManager;
  24. packageManagers.push(projectType);
  25. projectTypeAnalytics[projectType] = (_a = projectTypeAnalytics[projectType]) !== null && _a !== void 0 ? _a : {
  26. count: 0,
  27. };
  28. projectTypeAnalytics[projectType]['count']++;
  29. res.result.cloudConfigResults.forEach((policy) => {
  30. projectTypeAnalytics[projectType][policy.severity] =
  31. (projectTypeAnalytics[projectType][policy.severity] || 0) + 1;
  32. if (policy.isGeneratedByCustomRule) {
  33. issuesFromCustomRulesCount++;
  34. customRulesIdsFoundInIssues[policy.publicId] = true;
  35. }
  36. });
  37. });
  38. const uniqueCustomRulesCount = Object.keys(customRulesIdsFoundInIssues).length;
  39. analytics.add('packageManager', Array.from(new Set(packageManagers)));
  40. analytics.add('iac-issues-count', totalIssuesCount);
  41. analytics.add('iac-ignored-issues-count', opts.ignoredIssuesCount);
  42. analytics.add('iac-type', projectTypeAnalytics);
  43. analytics.add('iac-metrics', exports.performanceAnalyticsObject);
  44. analytics.add('iac-test-count', formattedResults.length); // TODO: remove this once we all analytics use iac-files-count
  45. analytics.add('iac-files-count', formattedResults.length);
  46. analytics.add('iac-local-custom-rules', opts.rulesOrigin === types_1.RulesOrigin.Local);
  47. analytics.add('iac-remote-custom-rules', opts.rulesOrigin === types_1.RulesOrigin.Remote);
  48. analytics.add('iac-custom-rules-issues-count', issuesFromCustomRulesCount);
  49. analytics.add('iac-custom-rules-checksum', file_utils_1.computeCustomRulesBundleChecksum());
  50. analytics.add('iac-custom-rules-coverage-count', uniqueCustomRulesCount);
  51. }
  52. exports.addIacAnalytics = addIacAnalytics;
  53. exports.performanceAnalyticsObject = {
  54. [types_1.PerformanceAnalyticsKey.InitLocalCache]: null,
  55. [types_1.PerformanceAnalyticsKey.FileLoading]: null,
  56. [types_1.PerformanceAnalyticsKey.FileParsing]: null,
  57. [types_1.PerformanceAnalyticsKey.FileScanning]: null,
  58. [types_1.PerformanceAnalyticsKey.OrgSettings]: null,
  59. [types_1.PerformanceAnalyticsKey.CustomSeverities]: null,
  60. [types_1.PerformanceAnalyticsKey.ResultFormatting]: null,
  61. [types_1.PerformanceAnalyticsKey.UsageTracking]: null,
  62. [types_1.PerformanceAnalyticsKey.CacheCleanup]: null,
  63. [types_1.PerformanceAnalyticsKey.Total]: null,
  64. };
  65. function addIacDriftAnalytics(analysis, options) {
  66. analytics.add('iac-drift-coverage', analysis.coverage);
  67. analytics.add('iac-drift-total-resources', analysis.summary.total_resources);
  68. analytics.add('iac-drift-total-unmanaged', analysis.summary.total_unmanaged);
  69. analytics.add('iac-drift-total-managed', analysis.summary.total_managed);
  70. analytics.add('iac-drift-total-missing', analysis.summary.total_missing);
  71. analytics.add('iac-drift-total-changed', analysis.summary.total_changed);
  72. analytics.add('iac-drift-iac-source-count', analysis.summary.total_iac_source_count);
  73. analytics.add('iac-drift-provider-name', analysis.provider_name);
  74. analytics.add('iac-drift-provider-version', analysis.provider_version);
  75. analytics.add('iac-drift-version', driftctl_1.driftctlVersion);
  76. analytics.add('iac-drift-scan-duration', analysis.scan_duration);
  77. let scope = 'all';
  78. if (options['only-managed']) {
  79. scope = 'managed';
  80. }
  81. else if (options['only-unmanaged']) {
  82. scope = 'unmanaged';
  83. }
  84. analytics.add('iac-drift-scan-scope', scope);
  85. }
  86. exports.addIacDriftAnalytics = addIacDriftAnalytics;
  87. /***/ }),
  88. /***/ 45281:
  89. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  90. Object.defineProperty(exports, "__esModule", ({ value: true }));
  91. exports.makeFileAndDirectoryGenerator = exports.computeCustomRulesBundleChecksum = exports.isValidBundle = exports.extractBundle = exports.createIacDir = void 0;
  92. const fs = __webpack_require__(35747);
  93. const tar = __webpack_require__(97998);
  94. const path = __webpack_require__(85622);
  95. const crypto = __webpack_require__(76417);
  96. const local_cache_1 = __webpack_require__(50089);
  97. const oci_pull_1 = __webpack_require__(166);
  98. const fs_1 = __webpack_require__(35747);
  99. const path_1 = __webpack_require__(85622);
  100. function hashData(s) {
  101. const hashedData = crypto
  102. .createHash('sha1')
  103. .update(s)
  104. .digest('hex');
  105. return hashedData;
  106. }
  107. function createIacDir() {
  108. // this path will be able to be customised by the user in the future
  109. const iacPath = path.join(local_cache_1.LOCAL_POLICY_ENGINE_DIR);
  110. try {
  111. if (!fs.existsSync(iacPath)) {
  112. fs.mkdirSync(iacPath, '700');
  113. }
  114. fs.accessSync(iacPath, fs.constants.W_OK);
  115. }
  116. catch {
  117. throw new local_cache_1.FailedToInitLocalCacheError();
  118. }
  119. }
  120. exports.createIacDir = createIacDir;
  121. function extractBundle(response) {
  122. return new Promise((resolve, reject) => {
  123. response
  124. .on('error', reject)
  125. .pipe(tar.x({
  126. C: path.join(local_cache_1.LOCAL_POLICY_ENGINE_DIR),
  127. }))
  128. .on('finish', resolve)
  129. .on('error', reject);
  130. });
  131. }
  132. exports.extractBundle = extractBundle;
  133. function isValidBundle(wasmPath, dataPath) {
  134. try {
  135. // verify that the correct files were generated, since this is user input
  136. return !(!fs.existsSync(wasmPath) || !fs.existsSync(dataPath));
  137. }
  138. catch {
  139. return false;
  140. }
  141. }
  142. exports.isValidBundle = isValidBundle;
  143. function computeCustomRulesBundleChecksum() {
  144. try {
  145. const customRulesPolicyWasmPath = path.join(local_cache_1.LOCAL_POLICY_ENGINE_DIR, oci_pull_1.CUSTOM_RULES_TARBALL);
  146. // if bundle is not configured we don't want to include the checksum
  147. if (!fs.existsSync(customRulesPolicyWasmPath)) {
  148. return;
  149. }
  150. const policyWasm = fs.readFileSync(customRulesPolicyWasmPath, 'utf8');
  151. return hashData(policyWasm);
  152. }
  153. catch (err) {
  154. return;
  155. }
  156. }
  157. exports.computeCustomRulesBundleChecksum = computeCustomRulesBundleChecksum;
  158. /**
  159. * makeFileAndDirectoryGenerator is a generator function that helps walking the directory and file structure of this pathToScan
  160. * @param root
  161. * @param maxDepth? - An optional `maxDepth` argument can be provided to limit how deep in the file tree the search will go.
  162. * @returns {Generator<object>} - a generator which yields an object with directories or paths for the path to scan
  163. */
  164. // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
  165. function* makeFileAndDirectoryGenerator(root = '.', maxDepth) {
  166. function* generatorHelper(pathToScan, currentDepth) {
  167. {
  168. yield { directory: pathToScan };
  169. }
  170. if (maxDepth !== currentDepth) {
  171. for (const dirent of fs_1.readdirSync(pathToScan, { withFileTypes: true })) {
  172. if (dirent.isDirectory() &&
  173. fs.readdirSync(path_1.join(pathToScan, dirent.name)).length !== 0) {
  174. yield* generatorHelper(path_1.join(pathToScan, dirent.name), currentDepth + 1);
  175. }
  176. else if (dirent.isFile()) {
  177. yield {
  178. file: {
  179. dir: pathToScan,
  180. fileName: path_1.join(pathToScan, dirent.name),
  181. },
  182. };
  183. }
  184. }
  185. }
  186. }
  187. yield* generatorHelper(root, 0);
  188. }
  189. exports.makeFileAndDirectoryGenerator = makeFileAndDirectoryGenerator;
  190. /***/ }),
  191. /***/ 50089:
  192. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  193. Object.defineProperty(exports, "__esModule", ({ value: true }));
  194. exports.InvalidCustomRulesPath = exports.InvalidCustomRules = exports.FailedToExtractCustomRulesError = exports.FailedToDownloadRulesError = exports.FailedToInitLocalCacheError = exports.cleanLocalCache = exports.initLocalCache = exports.getLocalCachePath = exports.assertNever = exports.CUSTOM_POLICY_ENGINE_WASM_PATH = exports.LOCAL_POLICY_ENGINE_DIR = void 0;
  195. const path = __webpack_require__(85622);
  196. const fs = __webpack_require__(35747);
  197. const types_1 = __webpack_require__(94820);
  198. const rimraf = __webpack_require__(50984);
  199. const file_utils_1 = __webpack_require__(45281);
  200. const Debug = __webpack_require__(15158);
  201. const errors_1 = __webpack_require__(55191);
  202. const analytics = __webpack_require__(82744);
  203. const error_utils_1 = __webpack_require__(36401);
  204. const config_1 = __webpack_require__(25425);
  205. const request_1 = __webpack_require__(1552);
  206. const debug = Debug('iac-local-cache');
  207. exports.LOCAL_POLICY_ENGINE_DIR = '.iac-data';
  208. const KUBERNETES_POLICY_ENGINE_WASM_PATH = path.join(exports.LOCAL_POLICY_ENGINE_DIR, 'k8s_policy.wasm');
  209. const KUBERNETES_POLICY_ENGINE_DATA_PATH = path.join(exports.LOCAL_POLICY_ENGINE_DIR, 'k8s_data.json');
  210. const TERRAFORM_POLICY_ENGINE_WASM_PATH = path.join(exports.LOCAL_POLICY_ENGINE_DIR, 'tf_policy.wasm');
  211. const TERRAFORM_POLICY_ENGINE_DATA_PATH = path.join(exports.LOCAL_POLICY_ENGINE_DIR, 'tf_data.json');
  212. const CLOUDFORMATION_POLICY_ENGINE_WASM_PATH = path.join(exports.LOCAL_POLICY_ENGINE_DIR, 'cloudformation_policy.wasm');
  213. const CLOUDFORMATION_POLICY_ENGINE_DATA_PATH = path.join(exports.LOCAL_POLICY_ENGINE_DIR, 'cloudformation_data.json');
  214. const ARM_POLICY_ENGINE_WASM_PATH = path.join(exports.LOCAL_POLICY_ENGINE_DIR, 'arm_policy.wasm');
  215. const ARM_POLICY_ENGINE_DATA_PATH = path.join(exports.LOCAL_POLICY_ENGINE_DIR, 'arm_data.json');
  216. // NOTE: The filenames used for the custom policy bundles match those output
  217. // by the `opa` CLI tool, which is why they are very generic.
  218. exports.CUSTOM_POLICY_ENGINE_WASM_PATH = path.join(exports.LOCAL_POLICY_ENGINE_DIR, 'policy.wasm');
  219. const CUSTOM_POLICY_ENGINE_DATA_PATH = path.join(exports.LOCAL_POLICY_ENGINE_DIR, 'data.json');
  220. function assertNever(value) {
  221. throw new Error(`Unhandled discriminated union member: ${JSON.stringify(value)}`);
  222. }
  223. exports.assertNever = assertNever;
  224. function getLocalCachePath(engineType) {
  225. switch (engineType) {
  226. case types_1.EngineType.Kubernetes:
  227. return [
  228. `${process.cwd()}/${KUBERNETES_POLICY_ENGINE_WASM_PATH}`,
  229. `${process.cwd()}/${KUBERNETES_POLICY_ENGINE_DATA_PATH}`,
  230. ];
  231. case types_1.EngineType.Terraform:
  232. return [
  233. `${process.cwd()}/${TERRAFORM_POLICY_ENGINE_WASM_PATH}`,
  234. `${process.cwd()}/${TERRAFORM_POLICY_ENGINE_DATA_PATH}`,
  235. ];
  236. case types_1.EngineType.CloudFormation:
  237. return [
  238. `${process.cwd()}/${CLOUDFORMATION_POLICY_ENGINE_WASM_PATH}`,
  239. `${process.cwd()}/${CLOUDFORMATION_POLICY_ENGINE_DATA_PATH}`,
  240. ];
  241. case types_1.EngineType.ARM:
  242. return [
  243. `${process.cwd()}/${ARM_POLICY_ENGINE_WASM_PATH}`,
  244. `${process.cwd()}/${ARM_POLICY_ENGINE_DATA_PATH}`,
  245. ];
  246. case types_1.EngineType.Custom:
  247. return [
  248. `${process.cwd()}/${exports.CUSTOM_POLICY_ENGINE_WASM_PATH}`,
  249. `${process.cwd()}/${CUSTOM_POLICY_ENGINE_DATA_PATH}`,
  250. ];
  251. default:
  252. assertNever(engineType);
  253. }
  254. }
  255. exports.getLocalCachePath = getLocalCachePath;
  256. async function initLocalCache({ customRulesPath, } = {}) {
  257. try {
  258. file_utils_1.createIacDir();
  259. }
  260. catch (e) {
  261. throw new FailedToInitLocalCacheError();
  262. }
  263. // Attempt to extract the custom rules from the path provided.
  264. if (customRulesPath) {
  265. if (!fs.existsSync(customRulesPath)) {
  266. throw new InvalidCustomRulesPath(customRulesPath);
  267. }
  268. try {
  269. const response = fs.createReadStream(customRulesPath);
  270. await file_utils_1.extractBundle(response);
  271. }
  272. catch (e) {
  273. throw new FailedToExtractCustomRulesError(customRulesPath);
  274. }
  275. if (!file_utils_1.isValidBundle(exports.CUSTOM_POLICY_ENGINE_WASM_PATH, CUSTOM_POLICY_ENGINE_DATA_PATH)) {
  276. throw new InvalidCustomRules(customRulesPath);
  277. }
  278. }
  279. // IAC_BUNDLE_PATH is a developer setting that is not useful to most users. It
  280. // is not a replacement for custom rules.
  281. if (config_1.default.IAC_BUNDLE_PATH) {
  282. const stream = fs.createReadStream(config_1.default.IAC_BUNDLE_PATH);
  283. await file_utils_1.extractBundle(stream);
  284. return;
  285. }
  286. // We extract the Snyk rules after the custom rules to ensure our files
  287. // always overwrite whatever might be there.
  288. try {
  289. const BUNDLE_URL = 'https://static.snyk.io/cli/wasm/bundle.tar.gz';
  290. const response = await request_1.streamRequest({
  291. method: 'get',
  292. url: BUNDLE_URL,
  293. body: null,
  294. headers: {},
  295. });
  296. await file_utils_1.extractBundle(response);
  297. }
  298. catch (e) {
  299. throw new FailedToDownloadRulesError();
  300. }
  301. }
  302. exports.initLocalCache = initLocalCache;
  303. function cleanLocalCache() {
  304. // path to delete is hardcoded for now
  305. const iacPath = path.join(`${process.cwd()}`, exports.LOCAL_POLICY_ENGINE_DIR);
  306. try {
  307. // when we support Node version >= 12.10.0 , we can replace rimraf
  308. // with the native fs.rmdirSync(path, {recursive: true})
  309. rimraf.sync(iacPath);
  310. }
  311. catch (e) {
  312. const err = new FailedToCleanLocalCacheError();
  313. analytics.add('error-code', err.code);
  314. debug('The local cache directory could not be deleted');
  315. }
  316. }
  317. exports.cleanLocalCache = cleanLocalCache;
  318. class FailedToInitLocalCacheError extends errors_1.CustomError {
  319. constructor(message) {
  320. super(message || 'Failed to initialize local cache');
  321. this.code = types_1.IaCErrorCodes.FailedToInitLocalCacheError;
  322. this.strCode = error_utils_1.getErrorStringCode(this.code);
  323. this.userMessage =
  324. 'We were unable to create a local directory to store the test assets, please ensure that the current working directory is writable';
  325. }
  326. }
  327. exports.FailedToInitLocalCacheError = FailedToInitLocalCacheError;
  328. class FailedToDownloadRulesError extends errors_1.CustomError {
  329. constructor(message) {
  330. super(message || 'Failed to download policies');
  331. this.code = types_1.IaCErrorCodes.FailedToDownloadRulesError;
  332. this.strCode = error_utils_1.getErrorStringCode(this.code);
  333. this.userMessage =
  334. 'We were unable to download the security rules, please ensure the network can access https://static.snyk.io';
  335. }
  336. }
  337. exports.FailedToDownloadRulesError = FailedToDownloadRulesError;
  338. class FailedToExtractCustomRulesError extends errors_1.CustomError {
  339. constructor(path, message) {
  340. super(message || 'Failed to download policies');
  341. this.code = types_1.IaCErrorCodes.FailedToExtractCustomRulesError;
  342. this.strCode = error_utils_1.getErrorStringCode(this.code);
  343. this.userMessage = `We were unable to extract the rules provided at: ${path}. The provided bundle may be corrupted or invalid. Please ensure it was generated using the 'snyk-iac-rules' SDK`;
  344. }
  345. }
  346. exports.FailedToExtractCustomRulesError = FailedToExtractCustomRulesError;
  347. class InvalidCustomRules extends errors_1.CustomError {
  348. constructor(path, message) {
  349. super(message || 'Invalid custom rules bundle');
  350. this.code = types_1.IaCErrorCodes.InvalidCustomRules;
  351. this.strCode = error_utils_1.getErrorStringCode(this.code);
  352. this.userMessage = `We were unable to extract the rules provided at: ${path}. The provided bundle does not match the required structure. Please ensure it was generated using the 'snyk-iac-rules' SDK`;
  353. }
  354. }
  355. exports.InvalidCustomRules = InvalidCustomRules;
  356. class InvalidCustomRulesPath extends errors_1.CustomError {
  357. constructor(path, message) {
  358. super(message || 'Invalid path to custom rules bundle');
  359. this.code = types_1.IaCErrorCodes.InvalidCustomRulesPath;
  360. this.strCode = error_utils_1.getErrorStringCode(this.code);
  361. this.userMessage = `We were unable to extract the rules provided at: ${path}. The bundle at the provided path does not exist`;
  362. }
  363. }
  364. exports.InvalidCustomRulesPath = InvalidCustomRulesPath;
  365. class FailedToCleanLocalCacheError extends errors_1.CustomError {
  366. constructor(message) {
  367. super(message || 'Failed to clean local cache');
  368. this.code = types_1.IaCErrorCodes.FailedToCleanLocalCacheError;
  369. this.strCode = error_utils_1.getErrorStringCode(this.code);
  370. this.userMessage = ''; // Not a user facing error.
  371. }
  372. }
  373. /***/ }),
  374. /***/ 166:
  375. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  376. Object.defineProperty(exports, "__esModule", ({ value: true }));
  377. exports.UnsupportedEntitlementPullError = exports.InvalidRemoteRegistryURLError = exports.InvalidManifestSchemaVersionError = exports.FailedToBuildOCIArtifactError = exports.pull = exports.extractOCIRegistryURLComponents = exports.CUSTOM_RULES_TARBALL = void 0;
  378. const fs_1 = __webpack_require__(35747);
  379. const path = __webpack_require__(85622);
  380. const types_1 = __webpack_require__(94820);
  381. const errors_1 = __webpack_require__(55191);
  382. const error_utils_1 = __webpack_require__(36401);
  383. const local_cache_1 = __webpack_require__(50089);
  384. const Debug = __webpack_require__(15158);
  385. const file_utils_1 = __webpack_require__(45281);
  386. const debug = Debug('iac-oci-pull');
  387. exports.CUSTOM_RULES_TARBALL = 'custom-bundle.tar.gz';
  388. function extractOCIRegistryURLComponents(OCIRegistryURL) {
  389. try {
  390. const urlWithoutProtocol = OCIRegistryURL.includes('://')
  391. ? OCIRegistryURL.split('://')[1]
  392. : OCIRegistryURL;
  393. const firstSlashIdx = urlWithoutProtocol.indexOf('/');
  394. const [registryHost, repoWithTag] = [
  395. urlWithoutProtocol.substring(0, firstSlashIdx),
  396. urlWithoutProtocol.substring(firstSlashIdx + 1),
  397. ];
  398. const [repo, tag = 'latest'] = repoWithTag.split(':');
  399. if (firstSlashIdx === -1 || !registryHost || !repoWithTag || !repo) {
  400. throw new InvalidRemoteRegistryURLError(OCIRegistryURL);
  401. }
  402. return { registryBase: registryHost, repo, tag };
  403. }
  404. catch {
  405. throw new InvalidRemoteRegistryURLError(OCIRegistryURL);
  406. }
  407. }
  408. exports.extractOCIRegistryURLComponents = extractOCIRegistryURLComponents;
  409. /**
  410. * Downloads an OCI Artifact from a remote OCI Registry and writes it to the
  411. * disk. The artifact here is a custom rules bundle stored in a remote registry.
  412. * In order to do that, it calls an external docker registry v2 client to get
  413. * the manifests, the layers and then builds the artifact. Example:
  414. * https://github.com/opencontainers/image-spec/blob/main/manifest.md#example-image-manifest
  415. *
  416. * @param registry The client for accessing an OCI registry.
  417. * @param repository The name of an OCI repository.
  418. * @param tag The tag of an image in an OCI repository.
  419. **/
  420. async function pull(registry, repository, tag) {
  421. const { schemaVersion, layers } = await registry.getManifest(repository, tag);
  422. if (schemaVersion !== 2) {
  423. throw new InvalidManifestSchemaVersionError(schemaVersion.toString());
  424. }
  425. // We assume that we will always have an artifact of a single layer
  426. if (layers.length > 1) {
  427. debug('There were more than one layers found in the OCI Artifact.');
  428. }
  429. const { blob } = await registry.getLayer(repository, layers[0].digest);
  430. try {
  431. const downloadPath = path.join(local_cache_1.LOCAL_POLICY_ENGINE_DIR, exports.CUSTOM_RULES_TARBALL);
  432. file_utils_1.createIacDir();
  433. await fs_1.promises.writeFile(downloadPath, blob);
  434. return downloadPath;
  435. }
  436. catch (err) {
  437. throw new FailedToBuildOCIArtifactError();
  438. }
  439. }
  440. exports.pull = pull;
  441. class FailedToBuildOCIArtifactError extends errors_1.CustomError {
  442. constructor(message) {
  443. super(message || 'Could not build OCI Artifact');
  444. this.code = types_1.IaCErrorCodes.FailedToBuildOCIArtifactError;
  445. this.strCode = error_utils_1.getErrorStringCode(this.code);
  446. this.userMessage =
  447. 'We were unable to build the remote OCI Artifact locally, please ensure that the local directory is writeable.';
  448. }
  449. }
  450. exports.FailedToBuildOCIArtifactError = FailedToBuildOCIArtifactError;
  451. class InvalidManifestSchemaVersionError extends errors_1.CustomError {
  452. constructor(message) {
  453. super(message || 'Invalid manifest schema version');
  454. this.code = types_1.IaCErrorCodes.InvalidRemoteRegistryURLError;
  455. this.strCode = error_utils_1.getErrorStringCode(this.code);
  456. this.userMessage = `Invalid manifest schema version: ${message}. We currently support Image Manifest Version 2, Schema 2`;
  457. }
  458. }
  459. exports.InvalidManifestSchemaVersionError = InvalidManifestSchemaVersionError;
  460. class InvalidRemoteRegistryURLError extends errors_1.CustomError {
  461. constructor(url) {
  462. super('Invalid URL for Remote Registry');
  463. this.code = types_1.IaCErrorCodes.InvalidRemoteRegistryURLError;
  464. this.strCode = error_utils_1.getErrorStringCode(this.code);
  465. this.userMessage = `The provided remote registry URL${url ? `: "${url}"` : ''} is invalid. Please check it again.`;
  466. }
  467. }
  468. exports.InvalidRemoteRegistryURLError = InvalidRemoteRegistryURLError;
  469. class UnsupportedEntitlementPullError extends errors_1.CustomError {
  470. constructor(entitlement) {
  471. super(`OCI Pull not supported - Missing the ${entitlement} entitlement`);
  472. this.code = types_1.IaCErrorCodes.UnsupportedEntitlementPullError;
  473. this.strCode = error_utils_1.getErrorStringCode(this.code);
  474. this.userMessage = `The custom rules feature is currently not supported for this org. To enable it, please contact snyk support.`;
  475. }
  476. }
  477. exports.UnsupportedEntitlementPullError = UnsupportedEntitlementPullError;
  478. /***/ })
  479. };
  480. ;
  481. //# sourceMappingURL=519.index.js.map