Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use google api keys based on heroku application name

I've created a few different "environments" for my app that is hosted on heroku so I have: appName-staging.heroku.com appName-production.heroku.com

I want to use different google api keys for these applications, how do I do this? i've created a google.yml file that looks like:

development: api_key: 'ABCXYZ'

production: api_key: 'DEFXYZ'

so I use ABCSZY when developing locally, and DEFXYZ for appName-production.heroku.com question is, how do i get appName-staging.heroku.com to use a different key?

since every application deployed to Heroku is considered to be in "production", both appName-staging.heroku.com and appName-production.heroku.com use the same key.

like image 685
Varun Avatar asked Dec 02 '10 10:12

Varun


People also ask

How do I get my Heroku API key?

You can view your Heroku API key by going to Account settings > API Key > Reveal .


1 Answers

You could add a heroku config variable to each environment, allowing you to identify each one from within the app.

Something along the lines of:

$ heroku config:add APP_NAME_ENV=production --app appName-production
$ heroku config:add APP_NAME_ENV=staging --app appName-staging

Then you could grab the current environment from within your app using:

ENV['APP_NAME_ENV']

And if you've got your YAML file as a hash called something like GOOGLE_KEYS, the following would return the correct key for a given environment:

GOOGLE_KEYS[ENV['APP_NAME_ENV']]
like image 116
theTRON Avatar answered Oct 11 '22 15:10

theTRON