diff --git a/Sources/SmithyIdentity/AWSCredentialIdentityResolvers/StaticAWSCredentialIdentityResolver.swift b/Sources/SmithyIdentity/AWSCredentialIdentityResolvers/StaticAWSCredentialIdentityResolver.swift index fc1e7a8d1..87d018c8e 100644 --- a/Sources/SmithyIdentity/AWSCredentialIdentityResolvers/StaticAWSCredentialIdentityResolver.swift +++ b/Sources/SmithyIdentity/AWSCredentialIdentityResolvers/StaticAWSCredentialIdentityResolver.swift @@ -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 } } + +@_spi(ClientConfigDefaultIdentityResolver) +extension StaticAWSCredentialIdentityResolver: ClientConfigDefaultIdentityResolver { + + public var isClientConfigDefault: Bool { + self.credentials.accessKey.isEmpty && self.credentials.secret.isEmpty + } +} diff --git a/Sources/SmithyIdentity/BearerTokenIdentityResolvers/StaticBearerTokenIdentityResolver.swift b/Sources/SmithyIdentity/BearerTokenIdentityResolvers/StaticBearerTokenIdentityResolver.swift index ff4888820..792752515 100644 --- a/Sources/SmithyIdentity/BearerTokenIdentityResolvers/StaticBearerTokenIdentityResolver.swift +++ b/Sources/SmithyIdentity/BearerTokenIdentityResolvers/StaticBearerTokenIdentityResolver.swift @@ -5,11 +5,17 @@ // SPDX-License-Identifier: Apache-2.0 // +@_spi(ClientConfigDefaultIdentityResolver) import protocol SmithyIdentityAPI.ClientConfigDefaultIdentityResolver 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 + } +} diff --git a/Sources/SmithyIdentityAPI/ClientConfigDefaultIdentityResolver.swift b/Sources/SmithyIdentityAPI/ClientConfigDefaultIdentityResolver.swift new file mode 100644 index 000000000..dd1dd6934 --- /dev/null +++ b/Sources/SmithyIdentityAPI/ClientConfigDefaultIdentityResolver.swift @@ -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. + +@_spi(ClientConfigDefaultIdentityResolver) +public protocol ClientConfigDefaultIdentityResolver: IdentityResolver { + + /// Indicates whether this identity resolver was provided as a client config default. + var isClientConfigDefault: Bool { get } +} diff --git a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/AuthSchemeResolverGenerator.kt b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/AuthSchemeResolverGenerator.kt index a90d2cd6b..268aa9cb8 100644 --- a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/AuthSchemeResolverGenerator.kt +++ b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/AuthSchemeResolverGenerator.kt @@ -132,7 +132,7 @@ class AuthSchemeResolverGenerator( // Model-based auth scheme resolver should be private internal impl detail if service uses rules-based resolver. val accessModifier = if (usesRulesBasedResolver) "private" else "public" val resolvedAccessModifier = - if (accessModifier == "public" && ctx.settings.visibility == "internal") { + if (accessModifier == "public" && ctx.settings.internalClient) { ctx.settings.visibility } else { accessModifier diff --git a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/SwiftDependency.kt b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/SwiftDependency.kt index 631d33338..0a20e6f88 100644 --- a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/SwiftDependency.kt +++ b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/SwiftDependency.kt @@ -52,19 +52,8 @@ class SwiftDependency( "", DistributionMethod.GIT, ) - val CRT = - SwiftDependency( - "AwsCommonRuntimeKit", - null, - "0.52.1", - "https://github.com/awslabs/aws-crt-swift", - "", - "aws-crt-swift", - DistributionMethod.GIT, - ) val CLIENT_RUNTIME = smithySwiftDependency("ClientRuntime") val SMITHY = smithySwiftDependency("Smithy") - val SMITHY_IDENTITY_API = smithySwiftDependency("SmithyIdentityAPI") val SMITHY_IDENTITY = smithySwiftDependency("SmithyIdentity") val SMITHY_RETRIES_API = smithySwiftDependency("SmithyRetriesAPI") val SMITHY_RETRIES = smithySwiftDependency("SmithyRetries") diff --git a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/SwiftSettings.kt b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/SwiftSettings.kt index 3c6f4366f..d52c734d2 100644 --- a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/SwiftSettings.kt +++ b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/SwiftSettings.kt @@ -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, 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, ) } diff --git a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/lang/AccessModifier.kt b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/lang/AccessModifier.kt index db97cd689..1f28142fd 100644 --- a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/lang/AccessModifier.kt +++ b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/lang/AccessModifier.kt @@ -15,6 +15,7 @@ enum class AccessModifier { PublicPrivateSet, Internal, Private, + Package, None, ; @@ -27,6 +28,7 @@ enum class AccessModifier { PublicPrivateSet -> "public private(set)" Internal -> "internal" Private -> "private" + Package -> "package" None -> "" } diff --git a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/lang/ReservedWords.kt b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/lang/ReservedWords.kt index 259806e6e..89246d8b5 100644 --- a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/lang/ReservedWords.kt +++ b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/lang/ReservedWords.kt @@ -83,6 +83,7 @@ val reservedWords = "operator", "optional", "override", + "package", "postfix", "prefix", "private", diff --git a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftmodules/ClientRuntimeTypes.kt b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftmodules/ClientRuntimeTypes.kt index 0ec7491eb..928486d99 100644 --- a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftmodules/ClientRuntimeTypes.kt +++ b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftmodules/ClientRuntimeTypes.kt @@ -108,12 +108,12 @@ private fun runtimeSymbol( name: String, declaration: SwiftDeclaration?, additionalImports: List = emptyList(), - spiName: List = emptyList(), + spiNames: List = emptyList(), ): Symbol = SwiftSymbol.make( name, declaration, SwiftDependency.CLIENT_RUNTIME.takeIf { additionalImports.isEmpty() }, additionalImports, - spiName, + spiNames, ) diff --git a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftmodules/SmithyIdentityTypes.kt b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftmodules/SmithyIdentityTypes.kt index a0e1bf722..47e3ddc3d 100644 --- a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftmodules/SmithyIdentityTypes.kt +++ b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftmodules/SmithyIdentityTypes.kt @@ -5,21 +5,25 @@ import software.amazon.smithy.swift.codegen.SwiftDeclaration import software.amazon.smithy.swift.codegen.SwiftDependency object SmithyIdentityTypes { - val AWSCredentialIdentityResolver = runtimeSymbol("AWSCredentialIdentityResolver", SwiftDeclaration.PROTOCOL) + val AWSCredentialIdentityResolver = + runtimeSymbol("AWSCredentialIdentityResolver", SwiftDeclaration.PROTOCOL, listOf("AWSCredentialIdentityResolver")) val BearerTokenIdentityResolver = runtimeSymbol("BearerTokenIdentityResolver", SwiftDeclaration.PROTOCOL) val BearerTokenIdentity = runtimeSymbol("BearerTokenIdentity", SwiftDeclaration.STRUCT) - val StaticBearerTokenIdentityResolver = runtimeSymbol("StaticBearerTokenIdentityResolver", SwiftDeclaration.STRUCT) - val StaticAWSCredentialIdentityResolver = runtimeSymbol("StaticAWSCredentialIdentityResolver", SwiftDeclaration.STRUCT) + val StaticAWSCredentialIdentityResolver = + runtimeSymbol("StaticAWSCredentialIdentityResolver", SwiftDeclaration.STRUCT, listOf("StaticAWSCredentialIdentityResolver")) + val StaticBearerTokenIdentityResolver = + runtimeSymbol("StaticBearerTokenIdentityResolver", SwiftDeclaration.STRUCT, listOf("StaticBearerTokenIdentityResolver")) } private fun runtimeSymbol( name: String, declaration: SwiftDeclaration? = null, + spiNames: List = listOf(), ): Symbol = SwiftSymbol.make( name, declaration, SwiftDependency.SMITHY_IDENTITY, emptyList(), - emptyList(), + spiNames, ) diff --git a/smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/codegencomponents/SwiftSettingsTest.kt b/smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/codegencomponents/SwiftSettingsTest.kt index 43c4024e8..ca8e18ecd 100644 --- a/smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/codegencomponents/SwiftSettingsTest.kt +++ b/smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/codegencomponents/SwiftSettingsTest.kt @@ -39,6 +39,7 @@ class SwiftSettingsTest { assertEquals("Amazon Web Services", settings.author) assertEquals("https://github.com/aws-amplify/amplify-codegen.git", settings.gitRepo) assertEquals(false, settings.mergeModels) + assertEquals(false, settings.internalClient) } // Smithy Protocol Selection Tests @@ -193,6 +194,7 @@ class SwiftSettingsTest { copyrightNotice = "// Test copyright", visibility = "public", forProtocolTests = false, + internalClient = false, ) private fun createServiceWithProtocols(protocols: Set): ServiceShape {