因此,对于Ruby,您可以将JSON内容设置为GOOGLE_CLOUD_KEYFILE_JSON的环境变量。我正在尝试查找Python文档,但是我所看到的只是文档加载了文件路径的身份验证。

最佳答案

我找到了一种方法,但是我想知道是否有更好的方法。使用google-auth库,我可以执行以下操作:

import json

from google.cloud import bigquery
from google.oauth2 import service_account

"""
Securely get content of JSON file from protected memory because having
the credential file plainly on the filesystem is unsafe
"""

service_account_info = json.loads(json_file_content_string)
credentials = service_account.Credentials.from_service_account_info(service_account_info)
client = bigquery.Client(project='secret-proj', credentials=credentials)


有关库的更多信息,请参见:https://google-auth.readthedocs.io/en/latest/reference/google.oauth2.service_account.html

08-04 14:44