Skip to content

Commit

Permalink
Merge pull request #183 from Charliekenney23/fix/no-empty-content-attrs
Browse files Browse the repository at this point in the history
don't send empty content attributes for OBJ objects
  • Loading branch information
0xch4z committed Sep 22, 2020
2 parents 1d275c7 + 0adbdc9 commit 0b3434e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
7 changes: 0 additions & 7 deletions linode/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ func expandStringList(list []interface{}) []string {
return slice
}

func expandStringPointer(v interface{}) *string {
if s, ok := v.(string); ok {
return &s
}
return nil
}

func expandStringSet(set *schema.Set) []string {
return expandStringList(set.List())
}
Expand Down
24 changes: 16 additions & 8 deletions linode/resource_linode_object_storage_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,14 @@ func resourceLinodeObjectStorageObjectUpdate(d *schema.ResourceData, meta interf

bucket := d.Get("bucket").(string)
key := d.Get("key").(string)
acl := d.Get("acl").(string)

if d.HasChange("acl") {
client := s3ConnFromResourceData(d)
if _, err := client.PutObjectAcl(&s3.PutObjectAclInput{
Bucket: &bucket,
Key: &key,
ACL: expandStringPointer(d.Get("acl")),
ACL: &acl,
}); err != nil {
return fmt.Errorf("failed to put Bucket (%s) Object (%s) ACL: %s", bucket, key, err)
}
Expand Down Expand Up @@ -214,18 +215,25 @@ func putLinodeObjectStorageObject(d *schema.ResourceData, meta interface{}) erro
bucket := d.Get("bucket").(string)
key := d.Get("key").(string)

nilOrValue := func(s string) *string {
if s == "" {
return nil
}
return &s
}

putInput := &s3.PutObjectInput{
Bucket: &bucket,
Key: &key,
Body: body,

ACL: expandStringPointer(d.Get("acl")),
CacheControl: expandStringPointer(d.Get("cache_control")),
ContentDisposition: expandStringPointer(d.Get("content_disposition")),
ContentEncoding: expandStringPointer(d.Get("content_encoding")),
ContentLanguage: expandStringPointer(d.Get("content_language")),
ContentType: expandStringPointer(d.Get("content_type")),
WebsiteRedirectLocation: expandStringPointer(d.Get("website_redirect")),
ACL: nilOrValue(d.Get("acl").(string)),
CacheControl: nilOrValue(d.Get("cache_control").(string)),
ContentDisposition: nilOrValue(d.Get("content_disposition").(string)),
ContentEncoding: nilOrValue(d.Get("content_encoding").(string)),
ContentLanguage: nilOrValue(d.Get("content_language").(string)),
ContentType: nilOrValue(d.Get("content_type").(string)),
WebsiteRedirectLocation: nilOrValue(d.Get("website_redirect").(string)),
}

if metadata, ok := d.GetOk("metadata"); ok {
Expand Down

0 comments on commit 0b3434e

Please sign in to comment.