Skip to content

Commit

Permalink
Merge pull request #533 from soruma/fix-default-s3-location
Browse files Browse the repository at this point in the history
Fixed a bug when a bucket was placed in us-east-1
  • Loading branch information
k1LoW authored May 8, 2021
2 parents 671b482 + b0a8db5 commit 3828f82
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
6 changes: 5 additions & 1 deletion lib/awspec/helper/finder/s3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ def find_bucket_policy(id)

def find_bucket_location(id)
bucket_location = s3_client.get_bucket_location(bucket: id)
bucket_location.location_constraint
if bucket_location.location_constraint.nil? || bucket_location.location_constraint.empty?
'us-east-1'
else
bucket_location.location_constraint
end
rescue Aws::S3::Errors::ServiceError
nil
end
Expand Down
2 changes: 1 addition & 1 deletion lib/awspec/stub/s3_bucket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
]
},
get_bucket_location: {
location_constraint: 'us-east-1'
location_constraint: 'ap-northeast-1'
},
get_bucket_encryption: {
server_side_encryption_configuration: {
Expand Down
2 changes: 1 addition & 1 deletion spec/generator/spec/s3_bucket_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
status: 'Enabled'
)
end
it { should have_location('us-east-1') }
it { should have_location('ap-northeast-1') }
end
EOF
expect(s3_bucket.generate_all.to_s).to eq spec
Expand Down
17 changes: 16 additions & 1 deletion spec/type/s3_bucket_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
it { should have_acl_grant(grantee: 'my-bucket-owner', permission: 'FULL_CONTROL') }
it { should have_acl_grant(grantee: 'http://acs.amazonaws.com/groups/s3/LogDelivery', permission: 'WRITE') }
it { should have_acl_grant(grantee: '68f4bb06b094152df53893bfba57760e', permission: 'READ') }
it { should have_location('us-east-1') }

it do
should have_cors_rule(
Expand Down Expand Up @@ -68,6 +67,22 @@
end
end

describe s3_bucket('my-bucket') do
context 'with bucket location is not blank' do
it { should have_location('ap-northeast-1') }
end

context 'with bucket location is blank' do
before do
Aws.config[:s3][:stub_responses][:get_bucket_location][:location_constraint] = ''
end

it 'should location be us-east-1' do
should have_location('us-east-1')
end
end
end

describe s3_bucket('my-bucket') do
it do
should have_lifecycle_rule(
Expand Down

0 comments on commit 3828f82

Please sign in to comment.