-
Notifications
You must be signed in to change notification settings - Fork 861
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
Adds the user agent appId metadata tag #5636
Open
cenedhryn
wants to merge
5
commits into
aws:master
Choose a base branch
from
cenedhryn:ua-appid
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
51a754c
Adds the user agent appId metadata tag to client and system configura…
cenedhryn 2a8c900
appId length check
cenedhryn 3819b2d
Fix imports
cenedhryn 633dd51
moving appId to client override config
cenedhryn 85d3340
Merge branch 'master' into ua-appid
cenedhryn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"type": "feature", | ||
"category": "AWS SDK for Java v2", | ||
"contributor": "", | ||
"description": "Adds an option to set 'appId' metadata to the client builder or to system settings and config files. This metadata string value will be added to the user agent string as `app/somevalue`" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
.../sdk-core/src/main/java/software/amazon/awssdk/core/internal/useragent/AppIdResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package software.amazon.awssdk.core.internal.useragent; | ||
|
||
import java.util.Optional; | ||
import java.util.function.Supplier; | ||
import software.amazon.awssdk.annotations.SdkInternalApi; | ||
import software.amazon.awssdk.core.SdkSystemSetting; | ||
import software.amazon.awssdk.profiles.ProfileFile; | ||
import software.amazon.awssdk.profiles.ProfileFileSystemSetting; | ||
import software.amazon.awssdk.profiles.ProfileProperty; | ||
import software.amazon.awssdk.utils.OptionalUtils; | ||
|
||
@SdkInternalApi | ||
public final class AppIdResolver { | ||
|
||
private Supplier<ProfileFile> profileFile; | ||
private String profileName; | ||
|
||
private AppIdResolver() { | ||
} | ||
|
||
public static AppIdResolver create() { | ||
return new AppIdResolver(); | ||
} | ||
|
||
public AppIdResolver profileFile(Supplier<ProfileFile> profileFile) { | ||
this.profileFile = profileFile; | ||
return this; | ||
} | ||
|
||
public AppIdResolver profileName(String profileName) { | ||
this.profileName = profileName; | ||
return this; | ||
} | ||
|
||
public Optional<String> resolve() { | ||
return OptionalUtils.firstPresent(fromSystemSettings(), | ||
() -> fromProfileFile(profileFile, profileName)); | ||
} | ||
|
||
private Optional<String> fromSystemSettings() { | ||
return SdkSystemSetting.AWS_SDK_UA_APP_ID.getStringValue(); | ||
} | ||
|
||
private Optional<String> fromProfileFile(Supplier<ProfileFile> profileFile, String profileName) { | ||
profileFile = profileFile != null ? profileFile : ProfileFile::defaultProfileFile; | ||
profileName = profileName != null ? profileName : ProfileFileSystemSetting.AWS_PROFILE.getStringValueOrThrow(); | ||
return profileFile.get() | ||
.profile(profileName) | ||
.flatMap(p -> p.property(ProfileProperty.SDK_UA_APP_ID)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
|
||
package software.amazon.awssdk.core.internal.useragent; | ||
|
||
import static software.amazon.awssdk.core.internal.useragent.UserAgentConstant.APP_ID; | ||
import static software.amazon.awssdk.core.internal.useragent.UserAgentConstant.CONFIG_METADATA; | ||
import static software.amazon.awssdk.core.internal.useragent.UserAgentConstant.ENV_METADATA; | ||
import static software.amazon.awssdk.core.internal.useragent.UserAgentConstant.HTTP; | ||
|
@@ -34,6 +35,7 @@ | |
import software.amazon.awssdk.annotations.SdkProtectedApi; | ||
import software.amazon.awssdk.annotations.ThreadSafe; | ||
import software.amazon.awssdk.core.util.SystemUserAgent; | ||
import software.amazon.awssdk.utils.Logger; | ||
import software.amazon.awssdk.utils.StringUtils; | ||
|
||
/** | ||
|
@@ -43,6 +45,8 @@ | |
@SdkProtectedApi | ||
public final class SdkUserAgentBuilder { | ||
|
||
private static final Logger log = Logger.loggerFor(SdkUserAgentBuilder.class); | ||
|
||
private SdkUserAgentBuilder() { | ||
} | ||
|
||
|
@@ -77,6 +81,12 @@ public static String buildClientUserAgentString(SystemUserAgent systemValues, | |
appendFieldAndSpace(uaString, CONFIG_METADATA, uaPair(RETRY_MODE, retryMode)); | ||
} | ||
|
||
String appId = userAgentProperties.getProperty(APP_ID); | ||
if (!StringUtils.isEmpty(appId)) { | ||
checkLengthAndWarn(appId); | ||
appendFieldAndSpace(uaString, APP_ID, appId); | ||
} | ||
|
||
removeFinalWhitespace(uaString); | ||
return uaString.toString(); | ||
} | ||
|
@@ -124,4 +134,12 @@ private static void appendAdditionalJvmMetadata(StringBuilder builder, SystemUse | |
appendNonEmptyField(builder, METADATA, lang); | ||
} | ||
} | ||
|
||
private static void checkLengthAndWarn(String appId) { | ||
if (appId.length() > 50) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to double check, is this only logged once? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it's only logged once. |
||
log.warn(() -> String.format("The configured appId '%s' is longer than the recommended maximum length of 50. " | ||
+ "This could result in not being able to transmit and log the whole user agent string, " | ||
+ "including the complete value of this string.", appId)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
final
?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.
they're not final