soto-project / soto

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

GetBucketLocation fails for any bucket in us-east-1 (v3) #502

Closed rausnitz closed 3 years ago

rausnitz commented 3 years ago

Describe the bug When I send a request to GetBucketLocation for a bucket in region us-east-1, I get the following error:

▿ ⚠️ DecodingError: Cannot initialize BucketLocationConstraint from invalid String value 
- id: DecodingError.dataCorrupted

  ▿ dataCorrupted : Context
    ▿ codingPath : 1 element
      - 0 : CodingKeys(stringValue: "LocationConstraint", intValue: nil)
    - debugDescription : "Cannot initialize BucketLocationConstraint from invalid String value "
    - underlyingError : nil

According to the AWS docs, Buckets in Region us-east-1 have a LocationConstraint of null.

To Reproduce Steps to reproduce the behavior:

public static func getBucketLocation() -> EventLoopFuture<S3.GetBucketLocationOutput> {
    let request = S3.GetBucketLocationRequest(bucket: "some-us-east-1-bucket")
    return S3().getBucketLocation(request)
}

Expected behavior The function should return a GetBucketLocationOutput where locationConstraint is nil, instead of failing to decode the GetBucketLocationOutput.

Setup (please complete the following information):

Additional context n/a

adam-fowler commented 3 years ago

I'm assuming you can't upgrade to v4.0. I'm not really supporting v3.x anymore.

Adding us-east-1 to this enum should fix the issue https://github.com/soto-project/soto/blob/08d3c295049cca3494203125277285ef223189cd/Sources/AWSSDKSwift/Services/S3/S3_Shapes.swift#L336-L339

If you want to make a PR to 3.x.x branch please do so. I can make a release with the change in after

rausnitz commented 3 years ago

Yeah I figured v3 isn't getting updates.

In any case I don't think your suggestion of adding us-east-1 to that enum would fix the issue. See above: Buckets in Region us-east-1 have a LocationConstraint of null.

I tested this in a few regions.

When the bucket is in us-west-2, the value of node on AWSClient.swift line 565 is:

<BucketLocation><LocationConstraint xmlns="http://s3.amazonaws.com/doc/2006-03-01/">us-west-2</LocationConstraint></BucketLocation>

When the bucket is in us-east-1, the value of node on AWSClient.swift line 565 is:

<BucketLocation><LocationConstraint xmlns="http://s3.amazonaws.com/doc/2006-03-01/"></LocationConstraint></BucketLocation>

These XML results are both expected. However in the latter case, the decoded GetBucketLocationOutput.locationConstraint value should be nil but instead there is a decoding error.

adam-fowler commented 3 years ago

Yes you are right. This was fixed in v5 here https://github.com/soto-project/soto/commit/f98cea6ae2ed1e13b1b6aa827d0dbb265a178fd8

adam-fowler commented 3 years ago

Given NIO 1.0 and Vapor 3.0 are no longer supported there will be no new updates to Soto v3 either