所以对于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 https://google-auth.readthedocs.io/en/latest/reference/google.oauth2.service_account.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)