Google Vision API Authentication on Hero

What's the best, simplest way to authenticate Vision API to heroku?

In development I just use:

@vision = Google::Cloud::Vision.new( project:  "instacult",
                                     keyfile:  "path/to/keyfile.json" )

      

Where keyfile is the json generated by google after creating the service account ( https://cloud.google.com/vision/docs/common/auth ).

But obviously I can't just upload the key file to github.

I tried saving all the json in Heroku config files and running:

Rails.env.production? ? ENV["GOOGLE_CREDENTIALS"] : path

      

But I got an "invalid file" in heroku logs. Seems logical as I am not passing a file but an object. But how to overcome it?

Cheers, Kai

+3


source to share


1 answer


DECIDE:

It turns out you can provide a json object in an environment variable, but there is a naming convention.

Here are the environment variables (in the order they were tested) for Credentials:

  • VISION_KEYFILE - path to the JSON file
  • GOOGLE_CLOUD_KEYFILE - path to the JSON file
  • VISION_KEYFILE_JSON - JSON content
  • GOOGLE_CLOUD_KEYFILE_JSON - JSON content

source: https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-vision/v0.23.0/guides/authentication

So, I ended up calling:



@vision = Google::Cloud::Vision.new( project:  "instacult")

      

By setting VISION_KEYFILE_JSON in my ~ / .bashrc:

export VISION_KEYFILE_JSON='the_json_content'

      

and on heroku ( https://devcenter.heroku.com/articles/config-vars#limits ).

+5


source







All Articles