-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add more user agent app id sources (#1071)
- Loading branch information
Showing
16 changed files
with
276 additions
and
63 deletions.
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,8 @@ | ||
{ | ||
"id": "2e8e4fee-c462-45d2-b421-46520d06eb60", | ||
"type": "feature", | ||
"description": "Add new sources for User-Agent app id", | ||
"issues": [ | ||
"awslabs/aws-sdk-kotlin#945" | ||
] | ||
} |
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
22 changes: 22 additions & 0 deletions
22
...runtime/aws-config/common/src/aws/sdk/kotlin/runtime/config/useragent/ResolveUserAgent.kt
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,22 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package aws.sdk.kotlin.runtime.config.useragent | ||
|
||
import aws.sdk.kotlin.runtime.InternalSdkApi | ||
import aws.sdk.kotlin.runtime.config.AwsSdkSetting | ||
import aws.sdk.kotlin.runtime.config.profile.AwsProfile | ||
import aws.sdk.kotlin.runtime.config.profile.sdkUserAgentAppId | ||
import aws.smithy.kotlin.runtime.config.resolve | ||
import aws.smithy.kotlin.runtime.util.LazyAsyncValue | ||
import aws.smithy.kotlin.runtime.util.PlatformProvider | ||
|
||
/** | ||
* Attempts to resolve user agent from specified sources. | ||
* @return The user agent app id if found, null if not | ||
*/ | ||
@InternalSdkApi | ||
public suspend fun resolveUserAgentAppId(platform: PlatformProvider = PlatformProvider.System, profile: LazyAsyncValue<AwsProfile>): String? = | ||
AwsSdkSetting.AwsAppId.resolve(platform) ?: profile.get().sdkUserAgentAppId |
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
63 changes: 63 additions & 0 deletions
63
aws-runtime/aws-config/jvm/test/aws/sdk/kotlin/runtime/config/utils/MockPlatform.kt
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,63 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package aws.sdk.kotlin.runtime.config.utils | ||
|
||
import aws.smithy.kotlin.runtime.util.OperatingSystem | ||
import aws.smithy.kotlin.runtime.util.PlatformProvider | ||
import io.mockk.coEvery | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import io.mockk.slot | ||
import java.io.File | ||
|
||
internal fun mockPlatform( | ||
pathSegment: String, | ||
awsProfileEnv: String? = null, | ||
awsConfigFileEnv: String? = null, | ||
homeEnv: String? = null, | ||
awsSharedCredentialsFileEnv: String? = null, | ||
awsSdkUserAgentAppIdEnv: String? = null, | ||
homeProp: String? = null, | ||
os: OperatingSystem, | ||
): PlatformProvider { | ||
val testPlatform = mockk<PlatformProvider>() | ||
val envKeyParam = slot<String>() | ||
val propKeyParam = slot<String>() | ||
val filePath = slot<String>() | ||
|
||
every { testPlatform.filePathSeparator } returns pathSegment | ||
every { testPlatform.getenv(capture(envKeyParam)) } answers { | ||
when (envKeyParam.captured) { | ||
"AWS_PROFILE" -> awsProfileEnv | ||
"AWS_CONFIG_FILE" -> awsConfigFileEnv | ||
"HOME" -> homeEnv | ||
"AWS_SHARED_CREDENTIALS_FILE" -> awsSharedCredentialsFileEnv | ||
"AWS_SDK_UA_APP_ID" -> awsSdkUserAgentAppIdEnv | ||
else -> error(envKeyParam.captured) | ||
} | ||
} | ||
every { testPlatform.getProperty(capture(propKeyParam)) } answers { | ||
if (propKeyParam.captured == "user.home") homeProp else null | ||
} | ||
every { testPlatform.osInfo() } returns os | ||
coEvery { | ||
testPlatform.readFileOrNull(capture(filePath)) | ||
} answers { | ||
if (awsConfigFileEnv != null) { | ||
val file = if (filePath.captured.endsWith("config")) { | ||
File(awsConfigFileEnv) | ||
} else { | ||
File(awsSharedCredentialsFileEnv) | ||
} | ||
|
||
if (file.exists()) file.readBytes() else null | ||
} else { | ||
null | ||
} | ||
} | ||
|
||
return testPlatform | ||
} |
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.