简体   繁体   English

在 Blitz.js api 处理程序中运行时,Google Cloud Storage 调用失败并显示“error:0909006C:PEM routines:get_name:no start line”

[英]Google Cloud Storage call fails with "error:0909006C:PEM routines:get_name:no start line" when run in Blitz.js api handler

When I try to use @google-cloud/storage inside of a Blitz.js /api handler , it generates this error:当我尝试在Blitz.js /api 处理程序中使用@google-cloud/storage时,它会生成此错误:

error:0909006C:PEM routines:get_name:no start line
    at Sign.sign (internal/crypto/sig.js:110:29)
    at NodeCrypto.sign (C:\Users\markj\workspace\myapp\node_modules\google-auth-library\build\src\crypto\node\crypto.js:35:23)
    at GoogleAuth.sign (C:\Users\markj\workspace\myapp\node_modules\google-auth-library\build\src\auth\googleauth.js:561:39)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async sign (C:\Users\markj\workspace\myapp\node_modules\@google-cloud\storage\build\src\signer.js:174:35) {
  name: 'SigningError'

However when I run it locally with node test_api.js , it works fine...但是,当我使用node test_api.js在本地运行它时,它工作正常......

Here is my code:这是我的代码:

// test_api.js

const {Storage} = require('@google-cloud/storage');

const client_id = process.env.GCP_STORAGE_ADMIN_CLIENT_ID
const projectId = process.env.GCP_PROJECT_ID
const client_email = process.env.GCP_STORAGE_ADMIN_CLIENT_EMAIL
const private_key = process.env.GCP_STORAGE_ADMIN_PRIVATE_KEY

const storage = new Storage({
    projectId,
    credentials: {
        client_id,
        client_email,
        private_key,
    }
});

async function listBuckets() {
    console.log('PRIVATE KEY: ', private_key) // the error seems to indicate there is an issue here
    // Output: "-----BEGIN PRIVATE KEY-----\n[the private key]\n-----END PRIVATE KEY-----\n"
    const [buckets] = await storage.getBuckets();
    console.log('Buckets:');
    buckets.forEach(bucket => {
      console.log(bucket.name);
    });
}

module.exports = {
    listBuckets // this function errors when called within Next.js /api handler
}

// When I uncomment this and run the file directly with node, it works
// listBuckets()

The error seems to indicate there is something wrong with the start/prefix of my private key, but I copied it exactly from the Google Service Account JSON file.该错误似乎表明我的私钥的开始/前缀有问题,但我从 Google 服务帐户 JSON 文件中准确复制了它。 It looks like this:它看起来像这样:

-----BEGIN PRIVATE KEY-----\n[the private key]\n-----END PRIVATE KEY-----\n

It turned out to be a misplaced trailing comma in my .env.local environment variables.原来是我的.env.local环境变量中错位的尾随逗号。

GCP_STORAGE_ADMIN_PRIVATE_KEY="[the private key]",

The trailing comma was not obvious because I had word wrap turned off, and the console.logs weren't displaying the comma, but it was somehow reading the comma and causing the entire private key to be parsed incorrectly.尾随的逗号不明显,因为我关闭了自动换行,并且 console.logs 没有显示逗号,但它以某种方式读取了逗号并导致整个私钥被错误地解析。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 error:0909006C:PEM routines:get_name:no start line - 适用于 heroku 中的谷歌云平台 - error:0909006C:PEM routines:get_name:no start line - for google cloud platform in heroku Firebase FCM sendAll() 私钥错误:error:0909006C:PEMroutines:get_name:no start line - Firebase FCM sendAll() private key error: error:0909006C:PEM routines:get_name:no start line 尝试发布数据时出现 Heroku 错误(错误:0909006C Pem 例程..._ - Error on Heroku when trying to post data ( error:0909006C Pem routines..._ Nest.js API + Cloud 上的 Google Cloud Storage 运行每个 GET 请求以触发“HTTP/2 框架层中的流错误”(POST 请求工作正常) - Nest.js API + Google Cloud Storage on Cloud Run every GET request to trigger "Stream error in the HTTP/2 framing layer" (POST requests work fine) 谷歌云 DLP API:如何在检查谷歌云存储文件时获得完整的 dlp 作业检查结果 - Google cloud DLP API: How to get full dlp job inspection results when inspecting google cloud storage files 如何从谷歌云存储桶中获取项目名称/ID? - How to get project name/id from Google Cloud Storage bucket? Google Cloud Platform 在使用第三方库时出现 PEM 错误 - Google Cloud Platform gives PEM Error when using third party libraries 从 Google Cloud Storage 加载 csv 文件时出现 BigQuery 错误 - BigQuery error when loading csv file from Google Cloud Storage APP Engine Google Cloud Storage - 下载文件时出现错误 500 - APP Engine Google Cloud Storage - Error 500 when downloading a file Google Cloud Storage:下载具有不同名称的文件 - Google Cloud Storage: download a file with a different name
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM