"Fossies" - the Fresh Open Source Software Archive

Member "cli-1.1280.1/src/lib/display-policy.ts" (20 Feb 2024, 1562 Bytes) of package /linux/misc/snyk-cli-1.1280.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) TypeScript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 import chalk from 'chalk';
    2 import { demunge } from 'snyk-policy';
    3 import config from './config';
    4 
    5 export async function display(policy) {
    6   const p = demunge(policy, config.PUBLIC_VULN_DB_URL);
    7   const delimiter = '\n\n------------------------\n';
    8 
    9   let res =
   10     chalk.bold(
   11       'Current Snyk policy, read from ' + policy.__filename + ' file',
   12     ) + '\n';
   13   res += 'Modified: ' + policy.__modified + '\n';
   14   res += 'Created:  ' + policy.__created + '\n';
   15 
   16   res += p.patch.map(displayRule('Patch vulnerability')).join('\n');
   17   if (p.patch.length && p.ignore.length) {
   18     res += delimiter;
   19   }
   20 
   21   res += p.ignore.map(displayRule('Ignore')).join('\n');
   22   if (p.ignore.length && p.exclude.length) {
   23     res += delimiter;
   24   }
   25 
   26   res += p.exclude.map(displayRule('Exclude')).join('\n');
   27 
   28   return Promise.resolve(res);
   29 }
   30 
   31 function displayRule(title) {
   32   return (rule, i) => {
   33     i += 1;
   34 
   35     const formattedTitle =
   36       title === 'Exclude'
   37         ? chalk.bold(`\n#${i} ${title}`) +
   38           ` the following ${chalk.bold(rule.id)} items/paths:\n`
   39         : chalk.bold(`\n#${i} ${title} ${rule.url}`) +
   40           ' in the following paths:\n';
   41 
   42     return (
   43       formattedTitle +
   44       rule.paths
   45         .map((p) => {
   46           return (
   47             p.path +
   48             (p.reason
   49               ? '\nReason: ' +
   50                 p.reason +
   51                 '\nExpires: ' +
   52                 p.expires.toUTCString() +
   53                 '\n'
   54               : '') +
   55             '\n'
   56           );
   57         })
   58         .join('')
   59         .replace(/\s*$/, '')
   60     );
   61   };
   62 }