soto-project / soto

Swift SDK for AWS that works on Linux, macOS and iOS
https://soto.codes
Apache License 2.0
875 stars 83 forks source link

CloudFront HttpVersion can't handle lowercase values #567

Closed jkirsteins closed 2 years ago

jkirsteins commented 2 years ago

Describe the bug

When creating a new CloudFront distribution:

// Cannot initialize HttpVersion from invalid String value http2

dataCorrupted(
    Swift.DecodingError.Context(
        codingPath: [
            CodingKeys(stringValue: \"Distribution\", intValue: nil), 
            CodingKeys(stringValue: \"DistributionConfig\", intValue: nil), 
            CodingKeys(stringValue: \"HttpVersion\", intValue: nil)
        ], 
        debugDescription: \"Cannot initialize HttpVersion from invalid String value http2\", underlyingError: nil
    )
)

To Reproduce

let config = CloudFront.DistributionConfig(
    callerReference: callerRef,
    comment: "",
    defaultCacheBehavior: CloudFront.DefaultCacheBehavior(
        allowedMethods: CloudFront.AllowedMethods(
            cachedMethods: nil,
            items: [.get, .head, .options],
            quantity: 3),
        cachePolicyId: policyId,
        targetOriginId: "default",
        viewerProtocolPolicy: CloudFront.ViewerProtocolPolicy.redirectToHttps),
    defaultRootObject: "index.html",
    enabled: true,
    origins: CloudFront.Origins(items: [
        CloudFront.Origin(
            customOriginConfig: CloudFront.CustomOriginConfig(
                hTTPPort: 80,
                hTTPSPort: 443,
                originProtocolPolicy: CloudFront.OriginProtocolPolicy.httpsOnly),
            domainName: domain,
            id: "default",  
            originPath: pathPrefix
        )
    ], quantity: 1)
)
let req = CloudFront.CreateDistributionRequest(distributionConfig: config)
let resp = try await cfClient.createDistribution(req)

Expected behavior

A successful response.

Setup (please complete the following information):

jkirsteins commented 2 years ago

Judging by https://docs.aws.amazon.com/cloudfront/latest/APIReference/API_DistributionConfig.html the enum values should be:

I can confirm that the API calls work with these values. However, it looks like this was deliberately changed here: https://github.com/soto-project/soto-codegenerator/blob/3778d74bb9f7d6b93d84fdac80a7bc3e656bac2e/Sources/SotoCodeGenerator/Model%2BPatch.swift#L26

I'm not sure why it was changed, so I'm not submitting a PR to fix it. However, as-is, calls involving DistributionConfig structures are broken.

adam-fowler commented 2 years ago

I was just looking at this. The commit message that went with the patch wasn't very helpful. I have now found the reason. HttpVersion is used in both DistributionConfig and DistributionSummary. In one it is uppercase and in the other it is lowercase.

Try running CloudFront.ListDistributions you'll see it returns a DistributionSummary with an uppercase HTTP enum.

adam-fowler commented 2 years ago

Do you want to try fix #568

jkirsteins commented 2 years ago

Thanks for the prompt response. I can confirm revision f70bd19ff7dc296294d992ad226cac55a9d6d8f8 works simultaneously for:

adam-fowler commented 2 years ago

Released in v5.12.0