Skip to content

Commit 2376b5a

Browse files
authored
chore: Refactor internal clients (#952)
1 parent 9ba23ff commit 2376b5a

File tree

11 files changed

+67
-20
lines changed

11 files changed

+67
-20
lines changed

Sources/SmithyIdentity/AWSCredentialIdentityResolvers/StaticAWSCredentialIdentityResolver.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@
55
// SPDX-License-Identifier: Apache-2.0
66
//
77

8+
@_spi(ClientConfigDefaultIdentityResolver) import protocol SmithyIdentityAPI.ClientConfigDefaultIdentityResolver
89
import struct Smithy.Attributes
910

1011
/// A credential identity resolver that provides a fixed set of credentials
1112
public struct StaticAWSCredentialIdentityResolver: AWSCredentialIdentityResolver {
12-
private let credentials: AWSCredentialIdentity
13+
fileprivate let credentials: AWSCredentialIdentity
14+
15+
@_spi(StaticAWSCredentialIdentityResolver)
16+
public init() {
17+
self.credentials = AWSCredentialIdentity(accessKey: "", secret: "")
18+
}
1319

1420
/// Creates a credential identity resolver for a fixed set of credentials
1521
///
@@ -24,3 +30,11 @@ public struct StaticAWSCredentialIdentityResolver: AWSCredentialIdentityResolver
2430
return credentials
2531
}
2632
}
33+
34+
@_spi(ClientConfigDefaultIdentityResolver)
35+
extension StaticAWSCredentialIdentityResolver: ClientConfigDefaultIdentityResolver {
36+
37+
public var isClientConfigDefault: Bool {
38+
self.credentials.accessKey.isEmpty && self.credentials.secret.isEmpty
39+
}
40+
}

Sources/SmithyIdentity/BearerTokenIdentityResolvers/StaticBearerTokenIdentityResolver.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@
55
// SPDX-License-Identifier: Apache-2.0
66
//
77

8+
@_spi(ClientConfigDefaultIdentityResolver) import protocol SmithyIdentityAPI.ClientConfigDefaultIdentityResolver
89
import struct Smithy.Attributes
910

1011
/// The token identity resolver that returns a static token identity given to it at initialization.
1112
public struct StaticBearerTokenIdentityResolver: BearerTokenIdentityResolver {
12-
private let token: BearerTokenIdentity
13+
fileprivate let token: BearerTokenIdentity
14+
15+
@_spi(StaticBearerTokenIdentityResolver)
16+
public init() {
17+
self.token = BearerTokenIdentity(token: "")
18+
}
1319

1420
public init(token: BearerTokenIdentity) {
1521
self.token = token
@@ -19,3 +25,11 @@ public struct StaticBearerTokenIdentityResolver: BearerTokenIdentityResolver {
1925
return token
2026
}
2127
}
28+
29+
@_spi(ClientConfigDefaultIdentityResolver)
30+
extension StaticBearerTokenIdentityResolver: ClientConfigDefaultIdentityResolver {
31+
32+
public var isClientConfigDefault: Bool {
33+
token.token.isEmpty
34+
}
35+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// Copyright Amazon.com Inc. or its affiliates.
3+
// All Rights Reserved.
4+
//
5+
// SPDX-License-Identifier: Apache-2.0
6+
//
7+
8+
/// A protocol on identity resolver used to signify that this resolver is a default resolver created because the client config was not passed a custom resolver at creation.
9+
///
10+
/// Resolvers that do not implement this protocol should be presumed to not be a client config default.
11+
12+
@_spi(ClientConfigDefaultIdentityResolver)
13+
public protocol ClientConfigDefaultIdentityResolver: IdentityResolver {
14+
15+
/// Indicates whether this identity resolver was provided as a client config default.
16+
var isClientConfigDefault: Bool { get }
17+
}

smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/AuthSchemeResolverGenerator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class AuthSchemeResolverGenerator(
132132
// Model-based auth scheme resolver should be private internal impl detail if service uses rules-based resolver.
133133
val accessModifier = if (usesRulesBasedResolver) "private" else "public"
134134
val resolvedAccessModifier =
135-
if (accessModifier == "public" && ctx.settings.visibility == "internal") {
135+
if (accessModifier == "public" && ctx.settings.internalClient) {
136136
ctx.settings.visibility
137137
} else {
138138
accessModifier

smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/SwiftDependency.kt

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,8 @@ class SwiftDependency(
5252
"",
5353
DistributionMethod.GIT,
5454
)
55-
val CRT =
56-
SwiftDependency(
57-
"AwsCommonRuntimeKit",
58-
null,
59-
"0.52.1",
60-
"https://github.com/awslabs/aws-crt-swift",
61-
"",
62-
"aws-crt-swift",
63-
DistributionMethod.GIT,
64-
)
6555
val CLIENT_RUNTIME = smithySwiftDependency("ClientRuntime")
6656
val SMITHY = smithySwiftDependency("Smithy")
67-
val SMITHY_IDENTITY_API = smithySwiftDependency("SmithyIdentityAPI")
6857
val SMITHY_IDENTITY = smithySwiftDependency("SmithyIdentity")
6958
val SMITHY_RETRIES_API = smithySwiftDependency("SmithyRetriesAPI")
7059
val SMITHY_RETRIES = smithySwiftDependency("SmithyRetries")

smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/SwiftSettings.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ private const val SWIFT_VERSION = "swiftVersion"
3737
private const val MERGE_MODELS = "mergeModels"
3838
private const val COPYRIGHT_NOTICE = "copyrightNotice"
3939
private const val VISIBILITY = "visibility"
40+
private const val INTERNAL_CLIENT = "internalClient"
4041
private const val FOR_PROTOCOL_TESTS = "forProtocolTests"
4142

4243
// Prioritized list of protocols supported for code generation
@@ -64,6 +65,7 @@ class SwiftSettings(
6465
val mergeModels: Boolean,
6566
val copyrightNotice: String,
6667
val visibility: String,
68+
val internalClient: Boolean,
6769
val forProtocolTests: Boolean,
6870
) {
6971
companion object {
@@ -120,6 +122,7 @@ class SwiftSettings(
120122
"// Code generated by smithy-swift-codegen. DO NOT EDIT!\n\n",
121123
)
122124
val visibility = config.getStringMemberOrDefault(VISIBILITY, "public")
125+
val internalClient = config.getBooleanMemberOrDefault(INTERNAL_CLIENT, false)
123126
val forProtocolTests = config.getBooleanMemberOrDefault(FOR_PROTOCOL_TESTS, false)
124127

125128
return SwiftSettings(
@@ -135,6 +138,7 @@ class SwiftSettings(
135138
mergeModels,
136139
copyrightNotice,
137140
visibility,
141+
internalClient,
138142
forProtocolTests,
139143
)
140144
}

smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/lang/AccessModifier.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ enum class AccessModifier {
1515
PublicPrivateSet,
1616
Internal,
1717
Private,
18+
Package,
1819
None,
1920
;
2021

@@ -27,6 +28,7 @@ enum class AccessModifier {
2728
PublicPrivateSet -> "public private(set)"
2829
Internal -> "internal"
2930
Private -> "private"
31+
Package -> "package"
3032
None -> ""
3133
}
3234

smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/lang/ReservedWords.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ val reservedWords =
8383
"operator",
8484
"optional",
8585
"override",
86+
"package",
8687
"postfix",
8788
"prefix",
8889
"private",

smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftmodules/ClientRuntimeTypes.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@ private fun runtimeSymbol(
108108
name: String,
109109
declaration: SwiftDeclaration?,
110110
additionalImports: List<Symbol> = emptyList(),
111-
spiName: List<String> = emptyList(),
111+
spiNames: List<String> = emptyList(),
112112
): Symbol =
113113
SwiftSymbol.make(
114114
name,
115115
declaration,
116116
SwiftDependency.CLIENT_RUNTIME.takeIf { additionalImports.isEmpty() },
117117
additionalImports,
118-
spiName,
118+
spiNames,
119119
)

smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftmodules/SmithyIdentityTypes.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,25 @@ import software.amazon.smithy.swift.codegen.SwiftDeclaration
55
import software.amazon.smithy.swift.codegen.SwiftDependency
66

77
object SmithyIdentityTypes {
8-
val AWSCredentialIdentityResolver = runtimeSymbol("AWSCredentialIdentityResolver", SwiftDeclaration.PROTOCOL)
8+
val AWSCredentialIdentityResolver =
9+
runtimeSymbol("AWSCredentialIdentityResolver", SwiftDeclaration.PROTOCOL, listOf("AWSCredentialIdentityResolver"))
910
val BearerTokenIdentityResolver = runtimeSymbol("BearerTokenIdentityResolver", SwiftDeclaration.PROTOCOL)
1011
val BearerTokenIdentity = runtimeSymbol("BearerTokenIdentity", SwiftDeclaration.STRUCT)
11-
val StaticBearerTokenIdentityResolver = runtimeSymbol("StaticBearerTokenIdentityResolver", SwiftDeclaration.STRUCT)
12-
val StaticAWSCredentialIdentityResolver = runtimeSymbol("StaticAWSCredentialIdentityResolver", SwiftDeclaration.STRUCT)
12+
val StaticAWSCredentialIdentityResolver =
13+
runtimeSymbol("StaticAWSCredentialIdentityResolver", SwiftDeclaration.STRUCT, listOf("StaticAWSCredentialIdentityResolver"))
14+
val StaticBearerTokenIdentityResolver =
15+
runtimeSymbol("StaticBearerTokenIdentityResolver", SwiftDeclaration.STRUCT, listOf("StaticBearerTokenIdentityResolver"))
1316
}
1417

1518
private fun runtimeSymbol(
1619
name: String,
1720
declaration: SwiftDeclaration? = null,
21+
spiNames: List<String> = listOf(),
1822
): Symbol =
1923
SwiftSymbol.make(
2024
name,
2125
declaration,
2226
SwiftDependency.SMITHY_IDENTITY,
2327
emptyList(),
24-
emptyList(),
28+
spiNames,
2529
)

0 commit comments

Comments
 (0)