-
Notifications
You must be signed in to change notification settings - Fork 33
chore: Refactor internal clients #952
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8484c8c
45eb26f
1c5c313
122d5dd
c143801
083c81e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,11 +5,17 @@ | |
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
@_spi(ClientConfigDefaultIdentityResolver) import protocol SmithyIdentityAPI.ClientConfigDefaultIdentityResolver | ||
import struct Smithy.Attributes | ||
|
||
/// A credential identity resolver that provides a fixed set of credentials | ||
public struct StaticAWSCredentialIdentityResolver: AWSCredentialIdentityResolver { | ||
private let credentials: AWSCredentialIdentity | ||
fileprivate let credentials: AWSCredentialIdentity | ||
|
||
@_spi(StaticAWSCredentialIdentityResolver) | ||
public init() { | ||
self.credentials = AWSCredentialIdentity(accessKey: "", secret: "") | ||
} | ||
|
||
/// Creates a credential identity resolver for a fixed set of credentials | ||
/// | ||
|
@@ -24,3 +30,11 @@ public struct StaticAWSCredentialIdentityResolver: AWSCredentialIdentityResolver | |
return credentials | ||
} | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
@_spi(ClientConfigDefaultIdentityResolver) | ||
extension StaticAWSCredentialIdentityResolver: ClientConfigDefaultIdentityResolver { | ||
|
||
public var isClientConfigDefault: Bool { | ||
self.credentials.accessKey.isEmpty && self.credentials.secret.isEmpty | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,11 +5,17 @@ | |
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
@_spi(ClientConfigDefaultIdentityResolver) import protocol SmithyIdentityAPI.ClientConfigDefaultIdentityResolver | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pretty much the same changes in this |
||
import struct Smithy.Attributes | ||
|
||
/// The token identity resolver that returns a static token identity given to it at initialization. | ||
public struct StaticBearerTokenIdentityResolver: BearerTokenIdentityResolver { | ||
private let token: BearerTokenIdentity | ||
fileprivate let token: BearerTokenIdentity | ||
|
||
@_spi(StaticBearerTokenIdentityResolver) | ||
public init() { | ||
self.token = BearerTokenIdentity(token: "") | ||
} | ||
|
||
public init(token: BearerTokenIdentity) { | ||
self.token = token | ||
|
@@ -19,3 +25,11 @@ public struct StaticBearerTokenIdentityResolver: BearerTokenIdentityResolver { | |
return token | ||
} | ||
} | ||
|
||
@_spi(ClientConfigDefaultIdentityResolver) | ||
extension StaticBearerTokenIdentityResolver: ClientConfigDefaultIdentityResolver { | ||
|
||
public var isClientConfigDefault: Bool { | ||
token.token.isEmpty | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
/// 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. | ||
/// | ||
/// Resolvers that do not implement this protocol should be presumed to not be a client config default. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The protocol below is used to determine if a credential resolver came from client config defaults. It's protected with |
||
@_spi(ClientConfigDefaultIdentityResolver) | ||
public protocol ClientConfigDefaultIdentityResolver: IdentityResolver { | ||
|
||
/// Indicates whether this identity resolver was provided as a client config default. | ||
var isClientConfigDefault: Bool { get } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ private const val SWIFT_VERSION = "swiftVersion" | |
private const val MERGE_MODELS = "mergeModels" | ||
private const val COPYRIGHT_NOTICE = "copyrightNotice" | ||
private const val VISIBILITY = "visibility" | ||
private const val INTERNAL_CLIENT = "internalClient" | ||
private const val FOR_PROTOCOL_TESTS = "forProtocolTests" | ||
|
||
// Prioritized list of protocols supported for code generation | ||
|
@@ -64,6 +65,7 @@ class SwiftSettings( | |
val mergeModels: Boolean, | ||
val copyrightNotice: String, | ||
val visibility: String, | ||
val internalClient: Boolean, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added this |
||
val forProtocolTests: Boolean, | ||
) { | ||
companion object { | ||
|
@@ -120,6 +122,7 @@ class SwiftSettings( | |
"// Code generated by smithy-swift-codegen. DO NOT EDIT!\n\n", | ||
) | ||
val visibility = config.getStringMemberOrDefault(VISIBILITY, "public") | ||
val internalClient = config.getBooleanMemberOrDefault(INTERNAL_CLIENT, false) | ||
val forProtocolTests = config.getBooleanMemberOrDefault(FOR_PROTOCOL_TESTS, false) | ||
|
||
return SwiftSettings( | ||
|
@@ -135,6 +138,7 @@ class SwiftSettings( | |
mergeModels, | ||
copyrightNotice, | ||
visibility, | ||
internalClient, | ||
forProtocolTests, | ||
) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ enum class AccessModifier { | |
PublicPrivateSet, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As of Swift 5.9 Adding it to this enum along with the existing levels. |
||
Internal, | ||
Private, | ||
Package, | ||
None, | ||
; | ||
|
||
|
@@ -27,6 +28,7 @@ enum class AccessModifier { | |
PublicPrivateSet -> "public private(set)" | ||
Internal -> "internal" | ||
Private -> "private" | ||
Package -> "package" | ||
None -> "" | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,6 +83,7 @@ val reservedWords = | |
"operator", | ||
"optional", | ||
"override", | ||
"package", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding There actually do seem to be services that already use |
||
"postfix", | ||
"prefix", | ||
"private", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,12 +108,12 @@ private fun runtimeSymbol( | |
name: String, | ||
declaration: SwiftDeclaration?, | ||
additionalImports: List<Symbol> = emptyList(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just fixed a typo in this file |
||
spiName: List<String> = emptyList(), | ||
spiNames: List<String> = emptyList(), | ||
): Symbol = | ||
SwiftSymbol.make( | ||
name, | ||
declaration, | ||
SwiftDependency.CLIENT_RUNTIME.takeIf { additionalImports.isEmpty() }, | ||
additionalImports, | ||
spiName, | ||
spiNames, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
@_spi
initializer below creates a AWS credential identity resolver with empty credentials. This is used in internal clients, where the default AWS credential identity resolver is never used.