UNPKG

aws-cdk

Version:

AWS CDK Toolkit CLI, the command line tool for CDK apps

112 lines (111 loc) • 4.5 kB
import { ProxyAgent } from 'proxy-agent'; /** * Validate a proxy address up front. * * `proxy-agent` only rejects an address with a missing or unsupported protocol * lazily, on the first request, so without `-vvv` the CLI appears to hang or * fails later with a misleading error (e.g. missing credentials). Fail fast * here with an actionable message instead. */ export declare function validateProxyAddress(proxyAddress: string): void; /** * Coerce a raw network setting into a value the rest of the CLI can rely on. * * `Settings.get()` is untyped and surfaces an unset `--proxy` or `--ca-bundle-path` as either * `undefined` or an empty array, depending on how it was parsed. An empty STRING is a different * thing: `--proxy ''` means "go direct, ignore the proxy environment variables", so it has to survive * normalization. Anything that is not a string counts as unconfigured, which is what makes the * environment the fallback. * * Applied at the point these settings enter typed code, for two reasons. An empty array is truthy, so * it slips past every `if (value)` guard downstream and then fails somewhere unhelpful -- * `path.resolve([])` throws a `TypeError` that the CA-bundle resolver swallows, silently discarding * the bundle. And both values now cross a process boundary into the detached telemetry sender, which * has no access to the settings to re-derive them. */ export declare function normalizeNetworkSetting(raw: unknown): string | undefined; /** * Options for proxy-agent SDKs */ interface ProxyAgentOptions { /** * Proxy address to use * * @default No proxy */ readonly proxyAddress?: string; /** * A path to a certificate bundle that contains a cert to be trusted. * * @default - resolved from the environment and the shared AWS config files */ readonly caBundlePath?: string; /** * The AWS profile whose `ca_bundle` setting is consulted when no CA bundle is configured explicitly * or through `AWS_CA_BUNDLE`. * * @default - `AWS_PROFILE`, then `AWS_DEFAULT_PROFILE`, then `default` */ readonly profile?: string; } /** * The proxy configuration resolved for this invocation. */ export interface ResolvedProxyAgent { /** * The agent to pass to anything making HTTPS requests in this process. */ readonly agent: ProxyAgent; /** * Absolute path to the resolved CA bundle, if one was configured and exists on disk. * * Exposed because `agent` cannot cross a process boundary: the detached telemetry sender builds its * own and needs to be told which bundle to trust. The path travels rather than the bytes, because a * system bundle is routinely ~190KB. * * @default - no CA bundle was configured, or the configured one does not exist */ readonly caBundlePath?: string; } /** * The part of `IoHelper` that proxy resolution needs. * * Structural so the detached telemetry sender, which has no IoHost, can pass a writer that goes to * stderr instead. A full `IoHelper` satisfies this as-is. */ export interface ProxyAgentDiagnostics { readonly defaults: { debug(message: string): Promise<void>; }; } export declare class ProxyAgentProvider { private readonly ioHelper; constructor(ioHelper: ProxyAgentDiagnostics); create(options: ProxyAgentOptions): Promise<ResolvedProxyAgent>; /** * Resolve the configured CA bundle to an absolute path, or undefined if there isn't a usable one. * * Absolute because the path is handed to the detached sender, which runs from a different cwd. */ private resolveCABundlePath; private tryReadCABundle; /** * Find a CA certificate bundle path when none is given explicitly. * * The order is: the `AWS_CA_BUNDLE` environment variable, then the `ca_bundle` setting * of the active profile in the shared credentials/config files, then the `REQUESTS_CA_BUNDLE` * environment variable. * * The profile is picked the way `AwsCliCompatible` in toolkit-lib picks it: `--profile`, then * `AWS_PROFILE`, then `AWS_DEFAULT_PROFILE`, then `default`. */ private caBundlePathFromEnvironment; /** * The `ca_bundle` setting of a profile in the shared ini files. * * The credentials file is consulted before the config file, the same order `AwsCliCompatible` * uses for the region. */ private caBundlePathFromProfile; } export {};