如何使用凭据文件而不将其推到存储库
我正在构建一个在GCP(Google Cloud Platform)上部署的Django Web应用程序。我需要使用Google Cloud存储存储桶来存储从应用程序生成的文件,因此我将代码添加到settings.py
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = os.path.join(BASE_DIR, 'credential.json')
中。目前,我将凭据文件放在计算机上的项目目录中,并且效果很好。但是现在,我需要将项目推向项目交接的公共存储库,我无法推动凭据文件,因为它包含了云存储存储桶的私钥。我该怎么做才能使程序正常运行,而无需将凭据文件推向存储库或其他人可以访问的文件?
I am building a Django web app that is deployed on GCP (google cloud platform). I need to use the google cloud storage bucket to store files generated from the app, So I added the code to settings.py
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = os.path.join(BASE_DIR, 'credential.json')
In the code, credential.json is referred to. Currently, I put the credential file in the project directory on my computer and it works fine. But now I need to push the project to a public repository for project handoff and I can’t push the credential file because it contains the private key to the cloud storage bucket. What should I do to make the program run normally without pushing the credential file to the repository or the file being accessible by other people?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要推动凭据文件,并告诉用户在项目文档中创建它。
一个常见的模式是提供一个示例文件,上面有虚拟数据,以帮助用来了解文件的结构。
您将拥有这样的文档:
Don't push the credential files and tell the user to create it in the project documentation.
A common pattern is to provide an example file with dummy data to help uses to understand the structure of the file.
You will have a documentation like this: