Skip to content

Commit

Permalink
fix: maybe overwrite user's existed cors rules for the s3
Browse files Browse the repository at this point in the history
  • Loading branch information
saltbo committed Jan 23, 2021
1 parent 647edb1 commit 126ca2c
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions provider/provider_s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,29 @@ func newS3Provider(conf Config) (*S3Provider, error) {
}

func (p *S3Provider) SetupCORS() error {
output, err := p.client.GetBucketCors(&s3.GetBucketCorsInput{Bucket: aws.String(p.bucket)})
if err != nil {
return err
}

allowedHeaders := make([]*string, 0)
for _, header := range corsAllowHeaders {
allowedHeaders = append(allowedHeaders, aws.String(header))
}
output.CORSRules = append(output.CORSRules, &s3.CORSRule{
AllowedOrigins: []*string{aws.String("*")},
AllowedMethods: []*string{aws.String("PUT")},
AllowedHeaders: allowedHeaders,
MaxAgeSeconds: aws.Int64(300),
})

input := &s3.PutBucketCorsInput{
Bucket: aws.String(p.bucket),
CORSConfiguration: &s3.CORSConfiguration{
CORSRules: []*s3.CORSRule{
{
AllowedOrigins: []*string{aws.String("*")},
AllowedMethods: []*string{aws.String("PUT")},
AllowedHeaders: allowedHeaders,
MaxAgeSeconds: aws.Int64(300),
},
},
CORSRules: output.CORSRules,
},
}
_, err := p.client.PutBucketCors(input)
_, err = p.client.PutBucketCors(input)
return err
}

Expand Down

0 comments on commit 126ca2c

Please sign in to comment.