Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,16 @@ import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import software.aws.toolkits.core.utils.createParentDirectories
import software.aws.toolkits.core.utils.debug
import software.aws.toolkits.core.utils.deleteIfExists
import software.aws.toolkits.core.utils.getLogger
import software.aws.toolkits.core.utils.info
import software.aws.toolkits.core.utils.inputStreamIfExists
import software.aws.toolkits.core.utils.outputStream
import software.aws.toolkits.core.utils.toHexString
import software.aws.toolkits.core.utils.touch
import software.aws.toolkits.core.utils.tryDirOp
import software.aws.toolkits.core.utils.tryFileOp
import software.aws.toolkits.core.utils.tryOrNull
import software.aws.toolkits.core.utils.warn
import software.aws.toolkits.telemetry.AuthTelemetry
import software.aws.toolkits.telemetry.Result
import java.io.InputStream
Expand Down Expand Up @@ -97,16 +96,16 @@ class DiskCache(
}

override fun invalidateClientRegistration(ssoRegion: String) {
LOG.debug { "invalidateClientRegistration for $ssoRegion" }
LOG.info { "invalidateClientRegistration for $ssoRegion" }
clientRegistrationCache(ssoRegion).tryDeleteIfExists()
}

override fun loadClientRegistration(cacheKey: ClientRegistrationCacheKey): ClientRegistration? {
LOG.debug { "loadClientRegistration for $cacheKey" }
LOG.info { "loadClientRegistration for $cacheKey" }
val inputStream = clientRegistrationCache(cacheKey).tryInputStreamIfExists()
if (inputStream == null) {
val stage = LoadCredentialStage.ACCESS_FILE
LOG.warn { "Failed to load Client Registration: cache file does not exist" }
LOG.info { "Failed to load Client Registration: cache file does not exist" }
AuthTelemetry.modifyConnection(
action = "Load cache file",
source = "loadClientRegistration",
Expand All @@ -120,15 +119,15 @@ class DiskCache(
}

override fun saveClientRegistration(cacheKey: ClientRegistrationCacheKey, registration: ClientRegistration) {
LOG.debug { "saveClientRegistration for $cacheKey" }
LOG.info { "saveClientRegistration for $cacheKey" }
val registrationCache = clientRegistrationCache(cacheKey)
writeKey(registrationCache) {
objectMapper.writeValue(it, registration)
}
}

override fun invalidateClientRegistration(cacheKey: ClientRegistrationCacheKey) {
LOG.debug { "invalidateClientRegistration for $cacheKey" }
LOG.info { "invalidateClientRegistration for $cacheKey" }
try {
clientRegistrationCache(cacheKey).tryDeleteIfExists()
} catch (e: Exception) {
Expand All @@ -144,7 +143,7 @@ class DiskCache(
}

override fun invalidateAccessToken(ssoUrl: String) {
LOG.debug { "invalidateAccessToken for $ssoUrl" }
LOG.info { "invalidateAccessToken for $ssoUrl" }
try {
accessTokenCache(ssoUrl).tryDeleteIfExists()
} catch (e: Exception) {
Expand All @@ -160,7 +159,7 @@ class DiskCache(
}

override fun loadAccessToken(cacheKey: AccessTokenCacheKey): AccessToken? {
LOG.debug { "loadAccessToken for $cacheKey" }
LOG.info { "loadAccessToken for $cacheKey" }
val cacheFile = accessTokenCache(cacheKey)
val inputStream = cacheFile.tryInputStreamIfExists() ?: return null

Expand All @@ -170,15 +169,15 @@ class DiskCache(
}

override fun saveAccessToken(cacheKey: AccessTokenCacheKey, accessToken: AccessToken) {
LOG.debug { "saveAccessToken for $cacheKey" }
LOG.info { "saveAccessToken for $cacheKey" }
val accessTokenCache = accessTokenCache(cacheKey)
writeKey(accessTokenCache) {
objectMapper.writeValue(it, accessToken)
}
}

override fun invalidateAccessToken(cacheKey: AccessTokenCacheKey) {
LOG.debug { "invalidateAccessToken for $cacheKey" }
LOG.info { "invalidateAccessToken for $cacheKey" }
try {
accessTokenCache(cacheKey).tryDeleteIfExists()
} catch (e: Exception) {
Expand All @@ -203,7 +202,7 @@ class DiskCache(
val sha = sha1(cacheNameMapper.writeValueAsString(it))

cacheDir.resolve("$sha.json").also {
LOG.debug { "$cacheKey resolves to $it" }
LOG.info { "$cacheKey resolves to $it" }
}
}

Expand All @@ -225,7 +224,7 @@ class DiskCache(
if (clientRegistration.expiresAt.isNotExpired()) {
return clientRegistration
} else {
LOG.warn { "Client Registration is expired" }
LOG.info { "Client Registration is expired" }
AuthTelemetry.modifyConnection(
action = "Validate Credentials",
source = "loadClientRegistration",
Expand All @@ -236,7 +235,7 @@ class DiskCache(
return null
}
} catch (e: Exception) {
LOG.warn { "Client Registration could not be read" }
LOG.info { "Client Registration could not be read" }
AuthTelemetry.modifyConnection(
action = "Validate Credentials",
source = "loadClientRegistration",
Expand Down Expand Up @@ -269,7 +268,7 @@ class DiskCache(
}

private fun writeKey(path: Path, consumer: (OutputStream) -> Unit) {
LOG.debug { "writing to $path" }
LOG.info { "writing to $path" }
try {
path.tryDirOp(LOG) { createParentDirectories() }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import software.amazon.awssdk.services.ssooidc.model.InvalidClientException
import software.amazon.awssdk.services.ssooidc.model.InvalidRequestException
import software.amazon.awssdk.services.ssooidc.model.SlowDownException
import software.aws.toolkits.core.utils.getLogger
import software.aws.toolkits.core.utils.info
import software.aws.toolkits.core.utils.warn
import software.aws.toolkits.jetbrains.core.credentials.sono.SONO_URL
import software.aws.toolkits.jetbrains.core.credentials.sso.pkce.PKCE_CLIENT_NAME
Expand Down Expand Up @@ -498,7 +499,7 @@ class SsoAccessTokenProvider(
requestId = requestId,
result = Result.Failed
)
LOG.warn { "RefreshAccessTokenFailed: ${e.message}" }
LOG.info { "RefreshAccessTokenFailed: ${e.message}" }
throw e
}
}
Expand Down
Loading