import os
import boto
import redis
from flask import Flask, render_template, request, redirect, url_for, send_from_directory
from time import time
from werkzeug import secure_filename
import json
from cfenv import AppEnv

# Setup ECS variables locally if not runing in CF
##ecs_access_key_id = '<Insert your key>@ecstestdrive.emc.com'
##ecs_secret_key = '<Insert your key>'

env = AppEnv()
ecs_access_key_id = env.get_credential('ECS_access_key')
ecs_secret_key = env.get_credential('ECS_secret')
ecs_host = env.get_credential('ECS_host')

# Set bucket name
bname = 'images'
namespace = ecs_access_key_id.split('@')[0]

http_url = 'http://{ns}.{host}/{bucket}/'.format(
    ns=namespace, host='public.ecstestdrive.com', bucket=bname)

if 'VCAP_SERVICES' in os.environ:
    VCAP_SERVICES = json.loads(os.environ['VCAP_SERVICES'])
    CREDENTIALS = VCAP_SERVICES["rediscloud"][0]["credentials"]
    r = redis.Redis(host=CREDENTIALS["hostname"],
                    port=CREDENTIALS["port"],
Example #2
0
"""
WSGI config for omb_eregs project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/
"""

import os

import newrelic.agent
from cfenv import AppEnv
from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "omb_eregs.settings")

env = AppEnv()
app_name = os.environ.get('NEW_RELIC_APP_NAME')
license_key = env.get_credential('NEW_RELIC_LICENSE_KEY')

if app_name and license:
    nr_settings = newrelic.agent.global_settings()
    nr_settings.app_name = app_name
    nr_settings.license_key = license_key
    newrelic.agent.initialize()

application = get_wsgi_application()
Example #3
0
    # safe because: the password str is telling get_url what key to use when
    # looking up a value
    url = redis.get_url(    # nosec
        host='hostname', password='******', port='port')
    BROKER_URL = 'redis://{}'.format(url)
    CACHES['regs_gov_cache']['LOCATION'] = BROKER_URL
    CACHES['regs_gov_cache']['BACKEND'] = 'django_redis.cache.RedisCache'


s3 = env.get_service(label='s3')
if s3:
    ATTACHMENT_ACCESS_KEY_ID = s3.credentials.get('access_key_id')
    ATTACHMENT_SECRET_ACCESS_KEY = s3.credentials.get('secret_access_key')
    ATTACHMENT_BUCKET = s3.credentials.get('bucket')

REGS_GOV_API_URL = env.get_credential(
    'REGS_GOV_API_URL', os.environ.get('REGS_GOV_API_URL'))
REGS_GOV_API_LOOKUP_URL = env.get_credential(
    'REGS_GOV_API_LOOKUP_URL', os.environ.get('REGS_GOV_API_LOOKUP_URL'))
REGS_GOV_API_KEY = env.get_credential(
    'REGS_GOV_API_KEY', os.environ.get('REGS_GOV_API_KEY'))
HTTP_AUTH_USER = env.get_credential('HTTP_AUTH_USER')
HTTP_AUTH_PASSWORD = env.get_credential('HTTP_AUTH_PASSWORD')

# HTTP Auth may have be different due to the above lines
if HTTP_AUTH_USER and HTTP_AUTH_PASSWORD:
    API_BASE = 'http://{}:{}@localhost:{}/api/'.format(
        HTTP_AUTH_USER, HTTP_AUTH_PASSWORD,
        os.environ.get('VCAP_APP_PORT', '8000'))

# Cookie settings - we don't inspect the contents of cookies, but this is good
# practice
Example #4
0
    # safe because: the password str is telling get_url what key to use when
    # looking up a value
    url = redis.get_url(    # nosec
        host='hostname', password='******', port='port')
    BROKER_URL = 'redis://{}'.format(url)
    CACHES['regs_gov_cache']['LOCATION'] = BROKER_URL
    CACHES['regs_gov_cache']['BACKEND'] = 'django_redis.cache.RedisCache'


s3 = env.get_service(label='s3')
if s3:
    ATTACHMENT_ACCESS_KEY_ID = s3.credentials.get('access_key_id')
    ATTACHMENT_SECRET_ACCESS_KEY = s3.credentials.get('secret_access_key')
    ATTACHMENT_BUCKET = s3.credentials.get('bucket')

REGS_GOV_API_URL = env.get_credential('REGS_GOV_API_URL')
REGS_GOV_API_LOOKUP_URL = env.get_credential('REGS_GOV_API_LOOKUP_URL')
REGS_GOV_API_KEY = env.get_credential('REGS_GOV_API_KEY')
HTTP_AUTH_USER = env.get_credential('HTTP_AUTH_USER')
HTTP_AUTH_PASSWORD = env.get_credential('HTTP_AUTH_PASSWORD')
COMMENT_DOCUMENT_ID = env.get_credential('DOCUMENT_ID')

# HTTP Auth may have be different due to the above lines
if HTTP_AUTH_USER and HTTP_AUTH_PASSWORD:
    API_BASE = 'http://{}:{}@localhost:{}/api/'.format(
        HTTP_AUTH_USER, HTTP_AUTH_PASSWORD,
        os.environ.get('PORT', '8000'))

# Cookie settings - we don't inspect the contents of cookies, but this is good
# practice
SESSION_COOKIE_HTTPONLY = True  # note that this is also Django's default
Example #5
0
logging.basicConfig(level=logging.INFO, stream=sys.stdout)

env = AppEnv()

DEBUG = False
TEMPLATE_DEBUG = False
ANALYTICS = {
}

DATABASES = {
    'default': dj_database_url.config()
}


vcap_app = json.loads(os.environ.get('VCAP_APPLICATION', '{}'))
ALLOWED_HOSTS = ['localhost'] + vcap_app.get('application_uris', [])

vcap_services = json.loads(os.environ.get('VCAP_SERVICES', '{}'))
es_config = vcap_services.get('elasticsearch-swarm-1.7.1', [])
if es_config:
    HAYSTACK_CONNECTIONS['default'] = {
        'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
        'URL': es_config[0]['credentials']['uri'],
        'INDEX_NAME': 'eregs',
    }

HTTP_AUTH_USER = env.get_credential('HTTP_AUTH_USER')
HTTP_AUTH_PASSWORD = env.get_credential('HTTP_AUTH_PASSWORD')

STATIC_URL = '/regulations/static/'
Example #6
0
        'GA_SITE_ID': 'UA-48605964-22',
    },
    'DAP': {
        'AGENCY': 'FEC',
    },
}

DATABASES = {'default': dj_database_url.config()}

vcap_app = json.loads(os.environ.get('VCAP_APPLICATION', '{}'))
ALLOWED_HOSTS = ['localhost'] + vcap_app.get('application_uris', [])

vcap_services = json.loads(os.environ.get('VCAP_SERVICES', '{}'))
es_config = vcap_services.get('elasticsearch24')
if es_config:
    HAYSTACK_CONNECTIONS['default'] = {
        'ENGINE':
        'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
        'URL': es_config[0]['credentials']['uri'],
        'INDEX_NAME': 'eregs',
    }

HTTP_AUTH_USER = env.get_credential('HTTP_AUTH_USER')
HTTP_AUTH_PASSWORD = env.get_credential('HTTP_AUTH_PASSWORD')

STATIC_URL = '/regulations/static/'
API_BASE = 'http://localhost:{}/regulations/api/'.format(
    os.environ.get('PORT', '8000'))

CACHES['eregs_longterm_cache']['TIMEOUT'] = 60 * 60
Example #7
0
import os

import dj_database_url
from cfenv import AppEnv
from django.utils.crypto import get_random_string

env = AppEnv()

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = env.get_credential('DJANGO_SECRET_KEY', get_random_string(50))

DEBUG = os.environ.get('DEBUG', 'FALSE').upper() == 'TRUE'

ALLOWED_HOSTS = env.uris

# Application definition

INSTALLED_APPS = (
    'reqs.apps.ReqsConfig',
    'taggit',
    'django.contrib.contenttypes',
    # must be after taggit and contenttypes, but before auth
    'ereqs_admin.apps.EreqsAdminConfig',
    'corsheaders',
    'django_filters',
Example #8
0
redis = env.get_service(label='redis28-swarm')
if redis:
    # safe because: the password str is telling get_url what key to use when
    # looking up a value
    url = redis.get_url(  # nosec
        host='hostname', password='******', port='port')
    BROKER_URL = 'redis://{}'.format(url)
    CACHES['regs_gov_cache']['LOCATION'] = BROKER_URL
    CACHES['regs_gov_cache']['BACKEND'] = 'django_redis.cache.RedisCache'

s3 = env.get_service(label='s3')
if s3:
    ATTACHMENT_ACCESS_KEY_ID = s3.credentials.get('access_key_id')
    ATTACHMENT_SECRET_ACCESS_KEY = s3.credentials.get('secret_access_key')
    ATTACHMENT_BUCKET = s3.credentials.get('bucket')

REGS_GOV_API_URL = env.get_credential('REGS_GOV_API_URL',
                                      os.environ.get('REGS_GOV_API_URL'))
REGS_GOV_API_LOOKUP_URL = env.get_credential(
    'REGS_GOV_API_LOOKUP_URL', os.environ.get('REGS_GOV_API_LOOKUP_URL'))
REGS_GOV_API_KEY = env.get_credential('REGS_GOV_API_KEY',
                                      os.environ.get('REGS_GOV_API_KEY'))
HTTP_AUTH_USER = env.get_credential('HTTP_AUTH_USER')
HTTP_AUTH_PASSWORD = env.get_credential('HTTP_AUTH_PASSWORD')

# HTTP Auth may have be different due to the above lines
if HTTP_AUTH_USER and HTTP_AUTH_PASSWORD:
    API_BASE = 'http://{}:{}@localhost:{}/api/'.format(
        HTTP_AUTH_USER, HTTP_AUTH_PASSWORD,
        os.environ.get('VCAP_APP_PORT', '8000'))
Example #9
0
app = Flask(__name__)

from app import views
views.register(app)

from app import helpers
helpers.register(app)

port = int(os.getenv("PORT", 5000))
environment = os.getenv("PULSE_ENV", "development")

if environment == "development":
  app.debug = True

# Configure newrelic
env = AppEnv()
app_name = os.environ.get('NEW_RELIC_APP_NAME')
license_key = env.get_credential('NEW_RELIC_LICENSE_KEY')

if app_name and license_key:
    nr_settings = newrelic.agent.global_settings()
    nr_settings.app_name = app_name
    nr_settings.license_key = license_key
    newrelic.agent.initialize()

if __name__ == "__main__":
  if environment == "development":
    app.run(port=port)
  else:
    serve(app, port=port)
Example #10
0
import os

import newrelic.agent
from cfenv import AppEnv
from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "atf_eregs.settings")
# important that the whitenoise import is after the line above
from whitenoise.django import DjangoWhiteNoise

env = AppEnv()

settings = newrelic.agent.global_settings()
settings.app_name = env.get_credential('NEW_RELIC_APP_NAME')
settings.license_key = env.get_credential('NEW_RELIC_LICENSE_KEY')
newrelic.agent.initialize()

application = DjangoWhiteNoise(get_wsgi_application())
Example #11
0
TEMPLATES[0]['OPTIONS']['builtins'] = [
    'overextends.templatetags.overextends_tags'
]

TEST_RUNNER = 'django_nose.runner.NoseTestSuiteRunner'

ROOT_URLCONF = 'fec_eregs.urls'

DATABASES = REGCORE_DATABASES

API_BASE = 'http://localhost:{}/api/'.format(os.environ.get('PORT', '8000'))

STATICFILES_DIRS = ['compiled']
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'frontend_build')

DATA_LAYERS = DATA_LAYERS or []

DATA_LAYERS = DATA_LAYERS + (
    'regulations.generator.layers.external_citation.ExternalCitationLayer', )

FEC_API_KEY = env.get_credential('FEC_API_KEY', '')
FEC_API_VERSION = os.environ.get('FEC_API_VERSION', 'v1')

FEC_API_URL = os.environ.get('FEC_API_URL', '')
FEC_CMS_URL = os.environ.get('FEC_CMS_URL', '')
FEC_WEB_URL = os.environ.get('FEC_WEB_URL', '')

SIDEBARS = ('regulations.generator.sidebar.help.Help', )
Example #12
0
if redis:
    # safe because: the password str is telling get_url what key to use when
    # looking up a value
    url = redis.get_url(  # nosec
        host='hostname', password='******', port='port')
    BROKER_URL = 'redis://{}'.format(url)
    CACHES['regs_gov_cache']['LOCATION'] = BROKER_URL
    CACHES['regs_gov_cache']['BACKEND'] = 'django_redis.cache.RedisCache'

s3 = env.get_service(label='s3')
if s3:
    ATTACHMENT_ACCESS_KEY_ID = s3.credentials.get('access_key_id')
    ATTACHMENT_SECRET_ACCESS_KEY = s3.credentials.get('secret_access_key')
    ATTACHMENT_BUCKET = s3.credentials.get('bucket')

REGS_GOV_API_URL = env.get_credential('REGS_GOV_API_URL')
REGS_GOV_API_LOOKUP_URL = env.get_credential('REGS_GOV_API_LOOKUP_URL')
REGS_GOV_API_KEY = env.get_credential('REGS_GOV_API_KEY')
HTTP_AUTH_USER = env.get_credential('HTTP_AUTH_USER')
HTTP_AUTH_PASSWORD = env.get_credential('HTTP_AUTH_PASSWORD')
COMMENT_DOCUMENT_ID = env.get_credential('DOCUMENT_ID')

# HTTP Auth may have be different due to the above lines
if HTTP_AUTH_USER and HTTP_AUTH_PASSWORD:
    API_BASE = 'http://{}:{}@localhost:{}/api/'.format(
        HTTP_AUTH_USER, HTTP_AUTH_PASSWORD, os.environ.get('PORT', '8000'))

# Cookie settings - we don't inspect the contents of cookies, but this is good
# practice
SESSION_COOKIE_HTTPONLY = True  # note that this is also Django's default
SESSION_COOKIE_SECURE = True
Example #13
0
    '--verbosity=3'
]

TEMPLATES[0]['OPTIONS']['context_processors'] += (
    'fec_eregs.context_processors.app_urls',
)

TEST_RUNNER = 'django_nose.runner.NoseTestSuiteRunner'

ROOT_URLCONF = 'fec_eregs.urls'

DATABASES = REGCORE_DATABASES

API_BASE = 'http://localhost:{}/api/'.format(
    os.environ.get('VCAP_APP_PORT', '8000'))

STATICFILES_DIRS = ['compiled']
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

DATA_LAYERS = DATA_LAYERS or []

DATA_LAYERS = DATA_LAYERS + (
    'regulations.generator.layers.external_citation.ExternalCitationLayer',)

FEC_API_KEY = env.get_credential('FEC_API_KEY', '')
FEC_API_VERSION = os.environ.get('FEC_API_VERSION', 'v1')

FEC_API_URL = os.environ.get('FEC_API_URL', '')
FEC_CMS_URL = os.environ.get('FEC_CMS_URL', '')
FEC_WEB_URL = os.environ.get('FEC_WEB_URL', '')