Fix bucket policy return err when no policy exist
parent
106366a628
commit
a560d84b25
|
@ -58,6 +58,11 @@ func (s *s3Repository) GetBucketPolicy(bucketName, region string) (*string, erro
|
|||
&s3.GetBucketPolicyInput{Bucket: &bucketName},
|
||||
)
|
||||
if err != nil {
|
||||
if awsErr, ok := err.(awserr.Error); ok {
|
||||
if awsErr.Code() == "NoSuchBucketPolicy" {
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
return nil, errors.Wrapf(
|
||||
err,
|
||||
"Error listing bucket policy %s",
|
||||
|
|
|
@ -297,6 +297,20 @@ func Test_s3Repository_GetBucketPolicy(t *testing.T) {
|
|||
},
|
||||
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",
|
||||
bucketName: "test-bucket",
|
||||
|
|
Loading…
Reference in New Issue