Skip to content

Commit

Permalink
added acl option
Browse files Browse the repository at this point in the history
  • Loading branch information
adranwit committed Aug 7, 2021
1 parent 7f3ab51 commit d085027
Showing 1 changed file with 32 additions and 30 deletions.
62 changes: 32 additions & 30 deletions s3/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ func (s *storager) upload(ctx context.Context, destination string, mode os.FileM
serverSideEncryption := &option.ServerSideEncryption{}
stream := &option.Stream{}
grant := &option.Grant{}
option.Assign(options, &md5Hash, &key, &checksum, &meta, &serverSideEncryption, &stream)
_, hasGrant := option.Assign(options, &grant)
acl := &option.ACL{}
option.Assign(options, &md5Hash, &key, &checksum, &meta, &serverSideEncryption, &stream, &grant, &acl)
if !checksum.Skip {
input := &s3.PutObjectInput{
Bucket: &s.bucket,
Expand All @@ -61,19 +61,21 @@ func (s *storager) upload(ctx context.Context, destination string, mode os.FileM
input.Metadata[contentMD5MetaKey] = input.ContentMD5
input.Body = bytes.NewReader(content)

if hasGrant {
if grant.FullControl != "" {
input.GrantFullControl = &grant.FullControl
}
if grant.FullControl != "" {
input.GrantRead = &grant.Read
}
if grant.FullControl != "" {
input.GrantReadACP = &grant.ReadACP
}
if grant.FullControl != "" {
input.GrantWriteACP = &grant.WriteACP
}
if acl.ACL != "" {
input.ACL = &acl.ACL
}

if grant.FullControl != "" {
input.GrantFullControl = &grant.FullControl
}
if grant.FullControl != "" {
input.GrantRead = &grant.Read
}
if grant.FullControl != "" {
input.GrantReadACP = &grant.ReadACP
}
if grant.FullControl != "" {
input.GrantWriteACP = &grant.WriteACP
}

if len(key.Key) > 0 {
Expand Down Expand Up @@ -117,20 +119,22 @@ func (s *storager) upload(ctx context.Context, destination string, mode os.FileM
Body: reader,
Metadata: map[string]*string{},
}
if hasGrant {
if grant.FullControl != "" {
input.GrantFullControl = &grant.FullControl
}
if grant.FullControl != "" {
input.GrantRead = &grant.Read
}
if grant.FullControl != "" {
input.GrantReadACP = &grant.ReadACP
}
if grant.FullControl != "" {
input.GrantWriteACP = &grant.WriteACP
}
if grant.FullControl != "" {
input.GrantFullControl = &grant.FullControl
}
if grant.FullControl != "" {
input.GrantRead = &grant.Read
}
if grant.FullControl != "" {
input.GrantReadACP = &grant.ReadACP
}
if grant.FullControl != "" {
input.GrantWriteACP = &grant.WriteACP
}
if acl.ACL != "" {
input.ACL = &acl.ACL
}

if len(meta.Values) > 0 {
for k := range meta.Values {
value := meta.Values[k]
Expand Down Expand Up @@ -165,8 +169,6 @@ func (s *storager) upload(ctx context.Context, destination string, mode os.FileM
return err
}



func updateMetaContent(meta *content.Meta, input *s3.PutObjectInput) {
if len(meta.Values) > 0 {
for k := range meta.Values {
Expand Down

0 comments on commit d085027

Please sign in to comment.