|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import base64 |
|
import hashlib |
|
import time |
|
|
|
|
|
BUCKET_NAME = "grpm-systest-{}".format(int(1000 * time.time())) |
|
BUCKET_POST_URL = "https://www.googleapis.com/storage/v1/b/" |
|
BUCKET_URL = "https://www.googleapis.com/storage/v1/b/{}".format(BUCKET_NAME) |
|
|
|
_DOWNLOAD_BASE = "https://www.googleapis.com/download/storage/v1/b/{}".format( |
|
BUCKET_NAME |
|
) |
|
DOWNLOAD_URL_TEMPLATE = _DOWNLOAD_BASE + "/o/{blob_name}?alt=media" |
|
|
|
_UPLOAD_BASE = ( |
|
"https://www.googleapis.com/upload/storage/v1/b/{}".format(BUCKET_NAME) |
|
+ "/o?uploadType=" |
|
) |
|
SIMPLE_UPLOAD_TEMPLATE = _UPLOAD_BASE + "media&name={blob_name}" |
|
MULTIPART_UPLOAD = _UPLOAD_BASE + "multipart" |
|
RESUMABLE_UPLOAD = _UPLOAD_BASE + "resumable" |
|
|
|
METADATA_URL_TEMPLATE = BUCKET_URL + "/o/{blob_name}" |
|
|
|
GCS_RW_SCOPE = "https://www.googleapis.com/auth/devstorage.read_write" |
|
|
|
ENCRYPTION_KEY = ( |
|
b"R\xb8\x1b\x94T\xea_\xa8\x93\xae\xd1\xf6\xfca\x15\x0ekA" |
|
b"\x08 Y\x13\xe2\n\x02i\xadc\xe2\xd99x" |
|
) |
|
|
|
|
|
def get_encryption_headers(key=ENCRYPTION_KEY): |
|
"""Builds customer-supplied encryption key headers |
|
|
|
See `Managing Data Encryption`_ for more details. |
|
|
|
Args: |
|
key (bytes): 32 byte key to build request key and hash. |
|
|
|
Returns: |
|
Dict[str, str]: The algorithm, key and key-SHA256 headers. |
|
|
|
.. _Managing Data Encryption: |
|
https://cloud.google.com/storage/docs/encryption |
|
""" |
|
key_hash = hashlib.sha256(key).digest() |
|
key_hash_b64 = base64.b64encode(key_hash) |
|
key_b64 = base64.b64encode(key) |
|
|
|
return { |
|
"x-goog-encryption-algorithm": "AES256", |
|
"x-goog-encryption-key": key_b64.decode("utf-8"), |
|
"x-goog-encryption-key-sha256": key_hash_b64.decode("utf-8"), |
|
} |
|
|