|
| 1 | +// Code generated by smithy-swift-codegen. DO NOT EDIT! |
| 2 | + |
| 3 | +import ClientRuntime |
| 4 | + |
| 5 | +public struct WeatherAuthSchemeResolverParameters: ClientRuntime.AuthSchemeResolverParameters { |
| 6 | + public let operation: String |
| 7 | + // Region is used for SigV4 auth scheme |
| 8 | + public let region: String? |
| 9 | +} |
| 10 | + |
| 11 | +public protocol WeatherAuthSchemeResolver: ClientRuntime.AuthSchemeResolver { |
| 12 | + // Intentionally empty. |
| 13 | + // This is the parent protocol that all auth scheme resolver implementations of |
| 14 | + // the service Weather must conform to. |
| 15 | +} |
| 16 | + |
| 17 | +public struct DefaultWeatherAuthSchemeResolver: WeatherAuthSchemeResolver { |
| 18 | + public func resolveAuthScheme(params: ClientRuntime.AuthSchemeResolverParameters) throws -> [AuthOption] { |
| 19 | + var validAuthOptions = [AuthOption]() |
| 20 | + guard let serviceParams = params as? WeatherAuthSchemeResolverParameters else { |
| 21 | + throw ClientError.authError("Service specific auth scheme parameters type must be passed to auth scheme resolver.") |
| 22 | + } |
| 23 | + switch serviceParams.operation { |
| 24 | + case "onlyHttpApiKeyAuth": |
| 25 | + validAuthOptions.append(AuthOption(schemeID: "smithy.api#httpApiKeyAuth")) |
| 26 | + case "onlyHttpApiKeyAuthOptional": |
| 27 | + validAuthOptions.append(AuthOption(schemeID: "smithy.api#httpApiKeyAuth")) |
| 28 | + validAuthOptions.append(AuthOption(schemeID: "smithy.api#noAuth")) |
| 29 | + case "onlyHttpBearerAuth": |
| 30 | + validAuthOptions.append(AuthOption(schemeID: "smithy.api#httpBearerAuth")) |
| 31 | + case "onlyHttpBearerAuthOptional": |
| 32 | + validAuthOptions.append(AuthOption(schemeID: "smithy.api#httpBearerAuth")) |
| 33 | + validAuthOptions.append(AuthOption(schemeID: "smithy.api#noAuth")) |
| 34 | + case "onlyHttpApiKeyAndBearerAuth": |
| 35 | + validAuthOptions.append(AuthOption(schemeID: "smithy.api#httpApiKeyAuth")) |
| 36 | + validAuthOptions.append(AuthOption(schemeID: "smithy.api#httpBearerAuth")) |
| 37 | + case "onlyHttpApiKeyAndBearerAuthReversed": |
| 38 | + validAuthOptions.append(AuthOption(schemeID: "smithy.api#httpBearerAuth")) |
| 39 | + validAuthOptions.append(AuthOption(schemeID: "smithy.api#httpApiKeyAuth")) |
| 40 | + case "onlySigv4Auth": |
| 41 | + var sigV4Option = AuthOption(schemeID: "aws.auth#sigv4") |
| 42 | + sigV4Option.signingProperties.set(key: AttributeKeys.signingName, value: "weather") |
| 43 | + guard let region = serviceParams.region else { |
| 44 | + throw ClientError.authError("Missing region in auth scheme parameters for SigV4 auth scheme.") |
| 45 | + } |
| 46 | + sigV4Option.signingProperties.set(key: AttributeKeys.signingRegion, value: region) |
| 47 | + validAuthOptions.append(sigV4Option) |
| 48 | + case "onlySigv4AuthOptional": |
| 49 | + var sigV4Option = AuthOption(schemeID: "aws.auth#sigv4") |
| 50 | + sigV4Option.signingProperties.set(key: AttributeKeys.signingName, value: "weather") |
| 51 | + guard let region = serviceParams.region else { |
| 52 | + throw ClientError.authError("Missing region in auth scheme parameters for SigV4 auth scheme.") |
| 53 | + } |
| 54 | + sigV4Option.signingProperties.set(key: AttributeKeys.signingRegion, value: region) |
| 55 | + validAuthOptions.append(sigV4Option) |
| 56 | + validAuthOptions.append(AuthOption(schemeID: "smithy.api#noAuth")) |
| 57 | + case "onlyFakeAuth": |
| 58 | + validAuthOptions.append(AuthOption(schemeID: "common#fakeAuth")) |
| 59 | + case "onlyFakeAuthOptional": |
| 60 | + validAuthOptions.append(AuthOption(schemeID: "common#fakeAuth")) |
| 61 | + validAuthOptions.append(AuthOption(schemeID: "smithy.api#noAuth")) |
| 62 | + default: |
| 63 | + var sigV4Option = AuthOption(schemeID: "aws.auth#sigv4") |
| 64 | + sigV4Option.signingProperties.set(key: AttributeKeys.signingName, value: "weather") |
| 65 | + guard let region = serviceParams.region else { |
| 66 | + throw ClientError.authError("Missing region in auth scheme parameters for SigV4 auth scheme.") |
| 67 | + } |
| 68 | + sigV4Option.signingProperties.set(key: AttributeKeys.signingRegion, value: region) |
| 69 | + validAuthOptions.append(sigV4Option) |
| 70 | + } |
| 71 | + return validAuthOptions |
| 72 | + } |
| 73 | + |
| 74 | + public func constructParameters(context: HttpContext) throws -> ClientRuntime.AuthSchemeResolverParameters { |
| 75 | + guard let opName = context.getOperation() else { |
| 76 | + throw ClientError.dataNotFound("Operation name not configured in middleware context for auth scheme resolver params construction.") |
| 77 | + } |
| 78 | + let opRegion = context.getRegion() |
| 79 | + return WeatherAuthSchemeResolverParameters(operation: opName, region: opRegion) |
| 80 | + } |
| 81 | +} |
0 commit comments