def insert(data): DOTENV_FILE = '/home/pi/Desktop/smart-greenhouse/.env' env_config = Config(RepositoryEnv(DOTENV_FILE)) state_name_id = data[0] state = data[1] value = data[2] created_at = data[3] # Read database connection url from .env DATABASE_URL = env_config.get('DATABASE_URL') postgres_insert_query = """ INSERT INTO data_state ( state_name_id, state, value, created_at ) VALUES ( %s, %s, %s, %s ) """ record_to_insert = (state_name_id, state, value, created_at) con = None try: # create a new database connection by calling the connect() function con = psycopg2.connect(DATABASE_URL) # create a new cursor cur = con.cursor() cur.execute(postgres_insert_query, record_to_insert) con.commit() print(state_name_id, " successfully inserted into table") # close the communication with the HerokuPostgres cur.close() except Exception as error: print('Could not connect') print('Cause: {}'.format(error)) finally: # close the communication with the database server by calling the close() if con is not None: con.close() print('Connection closed')
# Development settings from .common import * import posixpath from decouple import Config, RepositoryEnv from .common import * # Go up two directories from project base and then into config env_path = os.path.join(BASE_DIR, '..', '..', 'config', 'development.env') env_config = Config(RepositoryEnv(env_path)) ALLOWED_HOSTS = [] SECRET_KEY = env_config.get('SECRET_KEY') DEBUG = env_config.get('DEBUG', cast=bool) AWS_STORAGE_BUCKET_NAME = env_config.get('AWS_STORAGE_BUCKET_NAME') AWS_S3_REGION_NAME = env_config.get('AWS_S3_REGION_NAME') # e.g. us-east-2 AWS_ACCESS_KEY_ID = env_config.get('AWS_ACCESS_KEY_ID') AWS_SECRET_ACCESS_KEY = env_config.get('AWS_SECRET_ACCESS_KEY') DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), } } # Tell django-storages the domain to use to refer to static files. AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME # Tell the staticfiles app to use S3Boto3 storage when writing the collected static files (when
from threading import Event # Wait for an event to occur from django.db import transaction, IntegrityError from decouple import Config, RepositoryEnv, UndefinedValueError from redis import StrictRedis, WatchError import socketio from .chatbot import room_to_chatbot_user, ChatBotUser from .serializers import ChatBoxMessageSerializer from .models import ChatRoom # Redis Server Options DOTENV_FILE = os.path.join(os.getcwd(), 'chatbox_socketio', '.env') env_config = Config(RepositoryEnv(DOTENV_FILE)) HOST = env_config.get('REDIS_SERVER_HOST') try: PASSWORD = env_config.get('REDIS_SERVER_PASSWORD') except UndefinedValueError: PASSWORD = None PORT = env_config.get('REDIS_SERVER_PORT') if PASSWORD is None: REDIS_CONNECTION = StrictRedis(host=HOST, port=PORT) else: REDIS_CONNECTION = StrictRedis(host=HOST, password=PASSWORD, port=PORT) try: CHATBOX_DEMO_APPLICATION = env_config.get('CHATBOX_DEMO_APPLICATION',
import boto3 from boto3.dynamodb.conditions import Key, Attr import datetime import uuid import boto3 import datetime import uuid from decouple import Config, RepositoryEnv DOTENV_PATH = ".env" env = Config(RepositoryEnv(DOTENV_PATH)) # Call user/event table from AWS session = boto3.Session( aws_access_key_id=env.get('AWS_ACCESS_KEY_ID'), aws_secret_access_key=env.get('AWS_SECRET_ACCESS_KEY'), ) s3 = session.client('s3') dynamodb = session.resource('dynamodb', region_name='ap-southeast-2') meet_ball_user = dynamodb.Table('meet_ball_user') # Note compulsory attributes name, host_id, location # Attributes without values will use default vaues # If creating new event attributes can be empty # if person_limit, time_limit and radius are empty enter default values def add_event_to_table(host_id, name, place, description, photo, time, person_limit, time_limit, radius):
from ast import literal_eval DOTENV_FILE = './.env' env_config = Config(RepositoryEnv(DOTENV_FILE)) # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) IMPORTED_SETTINGS = None # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = env_config.get('SECRET_KEY') # Application definition INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'rest_framework', 'corsheaders', 'back-end' ] MIDDLEWARE = [ 'corsheaders.middleware.CorsMiddleware', 'django.middleware.common.BrokenLinkEmailsMiddleware', 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',
from os.path import dirname, abspath, join from decouple import Config, RepositoryEnv BASE_DIR = dirname(abspath(__file__)) DOTENV_FILE = join(BASE_DIR, '.env') env_config = Config(RepositoryEnv(DOTENV_FILE)) SERVER_ADDR = env_config.get("SERVER_ADDR") SERVER_PORT = env_config.get("SERVER_PORT") MSG_LEN = 1024
from .base import * from decouple import Config, RepositoryEnv DOTENV_FILE = './.env' env_config = Config(RepositoryEnv(DOTENV_FILE)) # SECURITY WARNING: don't run with debug turned on in production! DEBUG = False # ALLOWED_HOSTS = ["titanrecruit.net"] ALLOWED_HOSTS = [env_config.get('SERVER_NAME')] # Email Server Setting # EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' # Other security settings SECURE_CONTENT_TYPE_NOSNIFF = True SECURE_BROWSER_XSS_FILTER = True SESSION_COOKIE_SECURE = True SECURE_SSL_REDIRECT = True SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') # X_FRAME_OPTIONS = "DENY" CSRF_COOKIE_SECURE = True # Change it to true after installing SSL
from decouple import Config, RepositoryEnv from .base import * DOTENV_FILE = REPO_DIR.child('local.env') ENV_CONFIG = Config(RepositoryEnv(DOTENV_FILE)) SECRET_KEY = ENV_CONFIG.get('SECRET_KEY') DEBUG = ENV_CONFIG.get('DEBUG', cast=bool) ALLOWED_HOSTS = ENV_CONFIG.get('ALLOWED_HOSTS').split(',') MIDDLEWARE.remove('django.middleware.csrf.CsrfViewMiddleware') SESSION_ENGINE = 'django.contrib.sessions.backends.file' SESSION_FILE_PATH = REPO_DIR.child('django_sessions') SESSION_SAVE_EVERY_REQUEST = True DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': REPO_DIR.child('db.sqlite3'), } }
For the full list of settings and their values, see https://docs.djangoproject.com/en/2.2/ref/settings/ """ import os from decouple import Config, RepositoryEnv # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) env_config = Config(RepositoryEnv(os.path.join(BASE_DIR, '.env'))) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = env_config.get('SECRET_KEY') # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles',
service=APP_NAME, servers=_ZK_SERVERS, username=_ZK_USERNAME, password=_ZK_PASSWORD, cluster=CLUSTER ) config_manager = bootstrap.get_config_manager() config_repository = RepositoryHuskar( manager=config_manager, fallback=RepositoryShell(), fallback_key_prefix='HUSKAR_API_', ) config = Config(config_repository) DEBUG = config.get('DEBUG', cast=bool, default=False) TESTING = config.get('TESTING', default=False) SECRET_KEY = config.get('SECRET_KEY', cast=bytes) SENTRY_DSN = config.get('SENTRY_DSN', default=None) FALLBACK_SECRET_KEYS = config.get( 'FALLBACK_SECRET_KEYS', cast=partial(map, bytes), default=[]) DEFAULT_LOCALE = config.get('DEFAULT_LOCALE', 'zh_CN') DEFAULT_TIMEZONE = config.get('DEFAULT_TIMEZONE', 'Asia/Shanghai') DB_SETTINGS = { 'default': { 'urls': { 'master': config.get('DB_URL', default=None), 'slave': config.get('DB_URL', default=None), }, 'max_overflow': config.get('DB_MAX_OVERFLOW', default=-1),
For the full list of settings and their values, see https://docs.djangoproject.com/en/3.0/ref/settings/ """ import datetime import os from decouple import RepositoryEnv, Config from django.urls import reverse_lazy BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) env = os.environ.get('ENVIRONMENT') project_environment = env if env else 'local' ENV_FILE = os.path.join(BASE_DIR, '.env/.{}'.format(project_environment)) env_config = Config(RepositoryEnv(ENV_FILE)) SECRET_KEY = env_config.get('SECRET_KEY') DEBUG = env_config.get('DEBUG') ALLOWED_HOSTS = env_config.get('ALLOWED_HOSTS') # Application definition INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.postgres', 'rest_framework', 'apps.authentication', 'apps.answer',
# Development settings from .common import * import posixpath from decouple import Config, RepositoryEnv from .common import * # Go up two directories from project base and then into config env_path = os.path.join(BASE_DIR, '..', '..', 'config', 'production.env') env_config = Config(RepositoryEnv(env_path)) ALLOWED_HOSTS = env_config.get( 'ALLOWED_HOSTS', cast=lambda v: [s.strip() for s in v.split(',')]) SECRET_KEY = env_config.get('SECRET_KEY') DEBUG = env_config.get('DEBUG', cast=bool) AWS_STORAGE_BUCKET_NAME = env_config.get('AWS_STORAGE_BUCKET_NAME') AWS_S3_REGION_NAME = env_config.get('AWS_S3_REGION_NAME') # e.g. us-east-2 AWS_ACCESS_KEY_ID = env_config.get('AWS_ACCESS_KEY_ID') AWS_SECRET_ACCESS_KEY = env_config.get('AWS_SECRET_ACCESS_KEY') # Tell django-storages the domain to use to refer to static files. AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME # Tell the staticfiles app to use S3Boto3 storage when writing the collected static files (when # you run `collectstatic`). STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage' STATICFILES_LOCATION = 'static' STATICFILES_STORAGE = 'custom_storages.StaticStorage'
import os from decouple import Config, RepositoryEnv # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) #Reference to the file gig_root/gig/settings/'.env' env_config = Config(RepositoryEnv(os.path.join(BASE_DIR, '.env'))) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = env_config.get('SECRET_KEY') ALLOWED_HOSTS = ['gig.pythonanywhere.com'] # Application definition AUTH_USER_MODEL = "users.User" EMAIL_USE_TLS = True EMAIL_HOST = env_config.get('EMAIL_HOST') EMAIL_HOST_USER = env_config.get('EMAIL_HOST_USER') EMAIL_HOST_PASSWORD = env_config.get('EMAIL_HOST_PASSWORD') EMAIL_PORT = env_config.get('EMAIL_PORT', cast=int)
## LOAD CONFIG DATA #config = configparser.ConfigParser() #config.read('config.ini') ## SECURITY WARNING: keep the secret key used in production secret! #SECRET_KEY = config['DEFAULT']['PROJECT_SECRET_KEY'] ## Key for GEOCODE and MAPS API #GOOGLE_GEOCODE_API_KEY = config['DEFAULT']['GOOGLE_GEOCODE_API_KEY'] ## Key for PLACES API #GOOGLE_PLACES_API_KEY = config['DEFAULT']['GOOGLE_PLACES_API_KEY'] ## Key for DIRECTIONS API #GOOGLE_DIRECTIONS_API_KEY = config['DEFAULT']['GOOGLE_DIRECTIONS_API_KEY'] env_path = os.path.join(BASE_DIR,'..','..','config','development.env') print(env_path) env_config = Config(RepositoryEnv(env_path)) SECRET_KEY = env_config.get('PROJECT_SECRET_KEY') # Key for GEOCODE and MAPS API GOOGLE_GEOCODE_API_KEY = env_config.get('GOOGLE_GEOCODE_API_KEY') # Key for PLACES API GOOGLE_PLACES_API_KEY = env_config.get('GOOGLE_PLACES_API_KEY') # Key for DIRECTIONS API GOOGLE_DIRECTIONS_API_KEY = env_config.get('GOOGLE_DIRECTIONS_API_KEY') DEBUG = env_config.get('DEBUG',cast=bool) ALLOWED_HOSTS = [] # Database # https://docs.djangoproject.com/en/1.9/ref/settings/#databases DATABASES = { 'default': {
settings """ from decouple import Config, RepositoryEnv from video_streaming.env_config import ENV_FILE_PATH env_config = Config(RepositoryEnv(ENV_FILE_PATH)) PROJECT_NAME = "video_streaming" ################################################## # celery # ################################################## #: Only add pickle to this list if your broker is secured #: from unwanted access (see userguide/security.html) CELERY_BROKER_URL = env_config.get("CELERY_BROKER_URL", default="", cast=str) CELERY_RESULT_BACKEND = env_config.get("CELERY_RESULT_BACKEND", default="", cast=str) CELERY_ACCEPT_CONTENT = ['application/json'] CELERY_TASK_SERIALIZER = 'json' CELERY_RESULT_SERIALIZER = 'json' CELERY_BROKER_HEARTBEAT = 60 # load task modules from modules AUTO_DISCOVER_TASKS = [ f'{PROJECT_NAME}.core', f'{PROJECT_NAME}.grpc', f'{PROJECT_NAME}.ffmpeg' ] BASE_TASK_CLASS = 'video_streaming.core.tasks:BaseTask' TASK_RETRY_BACKOFF_MAX = env_config.get("TASK_RETRY_BACKOFF_MAX",
from decouple import Config, RepositoryEnv, UndefinedValueError from django.conf import settings from django.contrib.sessions.models import Session from django.core.cache import cache from django.core.management.base import BaseCommand from django.db import transaction from apps.clientwidget.models import ChatRoom DOTENV_FILE = os.path.join(os.getcwd(), 'chatbot', '.env') env_config = Config(RepositoryEnv(DOTENV_FILE)) try: USE_CELERY = env_config.get('USE_CELERY') except UndefinedValueError: USE_CELERY = False CHUNK_SIZE = 5000 def clear_ns(conn, ns): cursor = '0' ns_keys = ns + '*' while cursor != 0: cursor, keys = conn.scan(cursor=cursor, match=ns_keys, count=CHUNK_SIZE) if keys: conn.delete(*keys) return True
from boto3.session import Session import boto3 from decouple import RepositoryEnv, Config import os ambient = os.environ.get('ambient', "0") config = Config(RepositoryEnv('config.env')) cred = Config(RepositoryEnv('credentials.env')) _S3API = cred.get('aws_access_key_id', None) _S3SECRET = cred.get('aws_secret_access_key', None) _BUCKET = config.get('BUCKET') _REGION_NAME_S3 = config.get('REGION_NAME_S3', 'us-west-1') boto_sess = Session(region_name='us-west-1') if _S3API: boto_sess = Session( region_name='us-west-1', aws_access_key_id=_S3API, aws_secret_access_key=_S3SECRET )
'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'django_notebook_dev', 'USER': '******', 'PASSWORD': '******', 'HOST': 'localhost', 'PORT': '', } } # Email Settings EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' # Set config as .env.dev file # Using try expecpt so that tests can be run via GitHub Actions. try: env_path = 'notebook/settings/.env.local' env_config = Config(RepositoryEnv(env_path)) except: env_config = {} # Python Social Auth SOCIAL_AUTH_GITHUB_KEY = env_config.get('SOCIAL_AUTH_GITHUB_KEY', '') SOCIAL_AUTH_GITHUB_SECRET = env_config.get('SOCIAL_AUTH_GITHUB_SECRET', '') SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = env_config.get('SOCIAL_AUTH_GOOGLE_OAUTH2_KEY', '') SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = env_config.get('SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET', '')
https://docs.djangoproject.com/en/3.0/ref/settings/ """ import os from decouple import Config, RepositoryEnv # 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/3.0/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SETTINGS_INI_FILE = '../settings.ini' env_config = Config(RepositoryEnv(SETTINGS_INI_FILE)) SECRET_KEY = env_config.get('secret_key') # SECURITY WARNING: don't run with debug turned on in production! DEBUG = env_config.get('debug', cast=bool) ALLOWED_HOSTS = ['localhost', 'fabianoteichmann.pythonanywhere.com'] # Application definition INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles',
import os from decouple import Config, RepositoryEnv # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) TEMPLATE_DIR = os.path.join(BASE_DIR, 'templates') # Load config file DOTENV_FILE = BASE_DIR + '/config.ini' config = Config(RepositoryEnv(DOTENV_FILE)) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = config.get('SECRET_KEY') # SECURITY WARNING: don't run with debug turned on in production! DEBUG = config.get('DEBUG', cast=bool) ALLOWED_HOSTS = ['127.0.0.1', 'localhost'] # Application definition INSTALLED_APPS = [ 'flatpickr', 'dal', 'dal_select2', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes',
from .base import * from decouple import Csv, Config, RepositoryEnv # Set config as .env.dev file env_path = 'codeatlas/settings/.env.staging' env_config = Config(RepositoryEnv(env_path)) # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = env_config.get('SECRET_KEY') # SECURITY WARNING: don't run with debug turned on in production! DEBUG = env_config.get('DEBUG', default=False, cast=bool) ALLOWED_HOSTS = env_config.get('ALLOWED_HOSTS', cast=Csv()) # Database # https://docs.djangoproject.com/en/3.0/ref/settings/#databases DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': env_config.get('DB_NAME'), 'USER': env_config.get('DB_USER'), 'PASSWORD': env_config.get('DB_PASSWORD'), 'HOST': env_config.get('DB_HOST'), 'PORT': env_config.get('DB_PORT'), } } # Rest Api
from .base import * from decouple import Csv, Config, RepositoryEnv # Set config as .env.dev file env_path = 'notebook/settings/.env.staging' env_config = Config(RepositoryEnv(env_path)) # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = env_config.get('SECRET_KEY') # SECURITY WARNING: don't run with debug turned on in production! DEBUG = env_config.get('DEBUG', default=False, cast=bool) ALLOWED_HOSTS = env_config.get('ALLOWED_HOSTS', cast=Csv()) # Database # https://docs.djangoproject.com/en/3.0/ref/settings/#databases DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': env_config.get('DB_NAME'), 'USER': env_config.get('DB_USER'), 'PASSWORD': env_config.get('DB_PASSWORD'), 'HOST': env_config.get('DB_HOST'), 'PORT': env_config.get('DB_PORT'), } }
import json import pandas as pd from amftrack.transfer.functions.transfer import download, upload from tqdm.autonotebook import tqdm import dropbox from time import time_ns from decouple import Config, RepositoryEnv from pymatreader import read_mat DOTENV_FILE = (os.path.dirname( os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + "/local.env") env_config = Config(RepositoryEnv(DOTENV_FILE)) path_code = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + "/" temp_path = env_config.get("TEMP_PATH") target = env_config.get("DATA_PATH") data_path = env_config.get("STORAGE_PATH") fiji_path = env_config.get("FIJI_PATH") API = env_config.get("API_KEY") os.environ["TEMP"] = temp_path def pad_number(number): """ Convert number to string and padd with a zero Ex: 1 -> 01 23 -> 23 """
from celery.schedules import crontab from decouple import Config, RepositoryEnv # Build paths inside the project like this: BASE_DIR / 'subdir'. from firebase_admin import credentials BASE_DIR = Path(__file__).resolve(strict=True).parent.parent.parent # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ ENV_FILE = os.path.join(BASE_DIR, ".env.prod") env_config = Config(RepositoryEnv(ENV_FILE)) # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = env_config.get("SECRET_KEY") # SECURITY WARNING: don't run with debug turned on in production! DEBUG = int(env_config.get("DEBUG", default=0)) ALLOWED_HOSTS = env_config.get("DJANGO_ALLOWED_HOSTS").split(" ") # Application definition INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles',
from decouple import Config, RepositoryEnv from .common import * # decouple, by default searches for .env files in repo root # Need to point it in the right directory which is config/development.env env_path = os.path.join(BASE_DIR, '..', '..', 'config', 'development.env') env_config = Config(RepositoryEnv(env_path)) SECRET_KEY = env_config.get('SECRET_KEY') DEBUG = env_config.get('DEBUG', cast=bool) # This should be blank for development ALLOWED_HOSTS = [] DATABASES = { 'default': { 'ENGINE': env_config.get('DB_ENGINE'), 'NAME': os.path.join(BASE_DIR, env_config.get('DB_NAME')), } }
from decouple import Config, RepositoryEnv from .common import * # decouple, by default searches for .env files in repo root # Need to point it in the right directory which is config/production.env env_path = os.path.join(BASE_DIR,'..','..','config','production.env') env_config = Config(RepositoryEnv(env_path)) SECRET_KEY = env_config.get('SECRET_KEY') DEBUG = env_config.get('DEBUG',cast=bool) # Allowed Hosts should be a list ALLOWD_HOSTS = env_config.get('ALLOWED_HOSTS', cast=lambda v: [s.strip() for s in v.split(',')]) DATABASES = { 'default': { 'ENGINE': env_config.get('DB_ENGINE'), 'NAME': env_config.get('DB_NAME'), 'USER': env_config.get('DB_USER'), 'PASSWORD': env_config.get('DB_PASSWORD'), 'HOST': env_config.get('DB_HOST'), 'PORT': env_config.get('DB_PORT') } }
from pathlib import Path from decouple import Config, RepositoryEnv from ast import literal_eval # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve(strict=True).parent.parent # Create an env file DOTENV_FILE = '.env' env_config = Config(RepositoryEnv(DOTENV_FILE)) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = env_config.get('SECRET_KEY') # CORS Settings CORS_ORIGIN_ALLOW_ALL = True CORS_ORIGIN_WHITELIST = literal_eval(env_config.get('CORS_ORIGIN_WHITELIST')) # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True ALLOWED_HOSTS = env_config.get('ALLOWED_HOSTS') # Application definition INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'rest_framework',
from decouple import Config, RepositoryEnv from .common import * # Go up two directories from project base and then into config env_path = os.path.join(BASE_DIR,'..','..','config','production.env') env_config = Config(RepositoryEnv(env_path)) SECRET_KEY = env_config.get('PROJECT_SECRET_KEY') # Key for GEOCODE and MAPS API GOOGLE_GEOCODE_API_KEY = env_config.get('GOOGLE_GEOCODE_API_KEY') # Key for PLACES API GOOGLE_PLACES_API_KEY = env_config.get('GOOGLE_PLACES_API_KEY') # Key for DIRECTIONS API GOOGLE_DIRECTIONS_API_KEY = env_config.get('GOOGLE_DIRECTIONS_API_KEY') DEBUG = env_config.get('DEBUG',cast=bool) ALLOWED_HOSTS = env_config.get('ALLOWED_HOSTS', cast=lambda v: [s.strip() for s in v.split(',')]) DATABASES = { 'default': { 'ENGINE': env_config.get('DB_ENGINE'), 'NAME': env_config.get('DB_NAME'), 'USER': env_config.get('DB_USER'), 'PASSWORD': env_config.get('DB_PASSWORD'), 'HOST': env_config.get('DB_HOST'), # Or an IP Address that your DB is hosted on 'PORT': env_config.get('DB_PORT'), } }
from rest_api.database import db from rest_api.database.models import Author, Book from rest_api.api.restplus import api from rest_api.api.endpoints.authors import ns as author_namespace from rest_api.api.endpoints.books import ns as book_namespace app = Flask(__name__) app_config_file_path = os.path.normpath( os.path.join(os.path.dirname(__file__), './app.conf')) app_file_config = Config(RepositoryEnv(app_config_file_path)) logging_conf_path = os.path.normpath( os.path.join(os.path.dirname(__file__), './logging.conf')) logging.config.fileConfig(logging_conf_path) log = logging.getLogger(__name__) DEBUG_FLAG = app_file_config.get('DEBUG', cast=bool) def configure_app(flask_app): flask_app.config['SERVER_NAME'] = app_file_config.get('SERVER_NAME') flask_app.config['PROPAGATE_EXCEPTIONS'] = app_file_config.get( 'PROPAGATE_EXCEPTIONS') flask_app.config['SWAGGER_UI_DOC_EXPANSION'] = app_file_config.get( 'SWAGGER_UI_DOC_EXPANSION') flask_app.config['RESTPLUS_VALIDATE'] = app_file_config.get( 'RESTPLUS_VALIDATE', cast=bool) flask_app.config['RESTPLUS_MASK_SWAGGER'] = app_file_config.get( 'RESTPLUS_MASK_SWAGGER', cast=bool) flask_app.config['ERROR_404_HELP'] = app_file_config.get( 'RESTPLUS_ERROR_404_HELP', cast=bool)