Skip to content

Commit

Permalink
feat(clients): change runtime config from constant to functional
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanZhengYP committed Jul 15, 2021
1 parent 39484e5 commit 46a36f3
Show file tree
Hide file tree
Showing 1,370 changed files with 21,115 additions and 16,460 deletions.
7 changes: 2 additions & 5 deletions clients/client-accessanalyzer/AccessAnalyzerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import { UntagResourceCommandInput, UntagResourceCommandOutput } from "./command
import { UpdateArchiveRuleCommandInput, UpdateArchiveRuleCommandOutput } from "./commands/UpdateArchiveRuleCommand";
import { UpdateFindingsCommandInput, UpdateFindingsCommandOutput } from "./commands/UpdateFindingsCommand";
import { ValidatePolicyCommandInput, ValidatePolicyCommandOutput } from "./commands/ValidatePolicyCommand";
import { ClientDefaultValues as __ClientDefaultValues } from "./runtimeConfig";
import { getRuntimeConfig as __getRuntimeConfig } from "./runtimeConfig";
import {
EndpointsInputConfig,
EndpointsResolvedConfig,
Expand Down Expand Up @@ -323,10 +323,7 @@ export class AccessAnalyzerClient extends __Client<
readonly config: AccessAnalyzerClientResolvedConfig;

constructor(configuration: AccessAnalyzerClientConfig) {
let _config_0 = {
...__ClientDefaultValues,
...configuration,
};
let _config_0 = __getRuntimeConfig(configuration);
let _config_1 = resolveRegionConfig(_config_0);
let _config_2 = resolveEndpointsConfig(_config_1);
let _config_3 = resolveRetryConfig(_config_2);
Expand Down
49 changes: 28 additions & 21 deletions clients/client-accessanalyzer/runtimeConfig.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,40 @@ import { Sha256 } from "@aws-crypto/sha256-browser";
import { FetchHttpHandler, streamCollector } from "@aws-sdk/fetch-http-handler";
import { invalidProvider } from "@aws-sdk/invalid-dependency";
import { DEFAULT_MAX_ATTEMPTS, DEFAULT_RETRY_MODE } from "@aws-sdk/middleware-retry";
import { nullishCoalescing as coalesce } from "@aws-sdk/smithy-client";
import { fromBase64, toBase64 } from "@aws-sdk/util-base64-browser";
import { calculateBodyLength } from "@aws-sdk/util-body-length-browser";
import { defaultUserAgent } from "@aws-sdk/util-user-agent-browser";
import { fromUtf8, toUtf8 } from "@aws-sdk/util-utf8-browser";
import { ClientDefaults } from "./AccessAnalyzerClient";
import { ClientSharedValues } from "./runtimeConfig.shared";
import { AccessAnalyzerClientConfig } from "./AccessAnalyzerClient";
import { getRuntimeConfig as getSharedRuntimeConfig } from "./runtimeConfig.shared";

/**
* @internal
*/
export const ClientDefaultValues: Required<ClientDefaults> = {
...ClientSharedValues,
runtime: "browser",
base64Decoder: fromBase64,
base64Encoder: toBase64,
bodyLengthChecker: calculateBodyLength,
credentialDefaultProvider: (_: unknown) => () => Promise.reject(new Error("Credential is missing")),
defaultUserAgentProvider: defaultUserAgent({
serviceId: ClientSharedValues.serviceId,
clientVersion: packageInfo.version,
}),
maxAttempts: DEFAULT_MAX_ATTEMPTS,
region: invalidProvider("Region is missing"),
requestHandler: new FetchHttpHandler(),
retryModeProvider: () => Promise.resolve(DEFAULT_RETRY_MODE),
sha256: Sha256,
streamCollector,
utf8Decoder: fromUtf8,
utf8Encoder: toUtf8,
export const getRuntimeConfig = (config: AccessAnalyzerClientConfig) => {
const clientSharedValues = getSharedRuntimeConfig(config);
return {
...clientSharedValues,
runtime: "browser",
base64Decoder: coalesce(config.base64Decoder, fromBase64),
base64Encoder: coalesce(config.base64Encoder, toBase64),
bodyLengthChecker: coalesce(config.bodyLengthChecker, calculateBodyLength),
credentialDefaultProvider: coalesce(
config.credentialDefaultProvider,
(_: unknown) => () => Promise.reject(new Error("Credential is missing"))
),
defaultUserAgentProvider: coalesce(
config.defaultUserAgentProvider,
defaultUserAgent({ serviceId: clientSharedValues.serviceId, clientVersion: packageInfo.version })
),
maxAttempts: coalesce(config.maxAttempts, DEFAULT_MAX_ATTEMPTS),
region: coalesce(config.region, invalidProvider("Region is missing")),
requestHandler: coalesce(config.requestHandler, new FetchHttpHandler()),
retryModeProvider: coalesce(config.retryModeProvider, () => Promise.resolve(DEFAULT_RETRY_MODE)),
sha256: coalesce(config.sha256, Sha256),
streamCollector: coalesce(config.streamCollector, streamCollector),
utf8Decoder: coalesce(config.utf8Decoder, fromUtf8),
utf8Encoder: coalesce(config.utf8Encoder, toUtf8),
};
};
16 changes: 10 additions & 6 deletions clients/client-accessanalyzer/runtimeConfig.native.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { Sha256 } from "@aws-crypto/sha256-js";
import { ClientDefaults } from "./AccessAnalyzerClient";
import { ClientDefaultValues as BrowserDefaults } from "./runtimeConfig.browser";
import { nullishCoalescing as coalesce } from "@aws-sdk/smithy-client";
import { AccessAnalyzerClientConfig } from "./AccessAnalyzerClient";
import { getRuntimeConfig as getBrowserRuntimeConfig } from "./runtimeConfig.browser";

/**
* @internal
*/
export const ClientDefaultValues: Required<ClientDefaults> = {
...BrowserDefaults,
runtime: "react-native",
sha256: Sha256,
export const getRuntimeConfig = (config: AccessAnalyzerClientConfig) => {
const browserDefaults = getBrowserRuntimeConfig(config);
return {
...browserDefaults,
runtime: "react-native",
sha256: coalesce(config.sha256, Sha256),
};
};
16 changes: 9 additions & 7 deletions clients/client-accessanalyzer/runtimeConfig.shared.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { defaultRegionInfoProvider } from "./endpoints";
import { nullishCoalescing as coalesce } from "@aws-sdk/smithy-client";
import { Logger as __Logger } from "@aws-sdk/types";
import { parseUrl } from "@aws-sdk/url-parser";
import { AccessAnalyzerClientConfig } from "./AccessAnalyzerClient";

/**
* @internal
*/
export const ClientSharedValues = {
export const getRuntimeConfig = (config: AccessAnalyzerClientConfig) => ({
apiVersion: "2019-11-01",
disableHostPrefix: false,
logger: {} as __Logger,
regionInfoProvider: defaultRegionInfoProvider,
serviceId: "AccessAnalyzer",
urlParser: parseUrl,
};
disableHostPrefix: coalesce(config.disableHostPrefix, false),
logger: coalesce(config.logger, {} as __Logger),
regionInfoProvider: coalesce(config.regionInfoProvider, defaultRegionInfoProvider),
serviceId: coalesce(config.serviceId, "AccessAnalyzer"),
urlParser: coalesce(config.urlParser, parseUrl),
});
49 changes: 28 additions & 21 deletions clients/client-accessanalyzer/runtimeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,40 @@ import { Hash } from "@aws-sdk/hash-node";
import { NODE_MAX_ATTEMPT_CONFIG_OPTIONS, NODE_RETRY_MODE_CONFIG_OPTIONS } from "@aws-sdk/middleware-retry";
import { loadConfig as loadNodeConfig } from "@aws-sdk/node-config-provider";
import { NodeHttpHandler, streamCollector } from "@aws-sdk/node-http-handler";
import { nullishCoalescing as coalesce } from "@aws-sdk/smithy-client";
import { fromBase64, toBase64 } from "@aws-sdk/util-base64-node";
import { calculateBodyLength } from "@aws-sdk/util-body-length-node";
import { defaultUserAgent } from "@aws-sdk/util-user-agent-node";
import { fromUtf8, toUtf8 } from "@aws-sdk/util-utf8-node";
import { ClientDefaults } from "./AccessAnalyzerClient";
import { ClientSharedValues } from "./runtimeConfig.shared";
import { AccessAnalyzerClientConfig } from "./AccessAnalyzerClient";
import { getRuntimeConfig as getSharedRuntimeConfig } from "./runtimeConfig.shared";

/**
* @internal
*/
export const ClientDefaultValues: Required<ClientDefaults> = {
...ClientSharedValues,
runtime: "node",
base64Decoder: fromBase64,
base64Encoder: toBase64,
bodyLengthChecker: calculateBodyLength,
credentialDefaultProvider: decorateDefaultCredentialProvider(credentialDefaultProvider),
defaultUserAgentProvider: defaultUserAgent({
serviceId: ClientSharedValues.serviceId,
clientVersion: packageInfo.version,
}),
maxAttempts: loadNodeConfig(NODE_MAX_ATTEMPT_CONFIG_OPTIONS),
region: loadNodeConfig(NODE_REGION_CONFIG_OPTIONS, NODE_REGION_CONFIG_FILE_OPTIONS),
requestHandler: new NodeHttpHandler(),
retryModeProvider: loadNodeConfig(NODE_RETRY_MODE_CONFIG_OPTIONS),
sha256: Hash.bind(null, "sha256"),
streamCollector,
utf8Decoder: fromUtf8,
utf8Encoder: toUtf8,
export const getRuntimeConfig = (config: AccessAnalyzerClientConfig) => {
const clientSharedValues = getSharedRuntimeConfig(config);
return {
...clientSharedValues,
runtime: "node",
base64Decoder: coalesce(config.base64Decoder, fromBase64),
base64Encoder: coalesce(config.base64Encoder, toBase64),
bodyLengthChecker: coalesce(config.bodyLengthChecker, calculateBodyLength),
credentialDefaultProvider: coalesce(
config.credentialDefaultProvider,
decorateDefaultCredentialProvider(credentialDefaultProvider)
),
defaultUserAgentProvider: coalesce(
config.defaultUserAgentProvider,
defaultUserAgent({ serviceId: clientSharedValues.serviceId, clientVersion: packageInfo.version })
),
maxAttempts: coalesce(config.maxAttempts, loadNodeConfig(NODE_MAX_ATTEMPT_CONFIG_OPTIONS)),
region: coalesce(config.region, loadNodeConfig(NODE_REGION_CONFIG_OPTIONS, NODE_REGION_CONFIG_FILE_OPTIONS)),
requestHandler: coalesce(config.requestHandler, new NodeHttpHandler()),
retryModeProvider: coalesce(config.retryModeProvider, loadNodeConfig(NODE_RETRY_MODE_CONFIG_OPTIONS)),
sha256: coalesce(config.sha256, Hash.bind(null, "sha256")),
streamCollector: coalesce(config.streamCollector, streamCollector),
utf8Decoder: coalesce(config.utf8Decoder, fromUtf8),
utf8Encoder: coalesce(config.utf8Encoder, toUtf8),
};
};
7 changes: 2 additions & 5 deletions clients/client-acm-pca/ACMPCAClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import {
UpdateCertificateAuthorityCommandInput,
UpdateCertificateAuthorityCommandOutput,
} from "./commands/UpdateCertificateAuthorityCommand";
import { ClientDefaultValues as __ClientDefaultValues } from "./runtimeConfig";
import { getRuntimeConfig as __getRuntimeConfig } from "./runtimeConfig";
import {
EndpointsInputConfig,
EndpointsResolvedConfig,
Expand Down Expand Up @@ -327,10 +327,7 @@ export class ACMPCAClient extends __Client<
readonly config: ACMPCAClientResolvedConfig;

constructor(configuration: ACMPCAClientConfig) {
let _config_0 = {
...__ClientDefaultValues,
...configuration,
};
let _config_0 = __getRuntimeConfig(configuration);
let _config_1 = resolveRegionConfig(_config_0);
let _config_2 = resolveEndpointsConfig(_config_1);
let _config_3 = resolveRetryConfig(_config_2);
Expand Down
49 changes: 28 additions & 21 deletions clients/client-acm-pca/runtimeConfig.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,40 @@ import { Sha256 } from "@aws-crypto/sha256-browser";
import { FetchHttpHandler, streamCollector } from "@aws-sdk/fetch-http-handler";
import { invalidProvider } from "@aws-sdk/invalid-dependency";
import { DEFAULT_MAX_ATTEMPTS, DEFAULT_RETRY_MODE } from "@aws-sdk/middleware-retry";
import { nullishCoalescing as coalesce } from "@aws-sdk/smithy-client";
import { fromBase64, toBase64 } from "@aws-sdk/util-base64-browser";
import { calculateBodyLength } from "@aws-sdk/util-body-length-browser";
import { defaultUserAgent } from "@aws-sdk/util-user-agent-browser";
import { fromUtf8, toUtf8 } from "@aws-sdk/util-utf8-browser";
import { ClientDefaults } from "./ACMPCAClient";
import { ClientSharedValues } from "./runtimeConfig.shared";
import { ACMPCAClientConfig } from "./ACMPCAClient";
import { getRuntimeConfig as getSharedRuntimeConfig } from "./runtimeConfig.shared";

/**
* @internal
*/
export const ClientDefaultValues: Required<ClientDefaults> = {
...ClientSharedValues,
runtime: "browser",
base64Decoder: fromBase64,
base64Encoder: toBase64,
bodyLengthChecker: calculateBodyLength,
credentialDefaultProvider: (_: unknown) => () => Promise.reject(new Error("Credential is missing")),
defaultUserAgentProvider: defaultUserAgent({
serviceId: ClientSharedValues.serviceId,
clientVersion: packageInfo.version,
}),
maxAttempts: DEFAULT_MAX_ATTEMPTS,
region: invalidProvider("Region is missing"),
requestHandler: new FetchHttpHandler(),
retryModeProvider: () => Promise.resolve(DEFAULT_RETRY_MODE),
sha256: Sha256,
streamCollector,
utf8Decoder: fromUtf8,
utf8Encoder: toUtf8,
export const getRuntimeConfig = (config: ACMPCAClientConfig) => {
const clientSharedValues = getSharedRuntimeConfig(config);
return {
...clientSharedValues,
runtime: "browser",
base64Decoder: coalesce(config.base64Decoder, fromBase64),
base64Encoder: coalesce(config.base64Encoder, toBase64),
bodyLengthChecker: coalesce(config.bodyLengthChecker, calculateBodyLength),
credentialDefaultProvider: coalesce(
config.credentialDefaultProvider,
(_: unknown) => () => Promise.reject(new Error("Credential is missing"))
),
defaultUserAgentProvider: coalesce(
config.defaultUserAgentProvider,
defaultUserAgent({ serviceId: clientSharedValues.serviceId, clientVersion: packageInfo.version })
),
maxAttempts: coalesce(config.maxAttempts, DEFAULT_MAX_ATTEMPTS),
region: coalesce(config.region, invalidProvider("Region is missing")),
requestHandler: coalesce(config.requestHandler, new FetchHttpHandler()),
retryModeProvider: coalesce(config.retryModeProvider, () => Promise.resolve(DEFAULT_RETRY_MODE)),
sha256: coalesce(config.sha256, Sha256),
streamCollector: coalesce(config.streamCollector, streamCollector),
utf8Decoder: coalesce(config.utf8Decoder, fromUtf8),
utf8Encoder: coalesce(config.utf8Encoder, toUtf8),
};
};
16 changes: 10 additions & 6 deletions clients/client-acm-pca/runtimeConfig.native.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { Sha256 } from "@aws-crypto/sha256-js";
import { ClientDefaults } from "./ACMPCAClient";
import { ClientDefaultValues as BrowserDefaults } from "./runtimeConfig.browser";
import { nullishCoalescing as coalesce } from "@aws-sdk/smithy-client";
import { ACMPCAClientConfig } from "./ACMPCAClient";
import { getRuntimeConfig as getBrowserRuntimeConfig } from "./runtimeConfig.browser";

/**
* @internal
*/
export const ClientDefaultValues: Required<ClientDefaults> = {
...BrowserDefaults,
runtime: "react-native",
sha256: Sha256,
export const getRuntimeConfig = (config: ACMPCAClientConfig) => {
const browserDefaults = getBrowserRuntimeConfig(config);
return {
...browserDefaults,
runtime: "react-native",
sha256: coalesce(config.sha256, Sha256),
};
};
16 changes: 9 additions & 7 deletions clients/client-acm-pca/runtimeConfig.shared.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { defaultRegionInfoProvider } from "./endpoints";
import { nullishCoalescing as coalesce } from "@aws-sdk/smithy-client";
import { Logger as __Logger } from "@aws-sdk/types";
import { parseUrl } from "@aws-sdk/url-parser";
import { ACMPCAClientConfig } from "./ACMPCAClient";

/**
* @internal
*/
export const ClientSharedValues = {
export const getRuntimeConfig = (config: ACMPCAClientConfig) => ({
apiVersion: "2017-08-22",
disableHostPrefix: false,
logger: {} as __Logger,
regionInfoProvider: defaultRegionInfoProvider,
serviceId: "ACM PCA",
urlParser: parseUrl,
};
disableHostPrefix: coalesce(config.disableHostPrefix, false),
logger: coalesce(config.logger, {} as __Logger),
regionInfoProvider: coalesce(config.regionInfoProvider, defaultRegionInfoProvider),
serviceId: coalesce(config.serviceId, "ACM PCA"),
urlParser: coalesce(config.urlParser, parseUrl),
});
49 changes: 28 additions & 21 deletions clients/client-acm-pca/runtimeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,40 @@ import { Hash } from "@aws-sdk/hash-node";
import { NODE_MAX_ATTEMPT_CONFIG_OPTIONS, NODE_RETRY_MODE_CONFIG_OPTIONS } from "@aws-sdk/middleware-retry";
import { loadConfig as loadNodeConfig } from "@aws-sdk/node-config-provider";
import { NodeHttpHandler, streamCollector } from "@aws-sdk/node-http-handler";
import { nullishCoalescing as coalesce } from "@aws-sdk/smithy-client";
import { fromBase64, toBase64 } from "@aws-sdk/util-base64-node";
import { calculateBodyLength } from "@aws-sdk/util-body-length-node";
import { defaultUserAgent } from "@aws-sdk/util-user-agent-node";
import { fromUtf8, toUtf8 } from "@aws-sdk/util-utf8-node";
import { ClientDefaults } from "./ACMPCAClient";
import { ClientSharedValues } from "./runtimeConfig.shared";
import { ACMPCAClientConfig } from "./ACMPCAClient";
import { getRuntimeConfig as getSharedRuntimeConfig } from "./runtimeConfig.shared";

/**
* @internal
*/
export const ClientDefaultValues: Required<ClientDefaults> = {
...ClientSharedValues,
runtime: "node",
base64Decoder: fromBase64,
base64Encoder: toBase64,
bodyLengthChecker: calculateBodyLength,
credentialDefaultProvider: decorateDefaultCredentialProvider(credentialDefaultProvider),
defaultUserAgentProvider: defaultUserAgent({
serviceId: ClientSharedValues.serviceId,
clientVersion: packageInfo.version,
}),
maxAttempts: loadNodeConfig(NODE_MAX_ATTEMPT_CONFIG_OPTIONS),
region: loadNodeConfig(NODE_REGION_CONFIG_OPTIONS, NODE_REGION_CONFIG_FILE_OPTIONS),
requestHandler: new NodeHttpHandler(),
retryModeProvider: loadNodeConfig(NODE_RETRY_MODE_CONFIG_OPTIONS),
sha256: Hash.bind(null, "sha256"),
streamCollector,
utf8Decoder: fromUtf8,
utf8Encoder: toUtf8,
export const getRuntimeConfig = (config: ACMPCAClientConfig) => {
const clientSharedValues = getSharedRuntimeConfig(config);
return {
...clientSharedValues,
runtime: "node",
base64Decoder: coalesce(config.base64Decoder, fromBase64),
base64Encoder: coalesce(config.base64Encoder, toBase64),
bodyLengthChecker: coalesce(config.bodyLengthChecker, calculateBodyLength),
credentialDefaultProvider: coalesce(
config.credentialDefaultProvider,
decorateDefaultCredentialProvider(credentialDefaultProvider)
),
defaultUserAgentProvider: coalesce(
config.defaultUserAgentProvider,
defaultUserAgent({ serviceId: clientSharedValues.serviceId, clientVersion: packageInfo.version })
),
maxAttempts: coalesce(config.maxAttempts, loadNodeConfig(NODE_MAX_ATTEMPT_CONFIG_OPTIONS)),
region: coalesce(config.region, loadNodeConfig(NODE_REGION_CONFIG_OPTIONS, NODE_REGION_CONFIG_FILE_OPTIONS)),
requestHandler: coalesce(config.requestHandler, new NodeHttpHandler()),
retryModeProvider: coalesce(config.retryModeProvider, loadNodeConfig(NODE_RETRY_MODE_CONFIG_OPTIONS)),
sha256: coalesce(config.sha256, Hash.bind(null, "sha256")),
streamCollector: coalesce(config.streamCollector, streamCollector),
utf8Decoder: coalesce(config.utf8Decoder, fromUtf8),
utf8Encoder: coalesce(config.utf8Encoder, toUtf8),
};
};
Loading

0 comments on commit 46a36f3

Please sign in to comment.