-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add more user agent app id sources #1071
Conversation
*/ | ||
@InternalSdkApi | ||
public suspend fun resolveUserAgent(platform: PlatformProvider = PlatformProvider.System, profile: LazyAsyncValue<AwsProfile>): String? = | ||
platform.getProperty(AWS_APP_ID_PROP) ?: platform.getenv(AWS_APP_ID_ENV) ?: profile.get().sdkUserAgentAppId |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix: Use EnvironmentSetting<T>.resolve()
AwsSdkSetting.AwsAppId.resolve(platform) ?: profile.get().sdkUserAgentAppId
/** | ||
* The sdk user agent app ID. | ||
*/ | ||
public var sdkUserAgentAppId: String? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix: Lets gives some more context in the documentation on how this is used (same for the immutable val
docs).
e.g.
An optional application specific identifier. When set it will be appended to the
User-Agent
header of every request in the form ofapp/{sdkUserAgentAppId}
. When not explicitly set, this field will attempt to be sourced from the following locations:
* JVM System Property:aws.userAgentAppId
* Environment variableAWS_SDK_UA_APP_ID
* Shared configuration profile attribute:sdk_ua_app_id
See shared configuration settings reference for more information on environment variables and shared config settings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also do we want to rename this to just userAgentAppId
or simply applicationId
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think applicationId
makes more sense
baseClass = AwsRuntimeTypes.Core.Client.AwsSdkClientConfig | ||
useNestedBuilderBaseClass() | ||
documentation = """ | ||
The SDK user agent app ID used to identify applications. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update docs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I had a few nit-level comments
{ | ||
"id": "2e8e4fee-c462-45d2-b421-46520d06eb60", | ||
"type": "feature", | ||
"description": "Add new sources for user agent app id (explicit, from profile)", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: the parenthesis is missing mention of the system property and environment variable options. I think just "Add new sources ..." is a good enough changelog description and listing each one is not necessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "user agent" -> "User-Agent"
import aws.smithy.kotlin.runtime.util.PlatformProvider | ||
|
||
/** | ||
* Attempts to resolve user agent from specified sources. Returns null if none found |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: you can also use @return
for better KDoc integration
override val region: String = builder.region ?: error("region is required") | ||
override val region: String? = builder.region |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: what changed here, is region
no longer required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check wasn't required to begin with. I removed it because it was interfering with the applicationId
tests. I would've had to add a region to the TestClient
from the tests even if it wasn't necessary
@@ -33,6 +33,26 @@ class AwsServiceConfigIntegration : KotlinIntegration { | |||
order = -100 | |||
} | |||
|
|||
val userAgentAppId: ConfigProperty = ConfigProperty { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: name should be capitalized UserAgentAppId
@@ -33,6 +33,26 @@ class AwsServiceConfigIntegration : KotlinIntegration { | |||
order = -100 | |||
} | |||
|
|||
val userAgentAppId: ConfigProperty = ConfigProperty { | |||
name = "applicationId" | |||
symbol = KotlinTypes.String.toBuilder().nullable().build() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this can be simplified to KotlinTypes.String.asNullable()
A new generated diff is ready to view. |
A new generated diff is ready to view. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor issues. Fix and ship!
/** | ||
* Configure the user agent app ID | ||
*/ | ||
public val AwsAppId: EnvironmentSetting<String> = strEnvSetting("aws.userAgentAppId", "AWS_SDK_UA_APP_ID") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Reuse the AWS_APP_ID_ENV
and AWS_APP_ID_PROP
constants from AwsUserAgentMetadata.kt.
/** | ||
* 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, this field will attempt to be sourced from the following locations: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style: "this field will attempt to be sourced from" feels awkward. Perhaps "the value will be loaded from" would be clearer.
* - JVM System Properties: aws.userAgentAppId | ||
* - Environment variables: AWS_SDK_UA_APP_ID | ||
* - Shared configuration profile attribute: sdk_ua_app_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Make "properties" and "variables" singular. Also use backticks around the property name, variable name, and config key.
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
A new generated diff is ready to view. |
Issue #
closes #945
Description of changes
There will now be more sources to set the user agent app id. Added ones include explicitly set using client configuration and from the AWS shared config active profile. The precedence order is:
client configuration (highest)
aws.userAgentAppId system property
AWS_SDK_UA_APP_ID environment variable
sdk_ua_app_id profile key (lowest)
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.