gpt4 book ai didi

google-app-engine - 如何在谷歌应用引擎中存储服务器的私钥?

转载 作者:IT王子 更新时间:2023-10-29 01:39:21 27 4
gpt4 key购买 nike

我正在使用 "github.com/dgrijalva/jwt-go" 创建 JSON 网络 token 。
当我在本地托管我的服务器时,我可以像往常一样使用我的私钥。但在 GAE 中它不起作用,因为我无权访问文件系统。

你们会怎么做呢?将 key 存储在数据存储区或任何其他想法中?

谢谢

编辑:

我的 app.yaml 看起来像这样(在 api_version 和其他东西下面):

handlers:
- url: /.*
script: _go_app

最佳答案

在 AppEngine 上,您无权访问主机操作系统的文件系统,但您可以访问 Web 应用程序的文件(您拥有只读权限,无法更改它们,也无法创建应用程序文件夹中的新文件)。

所以问题是:您是否希望在不重新部署您的应用程序的情况下从您的应用程序更改此私钥?或者,如果它与您的应用程序代码一起“静态”部署就完全没问题?

如果您不需要更改它(或仅在重新部署您的应用程序时),最简单的方法是将其存储为“静态”文件作为您的网络应用程序的一部分。您可以使用相对路径引用应用程序的文件,其中当前或工作目录是应用程序的根目录。例如。如果您的应用在其根目录(app.yaml 所在的位置)包含一个 key 文件夹,并且 my_key.txt 文件位于 key文件夹,可以引用路径:key/my_key.txt

实际上,将静态文件与您的应用程序代码一起“传送”是很常见的:想想由 Go 代码读取和处理的 HTML 模板(例如 package html/template )以生成 HTML 结果; HTML 模板文件的内容不直接提供给客户。

如果您需要不时更改它而无需重新部署您的应用,则将其存储在您的应用可以读取和修改的数据存储中。

注意:

重要说明:并非每个文件都可以通过代码读取,这取决于应用程序配置。引自 Configuring with app.yaml / Static file handlers :

Static files are files to be served directly to the user for a given URL, such as images, CSS stylesheets, or JavaScript source files. Static file handlers describe which files in the application directory are static files, and which URLs serve them.

For efficiency, App Engine stores and serves static files separately from application files. Static files are not available in the application's file system. If you have data files that need to be read by the application code, the data files must be application files, and must not be matched by a static file pattern.

Static file handlers can be defined in two ways: as a directory structure of static files that maps to a URL path, or as a pattern that maps URLs to specific files.

阅读如何正确配置应用程序和静态文件/目录的链接。

关于google-app-engine - 如何在谷歌应用引擎中存储服务器的私钥?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34629056/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com