Reputation: 21
We are using Google classifier(AI and machine learning product of google) in our application for one of the use case.Google needs json file which contains credentials to access classifier related things.We are trying to set this json file in environment variables on heroku.
We want to set JSON file(.json) in environment variables on Heroku. How we can achieve above scenario?
Upvotes: 2
Views: 1351
Reputation: 4453
import json
with open('service_account.json', 'r') as f:
info = json.load(f)
service_account_info = json.dumps(info)
with open('.env', 'a') as f:
f.write(f'GOOGLE_SERVICE_ACCOUNT={service_account_info}')
from invoke import run
from honcho.environ import parse
with open('.env', 'r') as f:
env = parse(f.read())
cmd = 'heroku config:set ' + ' '.join(
f'{key}=\'{value}\''
for key, value in env.items()
)
run(cmd)
import json
service_account_info = json.loads(getenv('GOOGLE_SERVICE_ACCOUNT'))
# do something with service_account_info!
Upvotes: 1