Skip to content

Commit ba50bdf

Browse files
committed
Call credentialsProvider.resolve() for each generation
1 parent 6e3c0fd commit ba50bdf

File tree

1 file changed

+1
-13
lines changed
  • runtime/auth/aws-signing-common/common/src/aws/smithy/kotlin/runtime/auth/awssigning

1 file changed

+1
-13
lines changed

runtime/auth/aws-signing-common/common/src/aws/smithy/kotlin/runtime/auth/awssigning/AuthTokenGenerator.kt

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ import kotlin.time.Duration
1616
import kotlin.time.Duration.Companion.minutes
1717
import kotlin.time.Duration.Companion.seconds
1818

19-
// The default expiration value to use for [Credentials] when none is provided.
20-
private val DEFAULT_CREDENTIALS_EXPIRATION = 10.minutes
21-
2219
/**
2320
* Generates an authentication token, which is a SigV4-signed URL with the HTTP scheme removed.
2421
* @param service The name of the service the token is being generated for
@@ -30,27 +27,18 @@ private val DEFAULT_CREDENTIALS_EXPIRATION = 10.minutes
3027
public class AuthTokenGenerator(
3128
public val service: String,
3229
public val credentialsProvider: CredentialsProvider,
33-
public val credentialsRefreshBuffer: Duration = 10.seconds,
3430
public val signer: AwsSigner,
3531
public val clock: Clock = Clock.System,
3632
) {
37-
private lateinit var credentials: ExpiringValue<Credentials>
38-
3933
private fun Url.trimScheme(): String = toString().removePrefix(scheme.protocolName).removePrefix("://")
4034

4135
public suspend fun generateAuthToken(endpoint: Url, region: String, expiration: Duration): String {
42-
if (!::credentials.isInitialized || (credentials.expiresAt - clock.now()).absoluteValue <= credentialsRefreshBuffer) {
43-
val resolved = credentialsProvider.resolve()
44-
credentials = ExpiringValue(resolved, resolved.expiration ?: (clock.now() + DEFAULT_CREDENTIALS_EXPIRATION))
45-
}
46-
4736
val req = HttpRequest(HttpMethod.GET, endpoint)
4837

49-
val creds = credentials.value
5038
val serv = service
5139

5240
val config = AwsSigningConfig {
53-
credentials = creds
41+
credentials = credentialsProvider.resolve()
5442
this.region = region
5543
service = serv
5644
signingDate = clock.now()

0 commit comments

Comments
 (0)