Skip to content

Commit 7f285c5

Browse files
committed
feedback and fixes
1 parent 06422f1 commit 7f285c5

File tree

6 files changed

+44
-10
lines changed

6 files changed

+44
-10
lines changed

aws-runtime/aws-config/build.gradle.kts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ kotlin {
7171
fun awsModelFile(name: String): String =
7272
rootProject.file("codegen/sdk/aws-models/$name").relativeTo(project.layout.buildDirectory.get().asFile).toString()
7373

74+
fun awsShapeFile(name: String): String =
75+
rootProject.file("codegen/sdk/aws-shapes/$name").relativeTo(project.layout.buildDirectory.get().asFile).toString()
76+
7477
val codegen by configurations.getting
7578
dependencies {
7679
codegen(project(":codegen:aws-sdk-codegen"))
@@ -189,10 +192,10 @@ smithyBuild {
189192
)
190193
}
191194

192-
// FIXME: Shape from smoke tests fails projection: aws.test#AwsVendorParams (curr smoke tests temporarily removed from model)
193195
create("signin-credentials-provider") {
194196
imports = listOf(
195197
awsModelFile("sign-in.json"),
198+
awsShapeFile("shapes.json"),
196199
)
197200

198201
val serviceShape = "com.amazonaws.signin#Signin"

aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/auth/credentials/LoginCredentialsProvider.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,10 @@ import kotlin.coroutines.coroutineContext
3232
* the directory specified by the `AWS_LOGIN_CACHE_DIRECTORY` environment variable.
3333
*
3434
* ```
35-
* val source = LoginCredentialsProvider(
36-
* loginSession = "my-login-session"
37-
* )
38-
*
3935
* // Wrap the provider with a caching provider to cache the credentials until their expiration time
40-
* val loginProvider = CachedCredentialsProvider(source)
36+
* val loginProvider = LoginCredentialsProvider(
37+
* loginSession = "my-login-session"
38+
* ).cached()
4139
* ```
4240
* It is important that you wrap the provider with [CachedCredentialsProvider] if you are programmatically constructing
4341
* the provider directly. This prevents your application from accessing the cached access token and requesting new

aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/auth/credentials/LoginTokenProvider.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,14 @@ public class LoginTokenProvider(
144144

145145
private suspend fun writeToken(refreshed: LoginToken) {
146146
val cacheKey = getLoginCacheFilename(loginSessionName)
147-
val directory = platformProvider.getenv("AWS_LOGIN_IN_CACHE_DIRECTORY") ?: platformProvider.filepath("~", ".aws", "login", "cache")
147+
val directory = resolveCacheDir(platformProvider)
148148
val filepath = normalizePath(platformProvider.filepath(directory, cacheKey), platformProvider)
149149
val contents = serializeLoginToken(refreshed)
150150
try {
151151
platformProvider.writeFile(filepath, contents)
152152
} catch (ex: Exception) {
153153
coroutineContext.debug<LoginTokenProvider>(ex) { "failed to write refreshed token back to disk at $filepath" }
154+
throw ex
154155
}
155156
}
156157

@@ -333,13 +334,17 @@ private fun generateDpopProof(
333334
internal suspend fun readLoginTokenFromCache(cacheKey: String, platformProvider: PlatformProvider): LoginToken {
334335
val key = getLoginCacheFilename(cacheKey)
335336
val bytes = with(platformProvider) {
336-
val directory = getenv("AWS_LOGIN_IN_CACHE_DIRECTORY") ?: filepath("~", ".aws", "login", "cache")
337+
val directory = resolveCacheDir(this)
337338
val defaultCacheLocation = normalizePath(directory, this)
338339
readFileOrNull(filepath(defaultCacheLocation, key))
339340
} ?: throw ProviderConfigurationException("Invalid or missing login session cache. Run `aws login` to initiate a new session")
340341
return deserializeLoginToken(bytes)
341342
}
342343

344+
private fun resolveCacheDir(platformProvider: PlatformProvider) =
345+
platformProvider.getenv("AWS_LOGIN_IN_CACHE_DIRECTORY")
346+
?: platformProvider.filepath("~", ".aws", "login", "cache")
347+
343348
internal fun getLoginCacheFilename(cacheKey: String): String {
344349
val sha256HexDigest = cacheKey.trim().encodeToByteArray().sha256().encodeToHex()
345350
return "$sha256HexDigest.json"

aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/auth/credentials/profile/ProfileChain.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ private fun AwsProfile.leafProvider(config: AwsSharedConfig): LeafProvider {
359359
return webIdentityTokenCreds()
360360
.orElse { ssoSessionCreds(config) }
361361
.orElse(::legacySsoCreds)
362-
.orElse { loginSessionCreds() }
362+
.orElse(::loginSessionCreds)
363363
.unwrapOrElse(::processCreds)
364364
.unwrap()
365365
}

codegen/sdk/aws-models/sign-in.json

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,26 @@
113113
"smithy.api#http": {
114114
"method": "POST",
115115
"uri": "/v1/token"
116-
}
116+
},
117+
"smithy.test#smokeTests": [
118+
{
119+
"id": "TokenOperationSmokeTest",
120+
"params": {
121+
"tokenInput": {
122+
"clientId": "aws:signin:::cli/same-device",
123+
"grantType": "authorization_code",
124+
"code": "test-code",
125+
"redirectUri": "https://example.com",
126+
"codeVerifier": "test-code-verifier-1234567890abcdefghijklmnop"
127+
}
128+
},
129+
"vendorParamsShape": "aws.test#AwsVendorParams",
130+
"vendorParams": {},
131+
"expect": {
132+
"failure": {}
133+
}
134+
}
135+
]
117136
}
118137
},
119138
"com.amazonaws.signin#CreateOAuth2TokenRequest": {

codegen/sdk/aws-shapes/shapes.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"smithy": "2.0",
3+
"shapes": {
4+
"aws.test#AwsVendorParams": {
5+
"type": "structure",
6+
"members": {}
7+
}
8+
}
9+
}

0 commit comments

Comments
 (0)