"Fossies" - the Fresh Open Source Software Archive

Member "cli-1.1280.1/src/lib/config/index.ts" (20 Feb 2024, 2466 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 * as snykConfig from 'snyk-config';
    2 import { config as userConfig } from '../user-config';
    3 import {
    4   getBaseApiUrl,
    5   getRestApiUrl,
    6   getV1ApiUrl,
    7   getHiddenApiUrl,
    8   getRootUrl,
    9 } from './api-url';
   10 import { getOrganizationID } from '../organization';
   11 
   12 const DEFAULT_TIMEOUT = 5 * 60; // in seconds
   13 interface Config {
   14   PRUNE_DEPS_THRESHOLD: number;
   15   MAX_PATH_COUNT: number;
   16   API: string;
   17   api: string;
   18   API_REST_URL: string;
   19   API_HIDDEN_URL: string;
   20   // deprecated, use API_REST_URL instead
   21   API_V3_URL?: string;
   22   disableSuggestions: string;
   23   org: string;
   24   orgId?: string;
   25   ROOT: string;
   26   timeout: number;
   27   PROJECT_NAME: string;
   28   TOKEN: string;
   29   CODE_CLIENT_PROXY_URL: string;
   30   DISABLE_ANALYTICS: unknown;
   31   CACHE_PATH?: string;
   32   DRIFTCTL_PATH?: string;
   33   DRIFTCTL_URL?: string;
   34   IAC_BUNDLE_PATH?: string;
   35   IAC_POLICY_ENGINE_PATH?: string;
   36   IAC_RULES_CLIENT_URL?: string;
   37   PUBLIC_VULN_DB_URL: string;
   38 }
   39 
   40 // TODO: fix the types!
   41 const config = (snykConfig.loadConfig(
   42   __dirname + '/../..',
   43 ) as unknown) as Config;
   44 const defaultApiUrl = 'https://api.snyk.io';
   45 
   46 const configDefinedApiUrl = userConfig.get('endpoint');
   47 const envvarDefinedApiUrl = process.env.SNYK_API;
   48 
   49 const snykApiBaseUrl = getBaseApiUrl(
   50   defaultApiUrl,
   51   envvarDefinedApiUrl,
   52   configDefinedApiUrl,
   53 );
   54 config.API = getV1ApiUrl(snykApiBaseUrl);
   55 
   56 // API_V3_URL is deprecated, but maintaining backwards compatibility
   57 config.API_REST_URL = getRestApiUrl(
   58   snykApiBaseUrl,
   59   process.env.API_REST_URL || config.API_REST_URL,
   60   process.env.API_V3_URL || config.API_V3_URL,
   61 );
   62 
   63 config.API_HIDDEN_URL = getHiddenApiUrl(config.API_REST_URL);
   64 
   65 const disableSuggestions = userConfig.get('disableSuggestions');
   66 if (disableSuggestions) {
   67   config.disableSuggestions = disableSuggestions;
   68 }
   69 
   70 const org = userConfig.get('org');
   71 if (!config.org && org) {
   72   config.org = org;
   73 }
   74 
   75 config.orgId = getOrganizationID();
   76 
   77 // client request timeout
   78 // to change, set this config key to the desired value in seconds
   79 // invalid (non-numeric) value will fallback to the default
   80 const timeout = userConfig.get('timeout');
   81 if (!config.timeout) {
   82   config.timeout = timeout && +timeout ? +timeout : DEFAULT_TIMEOUT;
   83 }
   84 
   85 // this is a bit of an assumption that our web site origin is the same
   86 // as our API origin, but for now it's okay - RS 2015-10-16
   87 if (!config.ROOT) {
   88   config.ROOT = getRootUrl(config.API);
   89 }
   90 
   91 config.PUBLIC_VULN_DB_URL = 'https://security.snyk.io';
   92 
   93 export default config;