Skip to content

Commit 14e2db6

Browse files
feat: (storage) added sha512 in data object content (#13764) (#22592)
[upstream:61e2c9b2a4379bf77f7781c3f2d99e95dbf7d7be] Signed-off-by: Modular Magician <[email protected]>
1 parent d1306be commit 14e2db6

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

.changelog/13764.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
storage: added new field `content_hexsha512` and `content_base64sha512` in data source `google_storage_bucket_object_content`
3+
```

google/services/storage/data_source_storage_bucket_object_content.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
package storage
44

55
import (
6+
"crypto/sha512"
67
"encoding/base64"
8+
"encoding/hex"
79
"fmt"
810
"io/ioutil"
911
"net/http"
@@ -32,6 +34,22 @@ func DataSourceGoogleStorageBucketObjectContent() *schema.Resource {
3234
Required: false,
3335
}
3436

37+
dsSchema["content_hexsha512"] = &schema.Schema{
38+
Type: schema.TypeString,
39+
Description: "Hex encoded SHA512 checksum of object content.",
40+
Computed: true,
41+
Optional: false,
42+
Required: false,
43+
}
44+
45+
dsSchema["content_base64sha512"] = &schema.Schema{
46+
Type: schema.TypeString,
47+
Description: "Base64 encoded SHA512 checksum of object content.",
48+
Computed: true,
49+
Optional: false,
50+
Required: false,
51+
}
52+
3553
return &schema.Resource{
3654
Read: dataSourceGoogleStorageBucketObjectContentRead,
3755
Schema: dsSchema,
@@ -75,6 +93,15 @@ func dataSourceGoogleStorageBucketObjectContentRead(d *schema.ResourceData, meta
7593
return fmt.Errorf("Error setting content_base64: %s", err)
7694
}
7795

96+
sha512Sum := sha512.Sum512(objectBytes)
97+
if err := d.Set("content_hexsha512", hex.EncodeToString(sha512Sum[:])); err != nil {
98+
return fmt.Errorf("Error setting content_hexsha512: %s", err)
99+
}
100+
101+
if err := d.Set("content_base64sha512", base64.StdEncoding.EncodeToString(sha512Sum[:])); err != nil {
102+
return fmt.Errorf("Error setting content_base64sha512: %s", err)
103+
}
104+
78105
d.SetId(bucket + "-" + name)
79106
return nil
80107
}

google/services/storage/data_source_storage_bucket_object_content_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ func TestAccDataSourceStorageBucketObjectContent_FileContentBase64(t *testing.T)
7070
Config: testAccDataSourceStorageBucketObjectContent_FileContentBase64(bucket, folderName),
7171
Check: resource.ComposeTestCheckFunc(
7272
resource.TestCheckResourceAttrSet("data.google_storage_bucket_object_content.this", "content_base64"),
73+
resource.TestCheckResourceAttrSet("data.google_storage_bucket_object_content.this", "content_hexsha512"),
74+
resource.TestCheckResourceAttrSet("data.google_storage_bucket_object_content.this", "content_base64sha512"),
7375
verifyValidZip(),
7476
),
7577
},

website/docs/d/storage_bucket_object_content.html.markdown

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,8 @@ The following attributes are exported:
4545

4646
* `content_base64` - (Computed) Base64 encoded version of the object content.
4747
Use this when dealing with binary data.
48+
49+
* `content_hexsha512` - (Computed) Hex encoded SHA512 checksum of file content.
50+
51+
* `content_base64sha512` - (Computed) Base64 encoded SHA512 checksum of file content.
52+

0 commit comments

Comments
 (0)