How to use the @azure/core-http.getDefaultProxySettings function in @azure/core-http

To help you get started, we’ve selected a few @azure/core-http examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Azure / azure-sdk-for-js / sdk / keyvault / keyvault-secrets / samples / challenge.ts View on Github external
async function main(): Promise {
  // DefaultAzureCredential expects the following three environment variables:
  // - AZURE_TENANT_ID: The tenant ID in Azure Active Directory
  // - AZURE_CLIENT_ID: The application (client) ID registered in the AAD tenant
  // - AZURE_CLIENT_SECRET: The client secret for the registered application
  const credential = new DefaultAzureCredential();
  const retryOptions: any = {};
  const pipelineOptions: any = {};
  const requestPolicyFactories: RequestPolicyFactory[] = [
    proxyPolicy(getDefaultProxySettings((pipelineOptions.proxyOptions || {}).proxySettings)),
    userAgentPolicy({ value: "" }),
    generateClientRequestIdPolicy(),
    deserializationPolicy(), // Default deserializationPolicy is provided by protocol layer
    throttlingRetryPolicy(),
    systemErrorRetryPolicy(),
    exponentialRetryPolicy(
      retryOptions.retryCount,
      retryOptions.retryIntervalInMS,
      RetryConstants.MIN_RETRY_INTERVAL_MS, // Minimum retry interval to prevent frequent retries
      retryOptions.maxRetryDelayInMs
    ),
    redirectPolicy(),

    challengeBasedAuthenticationPolicy(credential)
  ];
github Azure / azure-sdk-for-js / sdk / storage / storage-file / src / Pipeline.ts View on Github external
// changes made by other factories (like UniqueRequestIDPolicyFactory)
  const factories: RequestPolicyFactory[] = [
    new KeepAlivePolicyFactory(pipelineOptions.keepAliveOptions),
    new TelemetryPolicyFactory(pipelineOptions.telemetry),
    new UniqueRequestIDPolicyFactory(),
    new BrowserPolicyFactory(),
    deserializationPolicy(), // Default deserializationPolicy is provided by protocol layer
    new RetryPolicyFactory(pipelineOptions.retryOptions),
    new LoggingPolicyFactory()
  ];

  if (isNode) {
    // ProxyPolicy is only avaiable in Node.js runtime, not in browsers
    let proxySettings: ProxySettings | undefined;
    if (typeof pipelineOptions.proxy === "string") {
      proxySettings = getDefaultProxySettings(pipelineOptions.proxy);
    } else {
      proxySettings = pipelineOptions.proxy;
    }
    factories.push(proxyPolicy(proxySettings));
  }
  factories.push(credential);

  return new Pipeline(factories, {
    HTTPClient: pipelineOptions.httpClient,
    logger: pipelineOptions.logger
  });
}
github Azure / azure-sdk-for-js / sdk / storage / storage-file / src / Pipeline.ts View on Github external
new UniqueRequestIDPolicyFactory(),
    new BrowserPolicyFactory(),
    deserializationPolicy(), // Default deserializationPolicy is provided by protocol layer
    new RetryPolicyFactory(pipelineOptions.retryOptions),
    logPolicy({
      logger: logger.info,
      allowedHeaderNames: StorageFileLoggingAllowedHeaderNames,
      allowedQueryParameters: StorageFileLoggingAllowedQueryParameters
    })
  ];

  if (isNode) {
    // ProxyPolicy is only avaiable in Node.js runtime, not in browsers
    let proxySettings: ProxySettings | undefined;
    if (typeof pipelineOptions.proxy === "string" || !pipelineOptions.proxy) {
      proxySettings = getDefaultProxySettings(pipelineOptions.proxy);
    } else {
      proxySettings = pipelineOptions.proxy;
    }
    factories.push(proxyPolicy(proxySettings));
  }
  factories.push(credential);

  return new Pipeline(factories, {
    HttpClient: pipelineOptions.httpClient,
    logger: pipelineOptions.logger
  });
}
github Azure / azure-sdk-for-js / sdk / storage / storage-Pipeline.ts View on Github external
// changes made by other factories (like UniqueRequestIDPolicyFactory)
  const factories: RequestPolicyFactory[] = [
    new KeepAlivePolicyFactory(pipelineOptions.keepAliveOptions),
    new TelemetryPolicyFactory(pipelineOptions.telemetry),
    new UniqueRequestIDPolicyFactory(),
    new BrowserPolicyFactory(),
    deserializationPolicy(), // Default deserializationPolicy is provided by protocol layer
    new RetryPolicyFactory(pipelineOptions.retryOptions),
    new LoggingPolicyFactory()
  ];

  if (isNode) {
    // ProxyPolicy is only avaiable in Node.js runtime, not in browsers
    let proxySettings: ProxySettings | undefined;
    if (typeof pipelineOptions.proxy === "string") {
      proxySettings = getDefaultProxySettings(pipelineOptions.proxy);
    } else {
      proxySettings = pipelineOptions.proxy;
    }
    factories.push(proxyPolicy(proxySettings));
  }
  factories.push(
    isTokenCredential(credential)
      ? bearerTokenAuthenticationPolicy(credential, "https://storage.azure.com/.default")
      : credential
  );

  return new Pipeline(factories, {
    HTTPClient: pipelineOptions.httpClient,
    logger: pipelineOptions.logger
  });
}