542.index.js
6.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
"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__(22541);
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 }));
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;
}
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 policy
.load(options['policy-path'])
.catch((error) => {
if (error.code === 'ENOENT') {
// file does not exist - create it
return policy.create();
}
throw Error('policyFile');
})
.then(async function ignoreIssue(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 an 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.default = ignore;
/***/ }),
/***/ 69943:
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.actionAllowed = void 0;
const snyk = __webpack_require__(9146);
const request_1 = __webpack_require__(52050);
const config_1 = __webpack_require__(22541);
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: 'token ' + snyk.api,
},
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