我正在编写一个用 postgres dialect 与 cloud spanner 对话的程序。我的应用程序是一个 gin 服务器,我正在使用 pgadapter 进行连接,如本文档中所述。
我的应用程序在本地运行良好。但是当我将其部署到云运行时,我收到以下日志。
该错误主要来自 startpgadapterwithcredentials 函数。
func StartPGAdapter(ctx context.Context, project, instance string) (port int, cleanup func(), err error) { credentials, err := google.FindDefaultCredentials(ctx) fmt.Println("credentials " + (credentials.ProjectID) + "json " + utils.ToString(credentials.JSON) + "ts " + utils.ToString(credentials.TokenSource)) if err != nil { return 0, func() {}, err } return StartPGAdapterWithCredentials(ctx, project, instance, credentials) } func StartPGAdapterWithCredentials(ctx context.Context, project, instance string, credentials *google.Credentials) (port int, cleanup func(), err error) { if credentials == nil { return 0, func() {}, fmt.Errorf("credentials cannot be nil") } if credentials.JSON == nil || len(credentials.JSON) == 0 { return 0, func() {}, fmt.Errorf("only JSON based credentials are supported") } credentialsFile, err := os.CreateTemp(os.TempDir(), "pgadapter-credentials") if err != nil { return 0, func() {}, err }
在我的本地系统上,设置了 google_application_credentials ,因此它能够获取凭据。但是,这在云运行中不起作用。
如何让它在云运行中运行?
其他信息:遵循此处提供的示例。
您似乎正在尝试在 Cloud Run 上的嵌入式容器中启动 PGAdapter,然后将服务帐户凭据从您的环境复制到 PGAdapter 嵌入式容器。问题在于 Cloud Run 不提供对底层服务帐户文件的访问。相反,您应该让 Google Cloud 库获取环境的默认凭据。
您的示例中的困难部分是您在嵌入式容器中启动 PGAdapter,这意味着该环境中没有默认凭据。在 Cloud Run 上运行 PGAdapter 的推荐方法是将其包含在主容器中。这将使 PGAdapter 能够仅获取 Cloud Run 提供的默认凭据。这意味着您不应该在启动 PGAdapter 时指定 -c /path/to/credentials.json 参数。
(至少)有两种方法可以将 PGAdapter 包含在主容器中:
请参阅 Go 的 PGAdapter Cloud Run 示例获取后一个选项的广泛(可运行)示例。
以上就是在 Cloud Run 中找不到默认凭据的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号