【发布时间】:2019-09-01 13:36:12
【问题描述】:
如何使用implicit GOOGLE_APPLICATION_CREDENTIALS environment variable provided to a Cloud Function 签署 Cloud Storage URL?
当存在GOOGLE_APPLICATION_CREDENTIALS 环境变量时,以下内容在本地工作,但在云函数内部运行时会因KeyError 而失败。
google_credentials = service_account.Credentials.from_service_account_file(
os.environ['GOOGLE_APPLICATION_CREDENTIALS']
)
client_email = google_credentials.service_account_email
credential_scope = '{}/auto/storage/goog4_request'.format(datestamp)
credential = '{}/{}'.format(client_email, credential_scope)
# ...
signature = binascii.hexlify(
google_credentials.signer.sign(string_to_sign)
).decode()
有问题的云功能将部署在多个环境中,所以我想避免实际部署凭据文件——确实工作。
如果相关,我使用 Python 3.7 并基于 this 示例解决我的问题。
【问题讨论】:
标签: python-3.x google-cloud-storage google-cloud-functions