我好像搞不懂。我所要做的就是访问在本地运行我的应用程序时为我创建的一个测试秘密。我得到了一个service-account.json,如下所示,我被告知要用于本地访问,但我找不到任何文档或任何其他资源来显示如何处理该文件。
{
"type": "service_account",
"project_id": "test-dev-project",
"private_key_id": "12cea3c45d67d0d89f0ccfca1bede23d4d56c7b8",
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBg1234\n-----END PRIVATE KEY-----\n",
"client_email": "my-secrets-email@test-dev-project.iam.gserviceaccount.com",
"client_id": "123456789012345678901",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/my-secrets-email%40test-dev-project.iam.gserviceaccount.com"
}我可以从医生们中收集到的一点是,我应该通过Powershell“设置”它的路径,但是即使我“设置”了它的路径,然后再次运行node index.js,我仍然得到了完全相同的错误:
Error: 7 PERMISSION_DENIED: Secret Manager API has not been used in project 123456789012 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/secretmanager.googleapis.com/overview?project=123456789012 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.我使用这类服务帐户文件的唯一其他经验是使用Firebase函数,在那里您可以将文件路径设置为应用程序初始化函数的参数,所以我想我必须在这里做一些类似的事情,但是我找不到任何这样的指示。
以下是我的Node项目的整体情况:
// ./index.js
(async() => {
const { SecretManagerServiceClient } = require('@google-cloud/secret-manager');
const client = new SecretManagerServiceClient();
const SOME_APIKEY = await client.accessSecretVersion({ name: 'latest' });
console.log('key:', SOME_APIKEY);
})();
// ./package.json
{
"name": "google-secret-attempt-17",
"main": "index.js",
"scripts": {},
"dependencies": {
"@google-cloud/secret-manager": "^3.10.1"
}
}
// ./service-account.json (already posted its content above)我一直在尝试的步骤是:
$env:GOOGLE_APPLICATION_CREDENTIALS="./service-account.json"node index.js我还尝试在我的process.env.GOOGLE_APPLICATION_CREDENTIALS = './service-account.json'开始时显式地设置index.js,然后运行步骤2,但是结果完全相同,所以我不知道该怎么做了。
任何对我哪里出错或其他任何事情的洞察力都将受到高度赞赏。
发布于 2021-12-02 14:46:46
看起来在相关的项目中没有启用Secrets Manager api。请让提供service-account.json文件的人访问https://console.developers.google.com/apis/api/secretmanager.googleapis.com/overview?project=123456789012并启用API。一旦完成,您应该能够访问api。
https://stackoverflow.com/questions/70196183
复制相似问题