@@ 9,10 9,11 @@ import (
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
+ "golang.org/x/exp/slices"
)
// https://docs.aws.amazon.com/AmazonS3/latest/userguide/acl-overview.html#canned-acl
-var s3CannedACL []string = []string{
+var s3CannedACL = []string{
"private",
"public-read",
"public-read-write",
@@ 59,20 60,20 @@ func NewS3Service(endpoint, bucket string, opts *S3Options) (*S3Service, error)
Client: client,
Prefix: opts.Prefix,
}
- if opts.ACL == "" {
- opts.ACL = "private"
+ if opts.ACL != "" {
+ err = service.SetACL(opts.ACL)
+ if err != nil {
+ return nil, err
+ }
}
- service.SetACL(opts.ACL)
return service, nil
}
// SetACL sets the s3 acl header to be used for future ops.
func (s *S3Service) SetACL(acl string) error {
- for _, x := range s3CannedACL {
- if x == acl {
- s.perm = acl
- return nil
- }
+ if slices.Contains(s3CannedACL, acl) {
+ s.perm = acl
+ return nil
}
return fmt.Errorf("Provided ACL '%s' is invalid", acl)
}
@@ 134,7 135,9 @@ func (s *S3Service) PutObject(ctx context.Context, path string, content io.Reade
var data bytes.Buffer
fullpath := pathutil.Join(s.Prefix, path)
meta := make(map[string]string)
- meta["x-amz-acl"] = s.perm
+ if s.perm != "" {
+ meta["x-amz-acl"] = s.perm
+ }
_, err := io.Copy(&data, content)
if err != nil {
return err