Fix bucket policy return err when no policy exist

main
Elie 2021-07-06 10:47:28 +02:00
parent 106366a628
commit a560d84b25
No known key found for this signature in database
GPG Key ID: 399AF69092C727B6
2 changed files with 19 additions and 0 deletions

View File

@ -58,6 +58,11 @@ func (s *s3Repository) GetBucketPolicy(bucketName, region string) (*string, erro
&s3.GetBucketPolicyInput{Bucket: &bucketName}, &s3.GetBucketPolicyInput{Bucket: &bucketName},
) )
if err != nil { if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
if awsErr.Code() == "NoSuchBucketPolicy" {
return nil, nil
}
}
return nil, errors.Wrapf( return nil, errors.Wrapf(
err, err,
"Error listing bucket policy %s", "Error listing bucket policy %s",

View File

@ -297,6 +297,20 @@ func Test_s3Repository_GetBucketPolicy(t *testing.T) {
}, },
want: awssdk.String("foobar"), want: awssdk.String("foobar"),
}, },
{
name: "get bucket location on 404",
bucketName: "test-bucket",
region: "us-east-1",
mocks: func(client *awstest.MockFakeS3) {
client.On("GetBucketPolicy", &s3.GetBucketPolicyInput{
Bucket: aws.String("test-bucket"),
}).Return(
nil,
awserr.New("NoSuchBucketPolicy", "", nil),
).Once()
},
want: nil,
},
{ {
name: "get bucket location when error", name: "get bucket location when error",
bucketName: "test-bucket", bucketName: "test-bucket",