Skip to content

Commit

Permalink
feat(clients): change runtime config from constant to provider functi…
Browse files Browse the repository at this point in the history
…ons (#2574)

* chore: update codegen to make runtime config functional

* feat(clients): change runtime config from constant to functional

* chore: use inline nullish coalescing instead of helper

* feat(clients): use inline nullish coalescing

* feat(clients): set configs not modeled in runtimeConfig

* test: fix codegen test
  • Loading branch information
AllanZhengYP authored Jul 22, 2021
1 parent e643735 commit 5eca565
Show file tree
Hide file tree
Showing 1,387 changed files with 19,284 additions and 16,526 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 @@ -324,10 +324,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
46 changes: 25 additions & 21 deletions clients/client-accessanalyzer/runtimeConfig.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,33 @@ 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,
...config,
runtime: "browser",
base64Decoder: config.base64Decoder ?? fromBase64,
base64Encoder: config.base64Encoder ?? toBase64,
bodyLengthChecker: config.bodyLengthChecker ?? calculateBodyLength,
credentialDefaultProvider:
config.credentialDefaultProvider ?? ((_: unknown) => () => Promise.reject(new Error("Credential is missing"))),
defaultUserAgentProvider:
config.defaultUserAgentProvider ??
defaultUserAgent({ serviceId: clientSharedValues.serviceId, clientVersion: packageInfo.version }),
maxAttempts: config.maxAttempts ?? DEFAULT_MAX_ATTEMPTS,
region: config.region ?? invalidProvider("Region is missing"),
requestHandler: config.requestHandler ?? new FetchHttpHandler(),
retryModeProvider: config.retryModeProvider ?? (() => Promise.resolve(DEFAULT_RETRY_MODE)),
sha256: config.sha256 ?? Sha256,
streamCollector: config.streamCollector ?? streamCollector,
utf8Decoder: config.utf8Decoder ?? fromUtf8,
utf8Encoder: 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 { 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,
...config,
runtime: "react-native",
sha256: config.sha256 ?? Sha256,
};
};
15 changes: 8 additions & 7 deletions clients/client-accessanalyzer/runtimeConfig.shared.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { defaultRegionInfoProvider } from "./endpoints";
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: config.disableHostPrefix ?? false,
logger: config.logger ?? ({} as __Logger),
regionInfoProvider: config.regionInfoProvider ?? defaultRegionInfoProvider,
serviceId: config.serviceId ?? "AccessAnalyzer",
urlParser: config.urlParser ?? parseUrl,
});
46 changes: 25 additions & 21 deletions clients/client-accessanalyzer/runtimeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,33 @@ 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,
...config,
runtime: "node",
base64Decoder: config.base64Decoder ?? fromBase64,
base64Encoder: config.base64Encoder ?? toBase64,
bodyLengthChecker: config.bodyLengthChecker ?? calculateBodyLength,
credentialDefaultProvider:
config.credentialDefaultProvider ?? decorateDefaultCredentialProvider(credentialDefaultProvider),
defaultUserAgentProvider:
config.defaultUserAgentProvider ??
defaultUserAgent({ serviceId: clientSharedValues.serviceId, clientVersion: packageInfo.version }),
maxAttempts: config.maxAttempts ?? loadNodeConfig(NODE_MAX_ATTEMPT_CONFIG_OPTIONS),
region: config.region ?? loadNodeConfig(NODE_REGION_CONFIG_OPTIONS, NODE_REGION_CONFIG_FILE_OPTIONS),
requestHandler: config.requestHandler ?? new NodeHttpHandler(),
retryModeProvider: config.retryModeProvider ?? loadNodeConfig(NODE_RETRY_MODE_CONFIG_OPTIONS),
sha256: config.sha256 ?? Hash.bind(null, "sha256"),
streamCollector: config.streamCollector ?? streamCollector,
utf8Decoder: config.utf8Decoder ?? fromUtf8,
utf8Encoder: 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 @@ -328,10 +328,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
46 changes: 25 additions & 21 deletions clients/client-acm-pca/runtimeConfig.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,33 @@ 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,
...config,
runtime: "browser",
base64Decoder: config.base64Decoder ?? fromBase64,
base64Encoder: config.base64Encoder ?? toBase64,
bodyLengthChecker: config.bodyLengthChecker ?? calculateBodyLength,
credentialDefaultProvider:
config.credentialDefaultProvider ?? ((_: unknown) => () => Promise.reject(new Error("Credential is missing"))),
defaultUserAgentProvider:
config.defaultUserAgentProvider ??
defaultUserAgent({ serviceId: clientSharedValues.serviceId, clientVersion: packageInfo.version }),
maxAttempts: config.maxAttempts ?? DEFAULT_MAX_ATTEMPTS,
region: config.region ?? invalidProvider("Region is missing"),
requestHandler: config.requestHandler ?? new FetchHttpHandler(),
retryModeProvider: config.retryModeProvider ?? (() => Promise.resolve(DEFAULT_RETRY_MODE)),
sha256: config.sha256 ?? Sha256,
streamCollector: config.streamCollector ?? streamCollector,
utf8Decoder: config.utf8Decoder ?? fromUtf8,
utf8Encoder: 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 { 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,
...config,
runtime: "react-native",
sha256: config.sha256 ?? Sha256,
};
};
15 changes: 8 additions & 7 deletions clients/client-acm-pca/runtimeConfig.shared.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { defaultRegionInfoProvider } from "./endpoints";
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: config.disableHostPrefix ?? false,
logger: config.logger ?? ({} as __Logger),
regionInfoProvider: config.regionInfoProvider ?? defaultRegionInfoProvider,
serviceId: config.serviceId ?? "ACM PCA",
urlParser: config.urlParser ?? parseUrl,
});
46 changes: 25 additions & 21 deletions clients/client-acm-pca/runtimeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,33 @@ 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,
...config,
runtime: "node",
base64Decoder: config.base64Decoder ?? fromBase64,
base64Encoder: config.base64Encoder ?? toBase64,
bodyLengthChecker: config.bodyLengthChecker ?? calculateBodyLength,
credentialDefaultProvider:
config.credentialDefaultProvider ?? decorateDefaultCredentialProvider(credentialDefaultProvider),
defaultUserAgentProvider:
config.defaultUserAgentProvider ??
defaultUserAgent({ serviceId: clientSharedValues.serviceId, clientVersion: packageInfo.version }),
maxAttempts: config.maxAttempts ?? loadNodeConfig(NODE_MAX_ATTEMPT_CONFIG_OPTIONS),
region: config.region ?? loadNodeConfig(NODE_REGION_CONFIG_OPTIONS, NODE_REGION_CONFIG_FILE_OPTIONS),
requestHandler: config.requestHandler ?? new NodeHttpHandler(),
retryModeProvider: config.retryModeProvider ?? loadNodeConfig(NODE_RETRY_MODE_CONFIG_OPTIONS),
sha256: config.sha256 ?? Hash.bind(null, "sha256"),
streamCollector: config.streamCollector ?? streamCollector,
utf8Decoder: config.utf8Decoder ?? fromUtf8,
utf8Encoder: config.utf8Encoder ?? toUtf8,
};
};
7 changes: 2 additions & 5 deletions clients/client-acm/ACMClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
UpdateCertificateOptionsCommandInput,
UpdateCertificateOptionsCommandOutput,
} from "./commands/UpdateCertificateOptionsCommand";
import { ClientDefaultValues as __ClientDefaultValues } from "./runtimeConfig";
import { getRuntimeConfig as __getRuntimeConfig } from "./runtimeConfig";
import {
EndpointsInputConfig,
EndpointsResolvedConfig,
Expand Down Expand Up @@ -279,10 +279,7 @@ export class ACMClient extends __Client<
readonly config: ACMClientResolvedConfig;

constructor(configuration: ACMClientConfig) {
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
Loading

0 comments on commit 5eca565

Please sign in to comment.