Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!requestAsync && !response.body.content) {
// Stop the validations.
return false;
}
if (!requestAsync) {
return true;
}
/* If the content already exists, we don't need to download it. */
if (response.body.content) {
return true;
}
try {
response.body.content = await requestAsync({
gzip: true,
method: 'GET',
rejectUnauthorized: false,
url: resource
});
return true;
} catch (e) {
debug(`Error accessing ${resource}. ${JSON.stringify(e)}`);
this.context.report(
urls.final,
getMessage('canNotGetResource', this.context.language, resource),
{ element, severity: Severity.error }
);
/* istanbul ignore if */
if (process.env.webpack) { // eslint-disable-line no-process-env
return require('./snyk-snapshot.json');
}
try {
const snykDBPath = require.resolve('./snyk-snapshot.json');
const snykStat = await promisify(fs.stat)(snykDBPath);
const modified = new Date(snykStat.mtime).getTime();
// We check if the file is older than 24h to update it
/* istanbul ignore if */
if (now - modified > oneDay) {
debug('snkyDB is older than 24h.');
debug('Updating snykDB');
const res = await requestAsync('https://snyk.io/partners/api/v2/vulndb/clientside.json');
await writeFileAsync(snykDBPath, res);
}
} catch (e) /* istanbul ignore next */ {
debug(e);
debug(`Error loading snyk's data`);
}
return require('./snyk-snapshot.json');
};