Skip to content

Commit

Permalink
feat: add more user agent app id sources (smithy-lang#1071)
Browse files Browse the repository at this point in the history
  • Loading branch information
0marperez authored Oct 11, 2023
1 parent 730628e commit 82b71fa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,26 @@ class AwsServiceConfigIntegration : KotlinIntegration {
order = -100
}

val UserAgentAppId: ConfigProperty = ConfigProperty {
name = "applicationId"
symbol = KotlinTypes.String.asNullable()
baseClass = AwsRuntimeTypes.Core.Client.AwsSdkClientConfig
useNestedBuilderBaseClass()
documentation = """
An optional application specific identifier.
When set it will be appended to the User-Agent header of every request in the form of: `app/{applicationId}`.
When not explicitly set, the value will be loaded from the following locations:
- JVM System Property: `aws.userAgentAppId`
- Environment variable: `AWS_SDK_UA_APP_ID`
- Shared configuration profile attribute: `sdk_ua_app_id`
See [shared configuration settings](https://docs.aws.amazon.com/sdkref/latest/guide/settings-reference.html)
reference for more information on environment variables and shared config settings.
""".trimIndent()
order = 100
}

// override the credentials provider prop registered by the Sigv4AuthSchemeIntegration, updates the
// documentation and sets a default value for AWS SDK to the default chain.
val CredentialsProviderProp: ConfigProperty = ConfigProperty {
Expand Down Expand Up @@ -158,5 +178,6 @@ class AwsServiceConfigIntegration : KotlinIntegration {
add(UseDualStackProp)
add(EndpointUrlProp)
add(AwsRetryPolicy)
add(UserAgentAppId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ class UserAgentMiddleware : ProtocolMiddleware {
writer.addImport(uaSymbol)
writer.addImport(apiMetaSymbol)
writer.addImport(middlewareSymbol)
writer.write("private val awsUserAgentMetadata = #T.fromEnvironment(#T(ServiceId, SdkVersion))", uaSymbol, apiMetaSymbol)
writer.write(
"private val awsUserAgentMetadata = #T.fromEnvironment(#T(ServiceId, SdkVersion), config.applicationId)",
uaSymbol,
apiMetaSymbol,
)
}

override fun render(ctx: ProtocolGenerator.GenerationContext, op: OperationShape, writer: KotlinWriter) {
Expand Down

0 comments on commit 82b71fa

Please sign in to comment.