726.index.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. exports.id = 726;
  2. exports.ids = [726,85];
  3. exports.modules = {
  4. /***/ 94378:
  5. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  6. try {
  7. var util = __webpack_require__(31669);
  8. /* istanbul ignore next */
  9. if (typeof util.inherits !== 'function') throw '';
  10. module.exports = util.inherits;
  11. } catch (e) {
  12. /* istanbul ignore next */
  13. module.exports = __webpack_require__(35717);
  14. }
  15. /***/ }),
  16. /***/ 35717:
  17. /***/ ((module) => {
  18. if (typeof Object.create === 'function') {
  19. // implementation from standard node.js 'util' module
  20. module.exports = function inherits(ctor, superCtor) {
  21. if (superCtor) {
  22. ctor.super_ = superCtor
  23. ctor.prototype = Object.create(superCtor.prototype, {
  24. constructor: {
  25. value: ctor,
  26. enumerable: false,
  27. writable: true,
  28. configurable: true
  29. }
  30. })
  31. }
  32. };
  33. } else {
  34. // old school shim for old browsers
  35. module.exports = function inherits(ctor, superCtor) {
  36. if (superCtor) {
  37. ctor.super_ = superCtor
  38. var TempCtor = function () {}
  39. TempCtor.prototype = superCtor.prototype
  40. ctor.prototype = new TempCtor()
  41. ctor.prototype.constructor = ctor
  42. }
  43. }
  44. }
  45. /***/ }),
  46. /***/ 70919:
  47. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  48. "use strict";
  49. Object.defineProperty(exports, "__esModule", ({ value: true }));
  50. const process_command_args_1 = __webpack_require__(52369);
  51. const legacyError = __webpack_require__(79407);
  52. const drift_1 = __webpack_require__(26445);
  53. const get_iac_org_settings_1 = __webpack_require__(11693);
  54. const assert_iac_options_flag_1 = __webpack_require__(33111);
  55. const config_1 = __webpack_require__(25425);
  56. const analytics_1 = __webpack_require__(41519);
  57. const analytics = __webpack_require__(82744);
  58. const policy_1 = __webpack_require__(32615);
  59. const describe_required_argument_error_1 = __webpack_require__(37541);
  60. const help_1 = __webpack_require__(21085);
  61. const driftctl_1 = __webpack_require__(3659);
  62. exports.default = async (...args) => {
  63. var _a, _b;
  64. const { options } = process_command_args_1.processCommandArgs(...args);
  65. // Ensure that this describe command can only be runned when using `snyk iac describe`
  66. // Avoid `snyk describe` direct usage
  67. if (options.iac != true) {
  68. return legacyError('describe');
  69. }
  70. // Ensure that we are allowed to run that command
  71. // by checking the entitlement
  72. const orgPublicId = (_a = options.org) !== null && _a !== void 0 ? _a : config_1.default.org;
  73. const iacOrgSettings = await get_iac_org_settings_1.getIacOrgSettings(orgPublicId);
  74. if (!((_b = iacOrgSettings.entitlements) === null || _b === void 0 ? void 0 : _b.iacDrift)) {
  75. throw new assert_iac_options_flag_1.UnsupportedEntitlementCommandError('drift', 'iacDrift');
  76. }
  77. const policy = await policy_1.findAndLoadPolicy(process.cwd(), 'iac', options);
  78. const driftIgnore = drift_1.driftignoreFromPolicy(policy);
  79. try {
  80. const describe = await driftctl_1.runDriftCTL({
  81. options: { ...options, kind: 'describe' },
  82. driftIgnore: driftIgnore,
  83. });
  84. process.exitCode = describe.code;
  85. analytics.add('is-iac-drift', true);
  86. analytics.add('iac-drift-exit-code', describe.code);
  87. if (describe.code === driftctl_1.DCTL_EXIT_CODES.EXIT_ERROR) {
  88. throw new Error();
  89. }
  90. // Parse analysis JSON and add to analytics
  91. const analysis = drift_1.parseDriftAnalysisResults(describe.stdout);
  92. analytics_1.addIacDriftAnalytics(analysis, options);
  93. const output = await drift_1.processAnalysis(options, describe);
  94. process.stdout.write(output);
  95. }
  96. catch (e) {
  97. if (e instanceof describe_required_argument_error_1.DescribeRequiredArgumentError) {
  98. // when missing a required arg we will display help to explain
  99. const helpMsg = await help_1.default('iac', 'describe');
  100. console.log(helpMsg);
  101. }
  102. return Promise.reject(e);
  103. }
  104. };
  105. /***/ }),
  106. /***/ 21085:
  107. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  108. "use strict";
  109. Object.defineProperty(exports, "__esModule", ({ value: true }));
  110. exports.findHelpFile = void 0;
  111. const fs = __webpack_require__(35747);
  112. const path = __webpack_require__(85622);
  113. const markdown_renderer_1 = __webpack_require__(99387);
  114. function findHelpFile(helpArgs, helpFolderPath = '../../help/cli-commands') {
  115. while (helpArgs.length > 0) {
  116. // cleanse the filename to only contain letters
  117. // aka: /\W/g but figured this was easier to read
  118. const file = `${helpArgs.join('-').replace(/[^a-z0-9-]/gi, '')}.md`;
  119. const testHelpAbsolutePath = path.resolve(__dirname, helpFolderPath, file);
  120. if (fs.existsSync(testHelpAbsolutePath)) {
  121. return testHelpAbsolutePath;
  122. }
  123. helpArgs = helpArgs.slice(0, -1);
  124. }
  125. return path.resolve(__dirname, helpFolderPath, `README.md`); // Default help file
  126. }
  127. exports.findHelpFile = findHelpFile;
  128. async function help(...args) {
  129. const helpArgs = args.filter((arg) => typeof arg === 'string');
  130. const helpFileAbsolutePath = findHelpFile(helpArgs);
  131. return markdown_renderer_1.renderMarkdown(fs.readFileSync(helpFileAbsolutePath, 'utf8'));
  132. }
  133. exports.default = help;
  134. /***/ }),
  135. /***/ 99387:
  136. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  137. "use strict";
  138. Object.defineProperty(exports, "__esModule", ({ value: true }));
  139. exports.renderMarkdown = void 0;
  140. const marked_1 = __webpack_require__(30970);
  141. const chalk_1 = __webpack_require__(32589);
  142. const reflow_text_1 = __webpack_require__(67211);
  143. // stateful variable to control left-padding by header level
  144. let currentHeader = 1;
  145. const listItemSeparator = 'LISTITEMSEPARATOR'; // Helper string for rendering ListItems
  146. /**
  147. * @description get padding spaces depending on the last header level used
  148. * @returns string
  149. */
  150. function getLeftTextPadding() {
  151. return ' '.repeat(currentHeader === 1 || currentHeader === 2 ? 1 : currentHeader - 1);
  152. }
  153. /**
  154. * @description Reads current terminal width if available to limit column width for text-reflowing
  155. * @returns {number}
  156. */
  157. const defaultMaximumLineWidth = 100;
  158. function getIdealTextWidth(maximumLineWidth = defaultMaximumLineWidth) {
  159. if (typeof process.stdout.columns === 'number') {
  160. if (process.stdout.columns < maximumLineWidth) {
  161. return process.stdout.columns - getLeftTextPadding().length - 5;
  162. }
  163. }
  164. return maximumLineWidth - getLeftTextPadding().length;
  165. }
  166. // Marked custom renderer class
  167. const renderer = {
  168. em(text) {
  169. return chalk_1.default.italic(text);
  170. },
  171. strong(text) {
  172. return chalk_1.default.bold(text);
  173. },
  174. link(href, title, text) {
  175. // Don't render links to relative paths (like local files)
  176. if (href.startsWith('./') || !href.includes('://')) {
  177. return text;
  178. }
  179. const renderedLink = chalk_1.default.bold.blueBright(href);
  180. if (text && text !== href) {
  181. return `${text} ${renderedLink}`;
  182. }
  183. return renderedLink;
  184. },
  185. blockquote(quote) {
  186. return quote;
  187. },
  188. list(body, ordered, start) {
  189. return (body
  190. .split(listItemSeparator)
  191. .map((listItem, listItemIndex) => {
  192. const bulletPoint = ordered ? `${listItemIndex + start}. ` : '- ';
  193. return reflow_text_1.reflowText(listItem, getIdealTextWidth())
  194. .split('\n')
  195. .map((listItemLine, listItemLineIndex) => {
  196. if (!listItemLine) {
  197. return '';
  198. }
  199. return `${getLeftTextPadding()}${listItemLineIndex === 0 ? bulletPoint : ' '}${listItemLine}`;
  200. })
  201. .join('\n');
  202. })
  203. .join('\n') + '\n');
  204. },
  205. listitem(text) {
  206. return text + listItemSeparator;
  207. },
  208. paragraph(text) {
  209. return (reflow_text_1.reflowText(text, getIdealTextWidth())
  210. .split('\n')
  211. .map((s) => getLeftTextPadding() + chalk_1.default.reset() + s)
  212. .join('\n') + '\n\n');
  213. },
  214. codespan(text) {
  215. return chalk_1.default.italic.blueBright(`${text}`);
  216. },
  217. code(code) {
  218. return (code
  219. .split('\n')
  220. .map((s) => getLeftTextPadding() + chalk_1.default.reset() + s)
  221. .join('\n') + '\n\n');
  222. },
  223. heading(text, level) {
  224. currentHeader = level;
  225. let coloring;
  226. switch (level) {
  227. case 1:
  228. coloring = chalk_1.default.bold.underline;
  229. break;
  230. case 3:
  231. case 4:
  232. coloring = chalk_1.default;
  233. break;
  234. default:
  235. coloring = chalk_1.default.bold;
  236. break;
  237. }
  238. return `${' '.repeat(level === 1 ? 0 : currentHeader - 2)}${coloring(text)}\n`;
  239. },
  240. };
  241. marked_1.marked.use({ renderer });
  242. marked_1.marked.setOptions({
  243. mangle: false,
  244. });
  245. const htmlUnescapes = {
  246. '&amp;': '&',
  247. '&lt;': '<',
  248. '&gt;': '>',
  249. '&quot;': '"',
  250. '&#39;': "'",
  251. '&#96;': '`',
  252. '&#x20;': '',
  253. };
  254. /**
  255. * @description Replace HTML entities with their non-encoded variant
  256. * @param {string} text
  257. * @returns {string}
  258. */
  259. function unescape(text) {
  260. Object.entries(htmlUnescapes).forEach(([escapedChar, unescapedChar]) => {
  261. const escapedCharRegExp = new RegExp(escapedChar, 'g');
  262. text = text.replace(escapedCharRegExp, unescapedChar);
  263. });
  264. return text;
  265. }
  266. function renderMarkdown(markdown) {
  267. return unescape(marked_1.marked.parse(markdown));
  268. }
  269. exports.renderMarkdown = renderMarkdown;
  270. /***/ }),
  271. /***/ 67211:
  272. /***/ ((__unused_webpack_module, exports) => {
  273. "use strict";
  274. /**
  275. Code in this file is adapted from mikaelbr/marked-terminal
  276. https://github.com/mikaelbr/marked-terminal/blob/7501b8bb24a5ed52ec7d9114d4aeefa14f1bf5e6/index.js#L234-L330
  277. MIT License
  278. Copyright (c) 2017 Mikael Brevik
  279. Permission is hereby granted, free of charge, to any person obtaining a copy
  280. of this software and associated documentation files (the "Software"), to deal
  281. in the Software without restriction, including without limitation the rights
  282. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  283. copies of the Software, and to permit persons to whom the Software is
  284. furnished to do so, subject to the following conditions:
  285. The above copyright notice and this permission notice shall be included in all
  286. copies or substantial portions of the Software.
  287. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  288. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  289. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  290. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  291. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  292. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  293. SOFTWARE.
  294. */
  295. Object.defineProperty(exports, "__esModule", ({ value: true }));
  296. exports.reflowText = void 0;
  297. // Compute length of str not including ANSI escape codes.
  298. // See http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
  299. function textLength(str) {
  300. // eslint-disable-next-line no-control-regex
  301. return str.replace(/\u001b\[(?:\d{1,3})(?:;\d{1,3})*m/g, '').length;
  302. }
  303. // Munge \n's and spaces in "text" so that the number of
  304. // characters between \n's is less than or equal to "width".
  305. function reflowText(text, width) {
  306. const HARD_RETURN = '\r|\n';
  307. const HARD_RETURN_GFM_RE = new RegExp(HARD_RETURN + '|<br ?/?>');
  308. const splitRe = HARD_RETURN_GFM_RE;
  309. const sections = text.split(splitRe);
  310. const reflowed = [];
  311. sections.forEach((section) => {
  312. // Split the section by escape codes so that we can
  313. // deal with them separately.
  314. // eslint-disable-next-line no-control-regex
  315. const fragments = section.split(/(\u001b\[(?:\d{1,3})(?:;\d{1,3})*m)/g);
  316. let column = 0;
  317. let currentLine = '';
  318. let lastWasEscapeChar = false;
  319. while (fragments.length) {
  320. const fragment = fragments[0];
  321. if (fragment === '') {
  322. fragments.splice(0, 1);
  323. lastWasEscapeChar = false;
  324. continue;
  325. }
  326. // This is an escape code - leave it whole and
  327. // move to the next fragment.
  328. if (!textLength(fragment)) {
  329. currentLine += fragment;
  330. fragments.splice(0, 1);
  331. lastWasEscapeChar = true;
  332. continue;
  333. }
  334. const words = fragment.split(/[ \t\n]+/);
  335. for (let i = 0; i < words.length; i++) {
  336. let word = words[i];
  337. let addSpace = column != 0;
  338. if (lastWasEscapeChar)
  339. addSpace = false;
  340. // If adding the new word overflows the required width
  341. if (column + word.length > width) {
  342. if (word.length <= width) {
  343. // If the new word is smaller than the required width
  344. // just add it at the beginning of a new line
  345. reflowed.push(currentLine);
  346. currentLine = word;
  347. column = word.length;
  348. }
  349. else {
  350. // If the new word is longer than the required width
  351. // split this word into smaller parts.
  352. const w = word.substr(0, width - column);
  353. if (addSpace)
  354. currentLine += ' ';
  355. currentLine += w;
  356. reflowed.push(currentLine);
  357. currentLine = '';
  358. column = 0;
  359. word = word.substr(w.length);
  360. while (word.length) {
  361. const w = word.substr(0, width);
  362. if (!w.length)
  363. break;
  364. if (w.length < width) {
  365. currentLine = w;
  366. column = w.length;
  367. break;
  368. }
  369. else {
  370. reflowed.push(w);
  371. word = word.substr(width);
  372. }
  373. }
  374. }
  375. }
  376. else {
  377. if (addSpace) {
  378. currentLine += ' ';
  379. column++;
  380. }
  381. currentLine += word;
  382. column += word.length;
  383. }
  384. lastWasEscapeChar = false;
  385. }
  386. fragments.splice(0, 1);
  387. }
  388. if (textLength(currentLine))
  389. reflowed.push(currentLine);
  390. });
  391. return reflowed.join('\n');
  392. }
  393. exports.reflowText = reflowText;
  394. /***/ }),
  395. /***/ 52369:
  396. /***/ ((__unused_webpack_module, exports) => {
  397. "use strict";
  398. Object.defineProperty(exports, "__esModule", ({ value: true }));
  399. exports.processCommandArgs = void 0;
  400. function processCommandArgs(...args) {
  401. let options = {};
  402. if (typeof args[args.length - 1] === 'object') {
  403. options = args.pop();
  404. }
  405. args = args.filter(Boolean);
  406. // For repository scanning, populate with default path (cwd) if no path given
  407. if (args.length === 0 && !options.docker) {
  408. args.unshift(process.cwd());
  409. }
  410. return { options, paths: args };
  411. }
  412. exports.processCommandArgs = processCommandArgs;
  413. /***/ }),
  414. /***/ 8820:
  415. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  416. "use strict";
  417. Object.defineProperty(exports, "__esModule", ({ value: true }));
  418. exports.findAndLoadPolicy = void 0;
  419. const snykPolicyLib = __webpack_require__(70535);
  420. const debugModule = __webpack_require__(15158);
  421. const _1 = __webpack_require__(32615);
  422. const analytics = __webpack_require__(82744);
  423. const debug = debugModule('snyk');
  424. async function findAndLoadPolicy(root, scanType, options, pkg, scannedProjectFolder) {
  425. const isDocker = scanType === 'docker';
  426. const isNodeProject = ['npm', 'yarn'].includes(scanType);
  427. // monitor
  428. let policyLocations = [
  429. options['policy-path'] || scannedProjectFolder || root,
  430. ];
  431. if (isDocker) {
  432. policyLocations = policyLocations.filter((loc) => loc !== root);
  433. }
  434. else if (isNodeProject) {
  435. // TODO: pluckPolicies expects a package.json object to
  436. // find and apply policies in node_modules
  437. policyLocations = policyLocations.concat(_1.pluckPolicies(pkg));
  438. }
  439. debug('Potential policy locations found:', policyLocations);
  440. analytics.add('policies', policyLocations.length);
  441. analytics.add('policyLocations', policyLocations);
  442. if (policyLocations.length === 0) {
  443. return;
  444. }
  445. let policy;
  446. try {
  447. policy = await snykPolicyLib.load(policyLocations, options);
  448. }
  449. catch (err) {
  450. // note: inline catch, to handle error from .load
  451. // if the .snyk file wasn't found, it is fine
  452. if (err.code !== 'ENOENT' && err.code !== 'ENOTDIR') {
  453. throw err;
  454. }
  455. }
  456. return policy;
  457. }
  458. exports.findAndLoadPolicy = findAndLoadPolicy;
  459. /***/ }),
  460. /***/ 32615:
  461. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  462. "use strict";
  463. Object.defineProperty(exports, "__esModule", ({ value: true }));
  464. var pluck_policies_1 = __webpack_require__(68247);
  465. Object.defineProperty(exports, "pluckPolicies", ({ enumerable: true, get: function () { return pluck_policies_1.pluckPolicies; } }));
  466. var find_and_load_policy_1 = __webpack_require__(8820);
  467. Object.defineProperty(exports, "findAndLoadPolicy", ({ enumerable: true, get: function () { return find_and_load_policy_1.findAndLoadPolicy; } }));
  468. /***/ }),
  469. /***/ 68247:
  470. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  471. "use strict";
  472. Object.defineProperty(exports, "__esModule", ({ value: true }));
  473. exports.pluckPolicies = void 0;
  474. const flatten = __webpack_require__(5800);
  475. function pluckPolicies(pkg) {
  476. if (!pkg) {
  477. return [];
  478. }
  479. if (pkg.snyk) {
  480. return pkg.snyk;
  481. }
  482. if (!pkg.dependencies) {
  483. return [];
  484. }
  485. return flatten(Object.keys(pkg.dependencies)
  486. .map((name) => pluckPolicies(pkg.dependencies[name]))
  487. .filter(Boolean));
  488. }
  489. exports.pluckPolicies = pluckPolicies;
  490. /***/ })
  491. };
  492. ;
  493. //# sourceMappingURL=726.index.js.map