Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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';
}
debug(
'changing policy: ignore "%s", for all paths, reason: "%s", until: %o',
options.id,
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(function ignoreIssue(pol) {
pol.ignore[options.id] = [
{
'*': {
reason: options.reason,
expires: options.expiry,
},
},
async function displayPolicy(path?: string): Promise {
try {
const loadedPolicy = (await policy.load(path || process.cwd())) as Promise<
string
>;
return await display(loadedPolicy);
} catch (error) {
let adaptedError: CustomError;
if (error.code === 'ENOENT') {
adaptedError = new PolicyNotFoundError();
} else {
adaptedError = new FailedToLoadPolicyError();
adaptedError.innerError = error;
}
throw adaptedError;
}
}
function displayPolicy(path) {
return policy.load(path || process.cwd())
.then(display)
.catch((e) => {
let error;
if (e.code === 'ENOENT') {
error = new errors.PolicyNotFoundError();
} else {
error = new errors.FailedToLoadPolicyError();
error.innerError = e;
}
throw error;
});
}