def test_apply_env_defaults(): """ Test loading the default .env file. """ apply_env() assert_env(os.environ)
class Config(object): logger.debug("Start of the Config() class.") # Apply the environment variables when running locally # When running in GCP, these are loaded from the env_variables.yaml file when the app loads if local: from env_tools import apply_env apply_env() logger.info("Local .env variables applied.") DEBUG = True else: DEBUG = False # Load AWS credentials AWS_ACCOUNT_ID = environ.get('AWS_ACCOUNT_ID') AWS_ACCESS_KEY = environ.get('AWS_ACCESS_KEY_ID') AWS_SECRET_ACCESS_KEY = environ.get('AWS_SECRET_ACCESS_KEY') AWS_USER = environ.get('AWS_USER') AWS_REGION = environ.get('AWS_REGION') # Load app-related credentials BOUND_PORT = 5000 DOMAIN_URL = environ.get('DOMAIN_URL') WHITELISTED_ORIGIN = environ.get('WHITELISTED_ORIGIN') WHITELISTED_ORIGINS = environ.get('WHITELISTED_ORIGINS') SECRET_KEY = environ.get( 'SECRET_KEY') or '0y4TJIyEjH8ZVkXPMGBiFEcHk8tdfe57kE1IJhvR1yb1cmWY' if SECRET_KEY != environ.get('SECRET_KEY'): logger.warning( "Error loading SECRET_KEY! Temporarily using a hard-coded key.") logger.debug("End of the Config() class.")
class Config(object): """Define the config parameters for this app.""" logger.info("Start of the Config() class.") # Location for environment variables is automatically set by the env_variables.yaml file when running in GCP if local: from env_tools import apply_env apply_env() logger.info("Applied .env variables using env_tools") # AWS credentials aws_account_id = environ.get('AWS_ACCOUNT_ID') aws_access_key = environ.get('AWS_ACCESS_KEY_ID') aws_secret_access_key = environ.get('AWS_SECRET_ACCESS_KEY') aws_user = environ.get('AWS_USER') aws_region = environ.get('AWS_REGION') aws_arn = environ.get('AWS_ARN') # App-related SECRET_KEY = environ.get( 'SECRET_KEY') or '0mW7@LN0n32L6ntaj0d8jzsXiAW4mkPL7u5l' domain_url = environ.get('DOMAIN_URL') # Date & time formatting prefs date_format = '%Y-%m-%d' datetime_format = '%Y-%m-%d %H:%M:%S' step_when_format = '%a %H:%M' logger.info("End of the Config() class.")
def test_config(): # Apply environment variables apply_env() # AWS credentials assert Config.AWS_ACCOUNT_ID is not None assert Config.AWS_ACCESS_KEY is not None assert Config.AWS_SECRET_ACCESS_KEY is not None assert Config.AWS_USER is not None assert Config.AWS_REGION is not None # App-related assert Config.BOUND_PORT is not None # assert Config.DOMAIN_URL is not None assert Config.WHITELISTED_ORIGINS is not None assert Config.SECRET_KEY is not None assert Config.DEBUG is not None
"""Migrate data from the local sqlite db to DynamoDB.""" import boto3 import sqlite3 import time from os import environ # set the config variables from env_tools import apply_env apply_env() # AWS Credentials aws_account_id = environ.get('AWS_ACCOUNT_ID') aws_access_key = environ.get('AWS_ACCESS_KEY') aws_secret_access_key = environ.get('AWS_SECRET_ACCESS_KEY') aws_user = environ.get('AWS_USER') aws_region = environ.get('AWS_REGION') aws_arn = environ.get('AWS_ARN') # initialize the dynamodb connections db = boto3.resource('dynamodb', region_name=aws_region, aws_access_key_id=aws_access_key, aws_secret_access_key=aws_secret_access_key, endpoint_url='http://localhost:8008') db_cloud = boto3.resource('dynamodb', region_name=aws_region, aws_access_key_id=aws_access_key, aws_secret_access_key=aws_secret_access_key) # initialize the sqlite db connection
import dj_database_url import django_heroku from env_tools import apply_env def to_bool(env, default="false"): """ Convert a string to a bool. """ return bool(util.strtobool(os.getenv(env, default))) # Apply the env in the .env file apply_env() # Detect when the tests are being run so we can disable certain features TESTING = "test" in sys.argv # ON_HEROKU should be true if we are running on heroku. ON_HEROKU = to_bool("ON_HEROKU") # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(__file__)) PORT = os.getenv("PORT", 8000) ENV = os.getenv("ENV", "development") # ENV = 'staging' DOMAIN = os.getenv("DOMAIN", "localhost:{}".format(PORT))
import os import requests # Loads environmental variables from a file, # by default it will load all variables from '.env' from env_tools import apply_env; apply_env() # TMDb API configuration API_VERSION = '3' API_ROOT_URL = 'https://api.themoviedb.org/{version}'.format(version=API_VERSION) API_KEY = os.environ['TMDB_API_KEY'] # To build image URL from TMDb three elements are required: base URL, size, and file path. # Base URL and a list of sizes is returned from calling TMDb API /configuration method # http://docs.themoviedb.apiary.io/#reference/configuration url = API_ROOT_URL + '/configuration' request = requests.get(url, params={'api_key': API_KEY}) IMAGE_BASE_URL = request.json()['images']['base_url'] IMAGE_BASE_URL += request.json()['images']['poster_sizes'][4] class movie(object): """Movie object with three properties: a writable title, poster image URL, and trailer youtube id. Attributes: title: A string. poster_image_url: String, the URL for the movie's poster image trailer_youtube_id: String, youtube trailer video id, used to fetch trailer. To use: