From 126ca2ceac74e7760e2e5981a6a6204a034421d3 Mon Sep 17 00:00:00 2001 From: saltbo Date: Sun, 24 Jan 2021 00:04:39 +0800 Subject: [PATCH] fix: maybe overwrite user's existed cors rules for the s3 --- provider/provider_s3.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/provider/provider_s3.go b/provider/provider_s3.go index 26c1b95..5e526f6 100644 --- a/provider/provider_s3.go +++ b/provider/provider_s3.go @@ -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 }