Skip to content

Commit 6258b22

Browse files
committed
doing dumb things to test the duplicate code pr checker
1 parent 7e12dd3 commit 6258b22

File tree

3 files changed

+109
-2
lines changed

3 files changed

+109
-2
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package software.aws.toolkits.jetbrains.core.credentials.sso
5+
6+
import com.fasterxml.jackson.annotation.JsonIgnore
7+
import com.fasterxml.jackson.annotation.JsonInclude
8+
import com.fasterxml.jackson.annotation.JsonSubTypes
9+
import com.fasterxml.jackson.annotation.JsonTypeInfo
10+
import com.intellij.collaboration.auth.credentials.Credentials
11+
import software.amazon.awssdk.auth.token.credentials.SdkToken
12+
import software.amazon.awssdk.services.sso.SsoClient
13+
import software.amazon.awssdk.services.ssooidc.SsoOidcClient
14+
import software.aws.toolkits.core.utils.SensitiveField
15+
import software.aws.toolkits.core.utils.redactedString
16+
import java.time.Instant
17+
import java.util.Optional
18+
19+
/**
20+
* Access token returned from [SsoOidcClient.createToken] used to retrieve AWS Credentials from [SsoClient.getRoleCredentials].
21+
*/
22+
@JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION)
23+
@JsonSubTypes(value = [JsonSubTypes.Type(DeviceAuthorizationGrantToken::class), JsonSubTypes.Type(PKCEAuthorizationGrantToken::class) ])
24+
sealed interface AccessToken : SdkToken, Credentials {
25+
val region: String
26+
27+
@SensitiveField
28+
override val accessToken: String
29+
30+
@SensitiveField
31+
@get:JsonInclude(JsonInclude.Include.NON_NULL)
32+
val refreshToken: String?
33+
34+
val expiresAt: Instant
35+
val createdAt: Instant
36+
37+
override fun token() = accessToken
38+
39+
override fun expirationTime() = Optional.of(expiresAt)
40+
41+
@get:JsonIgnore
42+
val ssoUrl: String
43+
}
44+
45+
data class DeviceAuthorizationGrantToken(
46+
val startUrl: String,
47+
override val region: String,
48+
override val accessToken: String,
49+
override val refreshToken: String? = null,
50+
override val expiresAt: Instant,
51+
override val createdAt: Instant = Instant.EPOCH,
52+
) : AccessToken {
53+
override val ssoUrl: String
54+
get() = startUrl
55+
56+
override fun toString() = redactedString(this)
57+
}
58+
59+
data class PKCEAuthorizationGrantToken(
60+
val issuerUrl: String,
61+
override val region: String,
62+
override val accessToken: String,
63+
override val refreshToken: String,
64+
override val expiresAt: Instant,
65+
override val createdAt: Instant,
66+
) : AccessToken {
67+
override val ssoUrl: String
68+
get() = issuerUrl
69+
70+
override fun toString() = redactedString(this)
71+
}
72+
73+
// we really don't need to differentitate since they refresh the same way, but to save some mental cycles,
74+
// treat them as independent so we don't need to worry about intermingling the token/registration combos
75+
@JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION)
76+
@JsonSubTypes(value = [JsonSubTypes.Type(DeviceGrantAccessTokenCacheKey::class), JsonSubTypes.Type(PKCEAccessTokenCacheKey::class) ])
77+
sealed interface AccessTokenCacheKey {
78+
val scopes: List<String>
79+
}
80+
81+
// diverging from SDK/CLI impl here since they do: sha1sum(sessionName ?: startUrl)
82+
// which isn't good enough for us
83+
// only used in scoped case
84+
data class DeviceGrantAccessTokenCacheKey(
85+
val connectionId: String,
86+
val startUrl: String,
87+
override val scopes: List<String>,
88+
) : AccessTokenCacheKey
89+
90+
data class PKCEAccessTokenCacheKey(
91+
val issuerUrl: String,
92+
val region: String,
93+
override val scopes: List<String>,
94+
) : AccessTokenCacheKey

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/utils/TextUtils.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@ fun formatText(project: Project, language: Language, content: String): String {
2525
return result
2626
}
2727

28+
fun formatText2(project: Project, language: Language, content: String): String {
29+
var result = content
30+
CommandProcessor.getInstance().runUndoTransparentAction {
31+
PsiFileFactory.getInstance(project)
32+
.createFileFromText("foo.bar", language, content, false, true)?.let {
33+
result = CodeStyleManager.getInstance(project).reformat(it).text
34+
}
35+
}
36+
37+
return result
38+
}
39+
40+
2841
/**
2942
* Designed to convert underscore separated words (e.g. UPDATE_COMPLETE) into title cased human readable text
3043
* (e.g. Update Complete)

plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/lambda/execution/remote/RemoteLambdaState.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import software.amazon.awssdk.core.SdkBytes
2020
import software.amazon.awssdk.services.lambda.LambdaClient
2121
import software.amazon.awssdk.services.lambda.model.LogType
2222
import software.aws.toolkits.jetbrains.core.AwsClientManager
23-
import software.aws.toolkits.jetbrains.utils.formatText
23+
import software.aws.toolkits.jetbrains.utils.formatText2
2424
import software.aws.toolkits.jetbrains.utils.pluginAwareExecuteOnPooledThread
2525
import software.aws.toolkits.resources.message
2626
import software.aws.toolkits.telemetry.LambdaTelemetry
@@ -128,7 +128,7 @@ class RemoteLambdaState(
128128
}
129129

130130
private fun formatJson(input: String) = if (input.isNotEmpty() && input.first() == '{' && input.last() == '}') {
131-
formatText(environment.project, JsonLanguage.INSTANCE, input)
131+
formatText2(environment.project, JsonLanguage.INSTANCE, input)
132132
} else {
133133
input
134134
}

0 commit comments

Comments
 (0)