"Fossies" - the Fresh Open Source Software Archive

Member "cli-1.1280.1/src/lib/plugins/sast/settings.ts" (20 Feb 2024, 1374 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 { Options } from '../../types';
    2 import { SastSettings } from './types';
    3 import config from '../../config';
    4 import { getSastSettingsForOrg, trackUsage } from './checks';
    5 
    6 import {
    7   AuthFailedError,
    8   FailedToRunTestError,
    9   FeatureNotSupportedForOrgError,
   10   NotFoundError,
   11 } from '../../errors';
   12 
   13 export async function getSastSettings(options: Options): Promise<SastSettings> {
   14   const org = options.org || config.org;
   15 
   16   // This is an unexpected path, code plugin executed for non-code command.
   17   if (!options.code) {
   18     throw new FeatureNotSupportedForOrgError(org);
   19   }
   20 
   21   const sastSettingsResponse = await getSastSettingsForOrg(org);
   22 
   23   if (
   24     sastSettingsResponse?.code === 401 ||
   25     sastSettingsResponse?.code === 403
   26   ) {
   27     throw AuthFailedError(
   28       sastSettingsResponse.error,
   29       sastSettingsResponse.code,
   30     );
   31   }
   32 
   33   if (sastSettingsResponse?.code === 404) {
   34     throw new NotFoundError(sastSettingsResponse?.userMessage);
   35   }
   36 
   37   if (!sastSettingsResponse.sastEnabled) {
   38     throw new FeatureNotSupportedForOrgError(
   39       org,
   40       'Snyk Code',
   41       'enable in Settings > Snyk Code',
   42     );
   43   }
   44 
   45   const trackUsageResponse = await trackUsage(org);
   46   if (trackUsageResponse.code === 429) {
   47     throw new FailedToRunTestError(
   48       trackUsageResponse.userMessage,
   49       trackUsageResponse.code,
   50     );
   51   }
   52   return sastSettingsResponse;
   53 }