542.index.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. "use strict";
  2. exports.id = 542;
  3. exports.ids = [542];
  4. exports.modules = {
  5. /***/ 71771:
  6. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7. Object.defineProperty(exports, "__esModule", ({ value: true }));
  8. exports.verifyAPI = exports.isAuthed = void 0;
  9. const snyk = __webpack_require__(9146);
  10. const config_1 = __webpack_require__(25425);
  11. const request_1 = __webpack_require__(52050);
  12. function isAuthed() {
  13. const token = snyk.config.get('api');
  14. return verifyAPI(token).then((res) => {
  15. return res.body.ok;
  16. });
  17. }
  18. exports.isAuthed = isAuthed;
  19. function verifyAPI(api) {
  20. const payload = {
  21. body: {
  22. api,
  23. },
  24. method: 'POST',
  25. url: config_1.default.API + '/verify/token',
  26. json: true,
  27. };
  28. return new Promise((resolve, reject) => {
  29. request_1.makeRequest(payload, (error, res, body) => {
  30. if (error) {
  31. return reject(error);
  32. }
  33. resolve({
  34. res,
  35. body,
  36. });
  37. });
  38. });
  39. }
  40. exports.verifyAPI = verifyAPI;
  41. /***/ }),
  42. /***/ 3542:
  43. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  44. Object.defineProperty(exports, "__esModule", ({ value: true }));
  45. exports.excludeFilePathPattern = exports.ignoreIssue = void 0;
  46. const policy = __webpack_require__(70535);
  47. const chalk_1 = __webpack_require__(32589);
  48. const authorization = __webpack_require__(69943);
  49. const auth = __webpack_require__(71771);
  50. const api_token_1 = __webpack_require__(95181);
  51. const is_ci_1 = __webpack_require__(10090);
  52. const Debug = __webpack_require__(15158);
  53. const debug = Debug('snyk');
  54. const misconfigured_auth_in_ci_error_1 = __webpack_require__(27747);
  55. function ignore(options) {
  56. debug('snyk ignore called with options: %O', options);
  57. return auth
  58. .isAuthed()
  59. .then((authed) => {
  60. if (!authed) {
  61. if (is_ci_1.isCI()) {
  62. throw misconfigured_auth_in_ci_error_1.MisconfiguredAuthInCI();
  63. }
  64. }
  65. api_token_1.apiTokenExists();
  66. })
  67. .then(() => {
  68. return authorization.actionAllowed('cliIgnore', options);
  69. })
  70. .then((cliIgnoreAuthorization) => {
  71. if (!cliIgnoreAuthorization.allowed) {
  72. debug('snyk ignore called when disallowed');
  73. console.log(chalk_1.default.bold.red(cliIgnoreAuthorization.reason));
  74. return;
  75. }
  76. const isFilePathProvided = !!options['file-path'];
  77. if (isFilePathProvided) {
  78. return excludeFilePathPattern(options);
  79. }
  80. return ignoreIssue(options);
  81. });
  82. }
  83. exports.default = ignore;
  84. function ignoreIssue(options) {
  85. if (!options.id) {
  86. throw Error('idRequired');
  87. }
  88. options.expiry = new Date(options.expiry);
  89. if (options.expiry.getTime() !== options.expiry.getTime()) {
  90. debug('No/invalid expiry given, using the default 30 days');
  91. options.expiry = new Date(Date.now() + 30 * 24 * 60 * 60 * 1000);
  92. }
  93. if (!options.reason) {
  94. options.reason = 'None Given';
  95. }
  96. const isPathProvided = !!options.path;
  97. if (!isPathProvided) {
  98. options.path = '*';
  99. }
  100. debug(`changing policy: ignore "%s", for %s, reason: "%s", until: %o`, options.id, isPathProvided ? 'all paths' : `path: '${options.path}'`, options.reason, options.expiry);
  101. return load(options['policy-path']).then(async (pol) => {
  102. var _a;
  103. let ignoreRulePathDataIdx = -1;
  104. const ignoreParams = {
  105. reason: options.reason,
  106. expires: options.expiry,
  107. created: new Date(),
  108. };
  109. const ignoreRules = pol.ignore;
  110. const issueIgnorePaths = (_a = ignoreRules[options.id]) !== null && _a !== void 0 ? _a : [];
  111. // Checking if the ignore-rule for this issue exists for the provided path.
  112. ignoreRulePathDataIdx = issueIgnorePaths.findIndex((ignoreMetadata) => !!ignoreMetadata[options.path]);
  113. // If an ignore-rule for this path doesn't exist, create one.
  114. if (ignoreRulePathDataIdx === -1) {
  115. issueIgnorePaths.push({
  116. [options.path]: ignoreParams,
  117. });
  118. }
  119. // Otherwise, update the existing rule's metadata.
  120. else {
  121. issueIgnorePaths[ignoreRulePathDataIdx][options.path] = ignoreParams;
  122. }
  123. ignoreRules[options.id] = issueIgnorePaths;
  124. pol.ignore = ignoreRules;
  125. return await policy.save(pol, options['policy-path']);
  126. });
  127. }
  128. exports.ignoreIssue = ignoreIssue;
  129. async function excludeFilePathPattern(options) {
  130. const pattern = options['file-path'];
  131. const group = options['file-path-group'] || 'global';
  132. const policyPath = options['policy-path'];
  133. const excludeOptions = {};
  134. if (options.reason !== undefined) {
  135. excludeOptions['reason'] = options.reason;
  136. }
  137. if (options.expiry !== undefined) {
  138. excludeOptions['expires'] = new Date(options.expiry);
  139. }
  140. debug(`changing policy: ignore "%s" added to "%s"`, pattern, policyPath);
  141. const pol = await load(policyPath);
  142. pol.addExclude(pattern, group, excludeOptions);
  143. return policy.save(pol, policyPath);
  144. }
  145. exports.excludeFilePathPattern = excludeFilePathPattern;
  146. async function load(path) {
  147. return policy.load(path).catch((error) => {
  148. if (error.code === 'ENOENT') {
  149. // file does not exist - create it
  150. return policy.create();
  151. }
  152. throw Error('policyFile');
  153. });
  154. }
  155. /***/ }),
  156. /***/ 69943:
  157. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  158. Object.defineProperty(exports, "__esModule", ({ value: true }));
  159. exports.actionAllowed = void 0;
  160. const api_token_1 = __webpack_require__(95181);
  161. const config_1 = __webpack_require__(25425);
  162. const request_1 = __webpack_require__(52050);
  163. async function actionAllowed(action, options) {
  164. const org = options.org || config_1.default.org || null;
  165. try {
  166. const res = await request_1.makeRequest({
  167. method: 'GET',
  168. url: config_1.default.API + '/authorization/' + action,
  169. json: true,
  170. headers: {
  171. authorization: api_token_1.getAuthHeader(),
  172. },
  173. qs: org && { org },
  174. });
  175. return res.body.result;
  176. }
  177. catch (err) {
  178. return {
  179. allowed: false,
  180. reason: 'There was an error while checking authorization',
  181. };
  182. }
  183. }
  184. exports.actionAllowed = actionAllowed;
  185. /***/ }),
  186. /***/ 27747:
  187. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  188. Object.defineProperty(exports, "__esModule", ({ value: true }));
  189. exports.MisconfiguredAuthInCI = void 0;
  190. const custom_error_1 = __webpack_require__(17188);
  191. function MisconfiguredAuthInCI() {
  192. const errorMsg = 'Snyk is missing auth token in order to run inside CI. You must include ' +
  193. 'your API token as an environment value: `SNYK_TOKEN=12345678`';
  194. const error = new custom_error_1.CustomError(errorMsg);
  195. error.code = 401;
  196. error.strCode = 'noAuthInCI';
  197. error.userMessage = errorMsg;
  198. return error;
  199. }
  200. exports.MisconfiguredAuthInCI = MisconfiguredAuthInCI;
  201. /***/ })
  202. };
  203. ;
  204. //# sourceMappingURL=542.index.js.map