"Fossies" - the Fresh Open Source Software Archive

Member "cli-1.1260.0/src/lib/ecosystems/policy.ts" (4 Dec 2023, 2049 Bytes) of package /linux/misc/snyk-cli-1.1260.0.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 * as path from 'path';
    2 
    3 import { SupportedPackageManagers } from '../package-managers';
    4 import { findAndLoadPolicy } from '../policy';
    5 import { Options, PolicyOptions } from '../types';
    6 import { Issue, IssuesData, ScanResult } from './types';
    7 import { Policy } from '../policy/find-and-load-policy';
    8 
    9 export async function findAndLoadPolicyForScanResult(
   10   scanResult: ScanResult,
   11   options: Options & PolicyOptions,
   12 ): Promise<object | undefined> {
   13   const targetFileRelativePath = scanResult.identity.targetFile
   14     ? path.join(path.resolve(`${options.path}`), scanResult.identity.targetFile)
   15     : undefined;
   16   const targetFileDir = targetFileRelativePath
   17     ? path.parse(targetFileRelativePath).dir
   18     : undefined;
   19   const scanType = options.docker
   20     ? 'docker'
   21     : (scanResult.identity.type as SupportedPackageManagers);
   22   // TODO: fix this and send only send when we used resolve-deps for node
   23   // it should be a ExpandedPkgTree type instead
   24   const packageExpanded = undefined;
   25 
   26   const policy = (await findAndLoadPolicy(
   27     options.path,
   28     scanType,
   29     options,
   30     packageExpanded,
   31     targetFileDir,
   32   )) as object | undefined; // TODO: findAndLoadPolicy() does not return a string!
   33   return policy;
   34 }
   35 
   36 export function filterIgnoredIssues(
   37   issues: Issue[],
   38   issuesData: IssuesData,
   39   policy?: Policy,
   40 ): [Issue[], IssuesData] {
   41   if (!policy?.ignore) {
   42     return [issues, issuesData];
   43   }
   44 
   45   const filteredIssuesData: IssuesData = { ...issuesData };
   46   const filteredIssues: Issue[] = issues.filter((issue) => {
   47     const ignoredIssue = policy.ignore[issue.issueId];
   48     if (!ignoredIssue) {
   49       return true;
   50     }
   51 
   52     const allResourcesRule = ignoredIssue.find((element) => '*' in element);
   53     if (!allResourcesRule) {
   54       return true;
   55     }
   56 
   57     const expiredIgnoreRule =
   58       new Date(allResourcesRule['*'].expires) < new Date();
   59     if (!expiredIgnoreRule) {
   60       delete filteredIssuesData[issue.issueId];
   61       return false;
   62     }
   63 
   64     return true;
   65   });
   66 
   67   return [filteredIssues, filteredIssuesData];
   68 }