【问题标题】:Google Cloud Functions: How to Use Security Certificates in BucketGoogle Cloud Functions:如何在存储桶中使用安全证书
【发布时间】:2020-10-04 08:11:07
【问题描述】:

我有一个调用 API 的 Google Cloud 函数。此调用需要我已上传到存储桶的 .pem 和 .key 安全证书。我正在尝试在云功能中使用它们。这似乎是一项简单的任务,但我尝试过或在线找到的代码都没有。这是我目前拥有的:

def receive_request(request):
    request_json = request.get_json()
    if request_json:
        source_bucket = storage.get_bucket('bucket_name')
        pem_file = source_bucket.get_blob(request_json.get('pem'))
        key_file = source_bucket.get_blob(request_json.get('key'))
        url = 'https://api_url/api/v2/acls'
        response = requests.get(url, cert=(pem_file,key_file ))

JSON 就在哪里:

{"pem":"file_name.pem","key":"file_name.key"}

我得到的错误信息是:

Error: function terminated. Recommended action: inspect logs for termination reason. Details:
stat: path should be string, bytes, os.PathLike or integer, not Blob

当我尝试使用 GS 路径(“gs://bucket_name/file_name.key”)时,GCP 没有部署该功能。如何正确构建这两个文件的导入?

【问题讨论】:

标签: google-cloud-platform google-cloud-functions google-cloud-storage


【解决方案1】:

您是否考虑过使用 Secret Manager 来存储您的证书?这可能比将它们存储在云存储上更有意义。

更多信息请参见https://cloud.google.com/secret-manager/docs

【讨论】:

  • 我已经尝试过了,但我没有设法将文件拉入函数中。我正在努力寻找在函数中使用秘密文件的示例 - 您有任何示例或其他资源建议吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多