Configure Heroku Config Var with content from the Google Cloud Service account key file

I have a web application that I am trying to deploy with Heroku. I use the Google Cloud Node.js library to access Google cloud storage. At the top of my server file is the following:

const gcs = require('@google-cloud/storage')({
  projectId: 'my-project-ID',
  credentials: process.env.GCS_KEYFILE
});

GCS_KEYFILE is a configuration variable that I set using Heroku command line tools using heroku config:set GCS_KEYFILE="$(< /my/file.json)"

Checking the control panel to ensure that the work is completed confirms that the contents of the JSON file are set to config var. The screenshot is as follows: enter image description here

The error that occurs when trying to do something with gcs:

Error: Could not authenticate request 
The incoming JSON object does not contain a client_email field

, . json ; Google Cloud, . keyFileName const gcs, ENAMETOOLONG ( docs say thats JSON ). , keyFileName JSON, , JSON .

, ? JSON Keyfiles Google Heroku?

+4
1

- .

google api JSON, - , JSON:

const gcs = require('@google-cloud/storage')({
  projectId: 'my-project-ID',
  credentials: JSON.parse(process.env.GCS_KEYFILE)
});
+4

Source: https://habr.com/ru/post/1679501/


All Articles