Skip to content
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

Merged
merged 9 commits into from
Oct 11, 2023
Merged

Conversation

0marperez
Copy link
Contributor

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.

@0marperez 0marperez marked this pull request as ready for review October 10, 2023 20:43
@0marperez 0marperez requested a review from a team as a code owner October 10, 2023 20:43
*/
@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
Copy link
Contributor

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?
Copy link
Contributor

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 of app/{sdkUserAgentAppId}. When not explicitly set, this field will attempt to be sourced 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 reference for more information on environment variables and shared config settings.

Copy link
Contributor

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?

Copy link
Contributor Author

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update docs

Copy link
Member

@lauzadis lauzadis left a 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)",
Copy link
Member

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

Copy link
Member

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
Copy link
Member

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

Comment on lines -62 to +125
override val region: String = builder.region ?: error("region is required")
override val region: String? = builder.region
Copy link
Member

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?

Copy link
Contributor Author

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 {
Copy link
Member

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()
Copy link
Member

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()

@github-actions
Copy link

A new generated diff is ready to view.

@github-actions
Copy link

A new generated diff is ready to view.

Copy link
Contributor

@ianbotsf ianbotsf left a 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")
Copy link
Contributor

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:
Copy link
Contributor

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.

Comment on lines 40 to 42
* - JVM System Properties: aws.userAgentAppId
* - Environment variables: AWS_SDK_UA_APP_ID
* - Shared configuration profile attribute: sdk_ua_app_id
Copy link
Contributor

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.

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@github-actions
Copy link

A new generated diff is ready to view.

@0marperez 0marperez merged commit 24851dc into main Oct 11, 2023
17 checks passed
@0marperez 0marperez deleted the user-agent-app-id-sources branch October 11, 2023 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support more sources for user agent's app ID
4 participants