123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- "use strict";
- exports.id = 542;
- exports.ids = [542];
- exports.modules = {
- /***/ 71771:
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
- Object.defineProperty(exports, "__esModule", ({ value: true }));
- exports.verifyAPI = exports.isAuthed = void 0;
- const snyk = __webpack_require__(9146);
- const config_1 = __webpack_require__(25425);
- const request_1 = __webpack_require__(52050);
- function isAuthed() {
- const token = snyk.config.get('api');
- return verifyAPI(token).then((res) => {
- return res.body.ok;
- });
- }
- exports.isAuthed = isAuthed;
- function verifyAPI(api) {
- const payload = {
- body: {
- api,
- },
- method: 'POST',
- url: config_1.default.API + '/verify/token',
- json: true,
- };
- return new Promise((resolve, reject) => {
- request_1.makeRequest(payload, (error, res, body) => {
- if (error) {
- return reject(error);
- }
- resolve({
- res,
- body,
- });
- });
- });
- }
- exports.verifyAPI = verifyAPI;
- /***/ }),
- /***/ 3542:
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
- Object.defineProperty(exports, "__esModule", ({ value: true }));
- exports.excludeFilePathPattern = exports.ignoreIssue = void 0;
- const policy = __webpack_require__(70535);
- const chalk_1 = __webpack_require__(32589);
- const authorization = __webpack_require__(69943);
- const auth = __webpack_require__(71771);
- const api_token_1 = __webpack_require__(95181);
- const is_ci_1 = __webpack_require__(10090);
- const Debug = __webpack_require__(15158);
- const debug = Debug('snyk');
- const misconfigured_auth_in_ci_error_1 = __webpack_require__(27747);
- function ignore(options) {
- debug('snyk ignore called with options: %O', options);
- return auth
- .isAuthed()
- .then((authed) => {
- if (!authed) {
- if (is_ci_1.isCI()) {
- throw misconfigured_auth_in_ci_error_1.MisconfiguredAuthInCI();
- }
- }
- api_token_1.apiTokenExists();
- })
- .then(() => {
- return authorization.actionAllowed('cliIgnore', options);
- })
- .then((cliIgnoreAuthorization) => {
- if (!cliIgnoreAuthorization.allowed) {
- debug('snyk ignore called when disallowed');
- console.log(chalk_1.default.bold.red(cliIgnoreAuthorization.reason));
- return;
- }
- const isFilePathProvided = !!options['file-path'];
- if (isFilePathProvided) {
- return excludeFilePathPattern(options);
- }
- return ignoreIssue(options);
- });
- }
- exports.default = ignore;
- function ignoreIssue(options) {
- if (!options.id) {
- throw Error('idRequired');
- }
- options.expiry = new Date(options.expiry);
- if (options.expiry.getTime() !== options.expiry.getTime()) {
- debug('No/invalid expiry given, using the default 30 days');
- options.expiry = new Date(Date.now() + 30 * 24 * 60 * 60 * 1000);
- }
- if (!options.reason) {
- options.reason = 'None Given';
- }
- const isPathProvided = !!options.path;
- if (!isPathProvided) {
- options.path = '*';
- }
- debug(`changing policy: ignore "%s", for %s, reason: "%s", until: %o`, options.id, isPathProvided ? 'all paths' : `path: '${options.path}'`, options.reason, options.expiry);
- return load(options['policy-path']).then(async (pol) => {
- var _a;
- let ignoreRulePathDataIdx = -1;
- const ignoreParams = {
- reason: options.reason,
- expires: options.expiry,
- created: new Date(),
- };
- const ignoreRules = pol.ignore;
- const issueIgnorePaths = (_a = ignoreRules[options.id]) !== null && _a !== void 0 ? _a : [];
- // Checking if the ignore-rule for this issue exists for the provided path.
- ignoreRulePathDataIdx = issueIgnorePaths.findIndex((ignoreMetadata) => !!ignoreMetadata[options.path]);
- // If an ignore-rule for this path doesn't exist, create one.
- if (ignoreRulePathDataIdx === -1) {
- issueIgnorePaths.push({
- [options.path]: ignoreParams,
- });
- }
- // Otherwise, update the existing rule's metadata.
- else {
- issueIgnorePaths[ignoreRulePathDataIdx][options.path] = ignoreParams;
- }
- ignoreRules[options.id] = issueIgnorePaths;
- pol.ignore = ignoreRules;
- return await policy.save(pol, options['policy-path']);
- });
- }
- exports.ignoreIssue = ignoreIssue;
- async function excludeFilePathPattern(options) {
- const pattern = options['file-path'];
- const group = options['file-path-group'] || 'global';
- const policyPath = options['policy-path'];
- const excludeOptions = {};
- if (options.reason !== undefined) {
- excludeOptions['reason'] = options.reason;
- }
- if (options.expiry !== undefined) {
- excludeOptions['expires'] = new Date(options.expiry);
- }
- debug(`changing policy: ignore "%s" added to "%s"`, pattern, policyPath);
- const pol = await load(policyPath);
- pol.addExclude(pattern, group, excludeOptions);
- return policy.save(pol, policyPath);
- }
- exports.excludeFilePathPattern = excludeFilePathPattern;
- async function load(path) {
- return policy.load(path).catch((error) => {
- if (error.code === 'ENOENT') {
- // file does not exist - create it
- return policy.create();
- }
- throw Error('policyFile');
- });
- }
- /***/ }),
- /***/ 69943:
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
- Object.defineProperty(exports, "__esModule", ({ value: true }));
- exports.actionAllowed = void 0;
- const api_token_1 = __webpack_require__(95181);
- const config_1 = __webpack_require__(25425);
- const request_1 = __webpack_require__(52050);
- async function actionAllowed(action, options) {
- const org = options.org || config_1.default.org || null;
- try {
- const res = await request_1.makeRequest({
- method: 'GET',
- url: config_1.default.API + '/authorization/' + action,
- json: true,
- headers: {
- authorization: api_token_1.getAuthHeader(),
- },
- qs: org && { org },
- });
- return res.body.result;
- }
- catch (err) {
- return {
- allowed: false,
- reason: 'There was an error while checking authorization',
- };
- }
- }
- exports.actionAllowed = actionAllowed;
- /***/ }),
- /***/ 27747:
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
- Object.defineProperty(exports, "__esModule", ({ value: true }));
- exports.MisconfiguredAuthInCI = void 0;
- const custom_error_1 = __webpack_require__(17188);
- function MisconfiguredAuthInCI() {
- const errorMsg = 'Snyk is missing auth token in order to run inside CI. You must include ' +
- 'your API token as an environment value: `SNYK_TOKEN=12345678`';
- const error = new custom_error_1.CustomError(errorMsg);
- error.code = 401;
- error.strCode = 'noAuthInCI';
- error.userMessage = errorMsg;
- return error;
- }
- exports.MisconfiguredAuthInCI = MisconfiguredAuthInCI;
- /***/ })
- };
- ;
- //# sourceMappingURL=542.index.js.map
|