0

I am new to hosting world (cloudcontrol), an i got some problem with application credentials, like database administration (mongohq), or google authentification.

So, will i put those variable with some kind of syntaxte (something like $variable) in the code, and then make a commandline with key-value as variable-value ?

Abdelouahab
  • 7,331
  • 11
  • 52
  • 82

1 Answers1

1

If you are using Tornado, it makes it even simpler. Use tornado.options and pass environment variables while running the code.

Use following in your Tornado code:

define("mysql_host", default="127.0.0.1:3306", help="Main user DB")
define("google_oauth_key", help="Client key for Google Oauth")

Then you can access the these values in your rest of your code as:

options.mysql_host
options.google_oauth_key

When you are running your Tornado script, pass the environment variables:

python main.py --mysql_host=$MYSQL_HOST --google_oauth_key=$OAUTH_KEY

assuming both $MYSQL_HOST and $OAUTH_KEY are environment variables. Let me know if you need a full working example or any further help.

example:

First set a environment variable:

$export mongo_uri_env=mongodb://alien:12345@kahana.mongohq.com:10067/essog

and make changes in your Tornado code:

define("mongo_uri", default="127.0.0.1:28017", help="MongoDB URI")
...
...
uri = options.mongo_uri

and you would run your code as

python main.py --mongo_uri=$mongo_uri_env 

If you don't want to pass it while running, then you have to read that environment variable directly in your script. For that

import os
...
...
uri = os.environ['mongo_uri_env']
avi
  • 9,292
  • 11
  • 47
  • 84
  • i dont get it, so cloudcontrol will use those variables when i put it as a command line in the procfile? – Abdelouahab Jul 12 '14 at 18:12
  • you want provide some variables to cloud control or use some already set environment variables in your code? – avi Jul 13 '14 at 04:28
  • i will use gmail and mongohq, so i guess there will be new custom envirnment variables? so where to set them, on the code itself? – Abdelouahab Jul 13 '14 at 04:32
  • I don't understand, can you please elaborate? for example you want your code to connect to mongohq and keep credentials in the environment variables? – avi Jul 13 '14 at 05:07
  • here is the code, https://github.com/abdelouahabb/essog/blob/master/handlers.py#L26 the login information are typed on the code itself, and i want to remove them and let only as variable and only put them when i will launch the application, so noone can see them – Abdelouahab Jul 13 '14 at 14:49
  • i dont get the code `define("mongo_uri", default="127.0.0.1:28017", help="MongoDB URI")` this is initalizing it, and then after i export the environement variable it will change so i can use the uri specified as mongodb database uri? – Abdelouahab Jul 14 '14 at 00:04
  • 1
    above line specifies Tornado that either `mongo_uri` will passed as argument while running or if not, use default `127.0.0.1:28017` It has nothing to do with environment variables. Read [this](http://tornado.readthedocs.org/en/latest/options.html) – avi Jul 14 '14 at 03:05
  • i am sorry, but the example, about making environment variable as argument are for local command line? not for cloudcontrol command line? – Abdelouahab Jul 14 '14 at 16:00
  • ^tried reading documentation? [this](https://www.cloudcontrol.com/dev-center/Platform%20Documentation) one explains how to do that – avi Jul 15 '14 at 03:00
  • yes, that was my question, where to put those values! https://www.cloudcontrol.com/dev-center/Platform%20Documentation#add-on-credentials – Abdelouahab Jul 15 '14 at 03:22
  • yes, but it is explained as it is on a local console, not on cloudcontrol system – Abdelouahab Jul 15 '14 at 17:37