Skip to content

Commit

Permalink
feat: standardize user agent value (#1775)
Browse files Browse the repository at this point in the history
* fix: update default useragent string to comply metrics requirements

* feat(util-user-agent-node): update node user agent provider to the latest

* feat(types): add user agent type

* feat(types): add useragent to handler exec context

* feat(util-user-agent-node): update node user agent provider to the latest design

* feat(util-user-agent-node): support app id and add unit tests

* feat(util-user-agent-browser): detect browser UA in new format

* feat(util-user-agent-browser): support react native user agent

* feat(middleware-user-agent): combine ua from context, default, and config into new sdk ua header

* feat(middleware-user-agent): add injectUserAgent plugin

* feat(middleware-user-agent): add retry mode metrics

* feat(util-user-agent-*): support non-AWS clients

* chore(codegen): consolidate user-agent customization to a codegen plugin

* fix(middleware-user-agent): remove injectUAPlugin because it's not used for now

* fix(util-user-agent-*): not to update version to 3.x.x

* feat(middleware-user-agent): lowercase service ids

* feat: rename defaultUserAgent config to defaultUserAgentProvider

* feat(client-*): update user-agent population and injecting
  • Loading branch information
AllanZhengYP authored Dec 19, 2020
1 parent 0011af2 commit 388b180
Show file tree
Hide file tree
Showing 1,035 changed files with 6,356 additions and 4,411 deletions.
27 changes: 15 additions & 12 deletions clients/client-accessanalyzer/AccessAnalyzerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import {
SmithyResolvedConfiguration as __SmithyResolvedConfiguration,
} from "@aws-sdk/smithy-client";
import {
Provider,
RegionInfoProvider,
Credentials as __Credentials,
Decoder as __Decoder,
Expand All @@ -72,6 +73,7 @@ import {
Provider as __Provider,
StreamCollector as __StreamCollector,
UrlParser as __UrlParser,
UserAgent as __UserAgent,
} from "@aws-sdk/types";

export type ServiceInputTypes =
Expand Down Expand Up @@ -161,11 +163,6 @@ export interface ClientDefaults extends Partial<__SmithyResolvedConfiguration<__
*/
utf8Encoder?: __Encoder;

/**
* The string that will be used to populate default value in 'User-Agent' header
*/
defaultUserAgent?: string;

/**
* The runtime environment
*/
Expand Down Expand Up @@ -207,6 +204,12 @@ export interface ClientDefaults extends Partial<__SmithyResolvedConfiguration<__
* Fetch related hostname, signing name or signing region with given region.
*/
regionInfoProvider?: RegionInfoProvider;

/**
* The provider populating default tracking information to be sent with `user-agent`, `x-amz-user-agent` header
* @internal
*/
defaultUserAgentProvider?: Provider<__UserAgent>;
}

export type AccessAnalyzerClientConfig = Partial<__SmithyConfiguration<__HttpHandlerOptions>> &
Expand All @@ -215,17 +218,17 @@ export type AccessAnalyzerClientConfig = Partial<__SmithyConfiguration<__HttpHan
EndpointsInputConfig &
AwsAuthInputConfig &
RetryInputConfig &
UserAgentInputConfig &
HostHeaderInputConfig;
HostHeaderInputConfig &
UserAgentInputConfig;

export type AccessAnalyzerClientResolvedConfig = __SmithyResolvedConfiguration<__HttpHandlerOptions> &
Required<ClientDefaults> &
RegionResolvedConfig &
EndpointsResolvedConfig &
AwsAuthResolvedConfig &
RetryResolvedConfig &
UserAgentResolvedConfig &
HostHeaderResolvedConfig;
HostHeaderResolvedConfig &
UserAgentResolvedConfig;

/**
* <p>AWS IAM Access Analyzer helps identify potential resource-access risks by enabling you to identify
Expand Down Expand Up @@ -253,16 +256,16 @@ export class AccessAnalyzerClient extends __Client<
let _config_2 = resolveEndpointsConfig(_config_1);
let _config_3 = resolveAwsAuthConfig(_config_2);
let _config_4 = resolveRetryConfig(_config_3);
let _config_5 = resolveUserAgentConfig(_config_4);
let _config_6 = resolveHostHeaderConfig(_config_5);
let _config_5 = resolveHostHeaderConfig(_config_4);
let _config_6 = resolveUserAgentConfig(_config_5);
super(_config_6);
this.config = _config_6;
this.middlewareStack.use(getAwsAuthPlugin(this.config));
this.middlewareStack.use(getRetryPlugin(this.config));
this.middlewareStack.use(getUserAgentPlugin(this.config));
this.middlewareStack.use(getContentLengthPlugin(this.config));
this.middlewareStack.use(getHostHeaderPlugin(this.config));
this.middlewareStack.use(getLoggerPlugin(this.config));
this.middlewareStack.use(getUserAgentPlugin(this.config));
}

destroy(): void {
Expand Down
5 changes: 4 additions & 1 deletion clients/client-accessanalyzer/runtimeConfig.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ export const ClientDefaultValues: Required<ClientDefaults> = {
base64Encoder: toBase64,
bodyLengthChecker: calculateBodyLength,
credentialDefaultProvider: invalidAsyncFunction("Credentialis missing") as any,
defaultUserAgent: defaultUserAgent(packageInfo.name, packageInfo.version),
defaultUserAgentProvider: defaultUserAgent({
serviceId: ClientSharedValues.serviceId,
clientVersion: packageInfo.version,
}),
maxAttempts: DEFAULT_MAX_ATTEMPTS,
region: invalidAsyncFunction("Region is missing") as any,
requestHandler: new FetchHttpHandler(),
Expand Down
3 changes: 0 additions & 3 deletions clients/client-accessanalyzer/runtimeConfig.native.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import packageInfo from "./package.json";

import { Sha256 } from "@aws-crypto/sha256-js";
import { parseUrl } from "@aws-sdk/url-parser-node";
import { ClientDefaults } from "./AccessAnalyzerClient";
Expand All @@ -11,7 +9,6 @@ import { ClientDefaultValues as BrowserDefaults } from "./runtimeConfig.browser"
export const ClientDefaultValues: Required<ClientDefaults> = {
...BrowserDefaults,
runtime: "react-native",
defaultUserAgent: `aws-sdk-js-v3-react-native-${packageInfo.name}/${packageInfo.version}`,
sha256: Sha256,
urlParser: parseUrl,
};
5 changes: 4 additions & 1 deletion clients/client-accessanalyzer/runtimeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ export const ClientDefaultValues: Required<ClientDefaults> = {
base64Encoder: toBase64,
bodyLengthChecker: calculateBodyLength,
credentialDefaultProvider,
defaultUserAgent: defaultUserAgent(packageInfo.name, packageInfo.version),
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(),
Expand Down
27 changes: 15 additions & 12 deletions clients/client-acm-pca/ACMPCAClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ import {
SmithyResolvedConfiguration as __SmithyResolvedConfiguration,
} from "@aws-sdk/smithy-client";
import {
Provider,
RegionInfoProvider,
Credentials as __Credentials,
Decoder as __Decoder,
Expand All @@ -107,6 +108,7 @@ import {
Provider as __Provider,
StreamCollector as __StreamCollector,
UrlParser as __UrlParser,
UserAgent as __UserAgent,
} from "@aws-sdk/types";

export type ServiceInputTypes =
Expand Down Expand Up @@ -206,11 +208,6 @@ export interface ClientDefaults extends Partial<__SmithyResolvedConfiguration<__
*/
utf8Encoder?: __Encoder;

/**
* The string that will be used to populate default value in 'User-Agent' header
*/
defaultUserAgent?: string;

/**
* The runtime environment
*/
Expand Down Expand Up @@ -252,6 +249,12 @@ export interface ClientDefaults extends Partial<__SmithyResolvedConfiguration<__
* Fetch related hostname, signing name or signing region with given region.
*/
regionInfoProvider?: RegionInfoProvider;

/**
* The provider populating default tracking information to be sent with `user-agent`, `x-amz-user-agent` header
* @internal
*/
defaultUserAgentProvider?: Provider<__UserAgent>;
}

export type ACMPCAClientConfig = Partial<__SmithyConfiguration<__HttpHandlerOptions>> &
Expand All @@ -260,17 +263,17 @@ export type ACMPCAClientConfig = Partial<__SmithyConfiguration<__HttpHandlerOpti
EndpointsInputConfig &
AwsAuthInputConfig &
RetryInputConfig &
UserAgentInputConfig &
HostHeaderInputConfig;
HostHeaderInputConfig &
UserAgentInputConfig;

export type ACMPCAClientResolvedConfig = __SmithyResolvedConfiguration<__HttpHandlerOptions> &
Required<ClientDefaults> &
RegionResolvedConfig &
EndpointsResolvedConfig &
AwsAuthResolvedConfig &
RetryResolvedConfig &
UserAgentResolvedConfig &
HostHeaderResolvedConfig;
HostHeaderResolvedConfig &
UserAgentResolvedConfig;

/**
* <note>
Expand Down Expand Up @@ -307,16 +310,16 @@ export class ACMPCAClient extends __Client<
let _config_2 = resolveEndpointsConfig(_config_1);
let _config_3 = resolveAwsAuthConfig(_config_2);
let _config_4 = resolveRetryConfig(_config_3);
let _config_5 = resolveUserAgentConfig(_config_4);
let _config_6 = resolveHostHeaderConfig(_config_5);
let _config_5 = resolveHostHeaderConfig(_config_4);
let _config_6 = resolveUserAgentConfig(_config_5);
super(_config_6);
this.config = _config_6;
this.middlewareStack.use(getAwsAuthPlugin(this.config));
this.middlewareStack.use(getRetryPlugin(this.config));
this.middlewareStack.use(getUserAgentPlugin(this.config));
this.middlewareStack.use(getContentLengthPlugin(this.config));
this.middlewareStack.use(getHostHeaderPlugin(this.config));
this.middlewareStack.use(getLoggerPlugin(this.config));
this.middlewareStack.use(getUserAgentPlugin(this.config));
}

destroy(): void {
Expand Down
5 changes: 4 additions & 1 deletion clients/client-acm-pca/runtimeConfig.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ export const ClientDefaultValues: Required<ClientDefaults> = {
base64Encoder: toBase64,
bodyLengthChecker: calculateBodyLength,
credentialDefaultProvider: invalidAsyncFunction("Credentialis missing") as any,
defaultUserAgent: defaultUserAgent(packageInfo.name, packageInfo.version),
defaultUserAgentProvider: defaultUserAgent({
serviceId: ClientSharedValues.serviceId,
clientVersion: packageInfo.version,
}),
maxAttempts: DEFAULT_MAX_ATTEMPTS,
region: invalidAsyncFunction("Region is missing") as any,
requestHandler: new FetchHttpHandler(),
Expand Down
3 changes: 0 additions & 3 deletions clients/client-acm-pca/runtimeConfig.native.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import packageInfo from "./package.json";

import { Sha256 } from "@aws-crypto/sha256-js";
import { parseUrl } from "@aws-sdk/url-parser-node";
import { ClientDefaults } from "./ACMPCAClient";
Expand All @@ -11,7 +9,6 @@ import { ClientDefaultValues as BrowserDefaults } from "./runtimeConfig.browser"
export const ClientDefaultValues: Required<ClientDefaults> = {
...BrowserDefaults,
runtime: "react-native",
defaultUserAgent: `aws-sdk-js-v3-react-native-${packageInfo.name}/${packageInfo.version}`,
sha256: Sha256,
urlParser: parseUrl,
};
5 changes: 4 additions & 1 deletion clients/client-acm-pca/runtimeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ export const ClientDefaultValues: Required<ClientDefaults> = {
base64Encoder: toBase64,
bodyLengthChecker: calculateBodyLength,
credentialDefaultProvider,
defaultUserAgent: defaultUserAgent(packageInfo.name, packageInfo.version),
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(),
Expand Down
27 changes: 15 additions & 12 deletions clients/client-acm/ACMClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import {
SmithyResolvedConfiguration as __SmithyResolvedConfiguration,
} from "@aws-sdk/smithy-client";
import {
Provider,
RegionInfoProvider,
Credentials as __Credentials,
Decoder as __Decoder,
Expand All @@ -76,6 +77,7 @@ import {
Provider as __Provider,
StreamCollector as __StreamCollector,
UrlParser as __UrlParser,
UserAgent as __UserAgent,
} from "@aws-sdk/types";

export type ServiceInputTypes =
Expand Down Expand Up @@ -155,11 +157,6 @@ export interface ClientDefaults extends Partial<__SmithyResolvedConfiguration<__
*/
utf8Encoder?: __Encoder;

/**
* The string that will be used to populate default value in 'User-Agent' header
*/
defaultUserAgent?: string;

/**
* The runtime environment
*/
Expand Down Expand Up @@ -201,6 +198,12 @@ export interface ClientDefaults extends Partial<__SmithyResolvedConfiguration<__
* Fetch related hostname, signing name or signing region with given region.
*/
regionInfoProvider?: RegionInfoProvider;

/**
* The provider populating default tracking information to be sent with `user-agent`, `x-amz-user-agent` header
* @internal
*/
defaultUserAgentProvider?: Provider<__UserAgent>;
}

export type ACMClientConfig = Partial<__SmithyConfiguration<__HttpHandlerOptions>> &
Expand All @@ -209,17 +212,17 @@ export type ACMClientConfig = Partial<__SmithyConfiguration<__HttpHandlerOptions
EndpointsInputConfig &
AwsAuthInputConfig &
RetryInputConfig &
UserAgentInputConfig &
HostHeaderInputConfig;
HostHeaderInputConfig &
UserAgentInputConfig;

export type ACMClientResolvedConfig = __SmithyResolvedConfiguration<__HttpHandlerOptions> &
Required<ClientDefaults> &
RegionResolvedConfig &
EndpointsResolvedConfig &
AwsAuthResolvedConfig &
RetryResolvedConfig &
UserAgentResolvedConfig &
HostHeaderResolvedConfig;
HostHeaderResolvedConfig &
UserAgentResolvedConfig;

/**
* <fullname>AWS Certificate Manager</fullname>
Expand All @@ -246,16 +249,16 @@ export class ACMClient extends __Client<
let _config_2 = resolveEndpointsConfig(_config_1);
let _config_3 = resolveAwsAuthConfig(_config_2);
let _config_4 = resolveRetryConfig(_config_3);
let _config_5 = resolveUserAgentConfig(_config_4);
let _config_6 = resolveHostHeaderConfig(_config_5);
let _config_5 = resolveHostHeaderConfig(_config_4);
let _config_6 = resolveUserAgentConfig(_config_5);
super(_config_6);
this.config = _config_6;
this.middlewareStack.use(getAwsAuthPlugin(this.config));
this.middlewareStack.use(getRetryPlugin(this.config));
this.middlewareStack.use(getUserAgentPlugin(this.config));
this.middlewareStack.use(getContentLengthPlugin(this.config));
this.middlewareStack.use(getHostHeaderPlugin(this.config));
this.middlewareStack.use(getLoggerPlugin(this.config));
this.middlewareStack.use(getUserAgentPlugin(this.config));
}

destroy(): void {
Expand Down
5 changes: 4 additions & 1 deletion clients/client-acm/runtimeConfig.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ export const ClientDefaultValues: Required<ClientDefaults> = {
base64Encoder: toBase64,
bodyLengthChecker: calculateBodyLength,
credentialDefaultProvider: invalidAsyncFunction("Credentialis missing") as any,
defaultUserAgent: defaultUserAgent(packageInfo.name, packageInfo.version),
defaultUserAgentProvider: defaultUserAgent({
serviceId: ClientSharedValues.serviceId,
clientVersion: packageInfo.version,
}),
maxAttempts: DEFAULT_MAX_ATTEMPTS,
region: invalidAsyncFunction("Region is missing") as any,
requestHandler: new FetchHttpHandler(),
Expand Down
3 changes: 0 additions & 3 deletions clients/client-acm/runtimeConfig.native.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import packageInfo from "./package.json";

import { Sha256 } from "@aws-crypto/sha256-js";
import { parseUrl } from "@aws-sdk/url-parser-node";
import { ClientDefaults } from "./ACMClient";
Expand All @@ -11,7 +9,6 @@ import { ClientDefaultValues as BrowserDefaults } from "./runtimeConfig.browser"
export const ClientDefaultValues: Required<ClientDefaults> = {
...BrowserDefaults,
runtime: "react-native",
defaultUserAgent: `aws-sdk-js-v3-react-native-${packageInfo.name}/${packageInfo.version}`,
sha256: Sha256,
urlParser: parseUrl,
};
5 changes: 4 additions & 1 deletion clients/client-acm/runtimeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ export const ClientDefaultValues: Required<ClientDefaults> = {
base64Encoder: toBase64,
bodyLengthChecker: calculateBodyLength,
credentialDefaultProvider,
defaultUserAgent: defaultUserAgent(packageInfo.name, packageInfo.version),
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(),
Expand Down
Loading

0 comments on commit 388b180

Please sign in to comment.