我使用 Google Secret Manager 的 Node.js 代码停止工作(前段时间运行良好)。我已将GOOGLE_APPLICATION_CREDENTIALS
env 变量设置为有效路径和console.log(process.env.GOOGLE_APPLICATION_CREDENTIALS)
;正确打印。我什至尝试重新生成新的 .json 文件,但仍然出现相同的错误。最初它没有 keyFilename,但两者都给出相同的结果,错误。密钥在管理网站中启用。我也试过打电话await client.initialize();
。
有没有办法对此进行更多调试?最近从冬季到夏季的时间变化会产生影响吗?但是为什么重新生成的密钥不起作用呢?
const { SecretManagerServiceClient } = require('@google-cloud/secret-manager');
const client = new SecretManagerServiceClient({
keyFilename: 'path-to.json'
});
const projectId = 'project-number';
const parent = 'projects/' + projectId;
...
async function listSecrets() { // Calling this throws the error
const [secrets] = await client.listSecrets({
parent: parent
});
完整的错误堆栈:
[2021-04-12T09:14:56.366Z] (node:51988) UnhandledPromiseRejectionWarning: Error: 16 UNAUTHENTICATED: Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.
at Object.callErrorFromStatus (<super-secret-path>\node_modules\@grpc\grpc-js\build\src\call.js:31:26)
at Object.onReceiveStatus (<super-secret-path>\node_modules\@grpc\grpc-js\build\src\client.js:176:52)
at Object.onReceiveStatus (<super-secret-path>\node_modules\@grpc\grpc-js\build\src\client-interceptors.js:336:141)
at Object.onReceiveStatus (<super-secret-path>\node_modules\@grpc\grpc-js\build\src\client-interceptors.js:299:181)
at <super-secret-path>\node_modules\@grpc\grpc-js\build\src\call-stream.js:130:78
at processTicksAndRejections (internal/process/task_queues.js:75:11)