gpt4 book ai didi

google-cloud-platform - 无法在GCP密码管理器中访问密码

转载 作者:行者123 更新时间:2023-12-03 15:29:41 25 4
gpt4 key购买 nike

我正在尝试将代码从使用.env文件中存储的API key 迁移到使用Google Cloud Platform Secrets Manager。我已按照here的指示进行操作,但遇到错误消息,说我无权访问该 secret 。

import * as admin from "firebase-admin"
import { SecretManagerServiceClient } from "@google-cloud/secret-manager"

admin.initializeApp()
const secretClient = new SecretManagerServiceClient()

async function main() {
async function getSecret(): Promise<string | null | undefined> {
const [version] = await secretClient.accessSecretVersion({ name: "TELEGRAM_TOKEN" })

return version.payload?.data?.toString()
}

const TELEGRAM_TOKEN = await getSecret()
console.log(TELEGRAM_TOKEN)
}

main().catch(console.error)
那就是我得到的错误:
> node lib/app.js --telegram

{ Error: 7 PERMISSION_DENIED: Permission denied on resource project TELEGRAM_TOKEN.
at Object.callErrorFromStatus (/Users/bartekpacia/dev/node/telegram-lang-enforcer/node_modules/@grpc/grpc-js/build/src/call.js:30:26)
at Object.onReceiveStatus (/Users/bartekpacia/dev/node/telegram-lang-enforcer/node_modules/@grpc/grpc-js/build/src/client.js:174:52)
at Object.onReceiveStatus (/Users/bartekpacia/dev/node/telegram-lang-enforcer/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:340:141)
at Object.onReceiveStatus (/Users/bartekpacia/dev/node/telegram-lang-enforcer/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:303:181)
at Http2CallStream.outputStatus (/Users/bartekpacia/dev/node/telegram-lang-enforcer/node_modules/@grpc/grpc-js/build/src/call-stream.js:114:27)
at Http2CallStream.maybeOutputStatus (/Users/bartekpacia/dev/node/telegram-lang-enforcer/node_modules/@grpc/grpc-js/build/src/call-stream.js:153:22)
at Http2CallStream.endCall (/Users/bartekpacia/dev/node/telegram-lang-enforcer/node_modules/@grpc/grpc-js/build/src/call-stream.js:140:18)
at Http2CallStream.handleTrailers (/Users/bartekpacia/dev/node/telegram-lang-enforcer/node_modules/@grpc/grpc-js/build/src/call-stream.js:262:14)
at ClientHttp2Stream.emit (events.js:198:13)
at emit (internal/http2/core.js:265:8)
code: 7,
details: 'Permission denied on resource project TELEGRAM_TOKEN.',
metadata:
Metadata {
internalRepr:
Map {
'google.rpc.help-bin' => [Array],
'grpc-status-details-bin' => [Array],
'grpc-server-stats-bin' => [Array] },
options: {} },
note:
'Exception occurred in retry method that was not classified as transient' }
我确实创建了一个具有“所有者”权限的服务帐户,将其下载并制作为 export GOOGLE_APPLICATION_CREDENTIALS=/Users/...。执行 echo $GOOGLE_APPLICATION_CREDENTIALS时,正确显示了我的服务帐户.json文件位置。
我真的不知道我在做什么错。

最佳答案

访问 secret 时,需要指定项目:

await secretClient.accessSecretVersion({ name: "TELEGRAM_TOKEN" })

应该
await secretClient.accessSecretVersion({ name: "projects/my-project/secrets/TELEGRAM_TOKEN" })

关于google-cloud-platform - 无法在GCP密码管理器中访问密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61282732/

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