Skip to content

Commit

Permalink
make local configuration of settings possible with vagrant
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshData committed Jul 31, 2017
1 parent f18ab4c commit ce09e6d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 50 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
.venv*
env/
local/
settings.env
pip-log.txt
static/css/all-min.css
static/images/dynamic
Expand Down
25 changes: 2 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ At the end:

### Configuration

TODO. This is not working yet.

Some features of the site require additional configuration. To set configuration variables, create a file named `.env` and optionally set any of the following variables (defaults are shown where applicable):
Some features of the site require additional configuration. To set configuration variables, create a file named `settings.env` and optionally set any of the following variables (defaults are shown where applicable):

# Database server.
# See https://github.com/kennethreitz/dj-database-url
Expand Down Expand Up @@ -85,26 +83,7 @@ Some features of the site require additional configuration. To set configuration
# and kept secure. You can generate a key with `./manage.py generate_secret_key`
SECRET_KEY=(randomly generated on each run if not specified)

# Some accounts...
GOOGLE_ANALYTICS_KEY=

# For captchas...
RECAPTCHA_PUBLIC_KEY=
RECAPTCHA_PRIVATE_KEY=

# For social login...
TWITTER_OAUTH_TOKEN=
TWITTER_OAUTH_TOKEN_SECRET=
TWITTER_ACCESS_TOKEN=
TWITTER_ACCESS_TOKEN_SECRET=
FACEBOOK_APP_ID=
FACEBOOK_APP_SECRET=
FACEBOOK_AUTH_SCOPE=
GOOGLE_APP_ID=
GOOGLE_APP_ID=
GOOGLE_AUTH_SCOPE=

See `.env.server.template` for details
See `settings.env.template` for details, especially for values used in production.

# Credits

Expand Down
5 changes: 5 additions & 0 deletions build/vagrant_manage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#!/bin/bash
cd /vagrant
export DEBUG=1
if [ -f settings.env ]; then
echo "using settings.env"
set -o allexport
source settings.env;
fi
./manage.py "$@"
23 changes: 7 additions & 16 deletions .env.server.template → settings.env.template
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,16 @@ AWS_SECRET_ACCESS_KEY=...
# Comma-separated list of strings representing the host/domain names that this
# site can serve.
# See https://docs.djangoproject.com/en/1.10/ref/settings/#allowed-hosts

ALLOWED_HOSTS=*


# URL-formatted string representing the database connection configuration.
# See https://github.com/kennethreitz/dj-database-url#url-schema

#DATABASE_URL=...

DATABASE_URL=...

# URL representing the cache connection configuration
# See https://github.com/ghickman/django-cache-url#supported-caches

CACHE_URL=locmem://opendataiscool


# URL representing the haystack connection configurations.
# See https://github.com/simpleenergy/dj-haystack-url#url-schema
#
Expand All @@ -57,29 +51,26 @@ CACHE_URL=locmem://opendataiscool
#
# For a production deployment you may want to use Solr instead, e.g.:
# solr:http://localhost:8983/solr/person

HAYSTACK_PERSON_CONNECTION=simple
HAYSTACK_BILL_CONNECTION=simple
HAYSTACK_STATE_CONNECTION=simple


# Django uses a secret key to provide cryptographic signing. It should be random
# and kept secure. You can generate a key with `./manage.py generate_secret_key`

SECRET_KEY=

CONGRESS_LEGISLATORS_PATH=../congress-legislators/
RSS_CAMPAIGN_QUERYSTRING=?utm_campaign=govtrack_feed&utm_source=govtrack/feed&utm_medium=rss
RSS_CAMPAIGN_QUERYSTRING="?utm_campaign=govtrack_feed&utm_source=govtrack/feed&utm_medium=rss"

# External account keys.
GOOGLE_ANALYTICS_KEY=fill this in

RECAPTCHA_PUBLIC_KEY=fill this in
RECAPTCHA_PRIVATE_KEY=fill this in

TWITTER_OAUTH_TOKEN=fill this in
TWITTER_OAUTH_TOKEN_SECRET=fill this in

FACEBOOK_APP_ID=fill this in
FACEBOOK_APP_SECRET=fill this in
FACEBOOK_AUTH_SCOPE=

FACEBOOK_AUTH_SCOPE=email
GOOGLE_APP_ID=fill this in
GOOGLE_APP_SECRET=fill this in
GOOGLE_AUTH_SCOPE="openid email"
32 changes: 21 additions & 11 deletions settings_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,33 @@ def get_env_boolvar(var_name, default=NOT_SET):
}

CONGRESS_LEGISLATORS_PATH = get_env_variable('CONGRESS_LEGISLATORS_PATH', default='data/congress-legislators')
GEOIP_DB_PATH = None
RSS_CAMPAIGN_QUERYSTRING = get_env_variable('RSS_CAMPAIGN_QUERYSTRING', default="?utm_campaign=govtrack_feed&utm_source=govtrack/feed&utm_medium=rss")

from django.utils.crypto import get_random_string
default_secret_key = get_random_string(50, 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)')
SECRET_KEY = get_env_variable('SECRET_KEY', default=default_secret_key)

GOOGLE_ANALYTICS_KEY = get_env_variable('GOOGLE_ANALYTICS_KEY', default='')

# for registration
RECAPTCHA_PUBLIC_KEY = get_env_variable('RECAPTCHA_PUBLIC_KEY', default='')
RECAPTCHA_PRIVATE_KEY = get_env_variable('RECAPTCHA_PRIVATE_KEY', default='')
TWITTER_OAUTH_TOKEN = get_env_variable('TWITTER_OAUTH_TOKEN', default='')
TWITTER_OAUTH_TOKEN_SECRET = get_env_variable('TWITTER_OAUTH_TOKEN_SECRET', default='')
FACEBOOK_APP_ID = get_env_variable('FACEBOOK_APP_ID', default='')
FACEBOOK_APP_SECRET = get_env_variable('FACEBOOK_APP_SECRET', default='')
FACEBOOK_AUTH_SCOPE = get_env_variable('FACEBOOK_AUTH_SCOPE', default='') # can be an empty string
# Copy some environment variables into the Django settings object.
copy_env_vars = [
# For accounts logic.
"RECAPTCHA_PUBLIC_KEY",
"RECAPTCHA_PRIVATE_KEY",
"TWITTER_OAUTH_TOKEN", # also for automated tweets and used to update @GovTrack/Members-of-Congress twitter list
"TWITTER_OAUTH_TOKEN_SECRET",
"FACEBOOK_APP_ID", # also used for Facebook widgets
"FACEBOOK_APP_SECRET",
"FACEBOOK_AUTH_SCOPE",
"GOOGLE_APP_ID",
"GOOGLE_APP_SECRET",
"GOOGLE_AUTH_SCOPE",

# For us...
"GOOGLE_ANALYTICS_KEY",
"TWITTER_ACCESS_TOKEN", # for automated tweets and to update @GovTrack/Members-of-Congress twitter list
"TWITTER_ACCESS_TOKEN_SECRET",
]
for var in copy_env_vars:
locals()[var] = get_env_variable(var, default='')

# TODO. The ad-free payment requires something like this:
#import paypalrestsdk
Expand Down

0 comments on commit ce09e6d

Please sign in to comment.