【发布时间】:2020-03-20 07:48:51
【问题描述】:
我正在使用 Google Cloud Function 使用 Cloud Scheduler 以设定的时间间隔对我的 Firestore 集合执行一些操作(都在同一个项目中)。
它的功能本身可以正常工作并进行身份验证。但是,我在我的 python 代码中使用服务帐户 JSON 进行身份验证,如下所示:
cred = credentials.Certificate({
"type": "service_account",
"project_id": "...",
"private_key_id": "...",
"private_key": "...",
"client_email": "...",
"client_id": "...",
"auth_uri": "...",
"token_uri": "...,
"auth_provider_x509_cert_url": "...",
"client_x509_cert_url": "..."
})
firebase_admin.initialize_app(cred)
db = firestore.client()
我知道有更好的身份验证方法,因为数据库和函数位于同一个 Google Cloud 项目中。但是,我找不到任何有关如何通过内联编辑器执行此操作的文档。
如何在不使用服务帐户的情况下验证并引用我的 Firestore 数据库?
【问题讨论】:
-
您是否检查过来自 Google 的 Python 示例以获得 GCP? link 您可以在此处找到 Cloud Functions 和 Firestore 的代码 sn-ps。
标签: python-3.x firebase google-cloud-platform google-cloud-firestore google-cloud-functions