def main(global_config, **settings): """ This function returns a Pyramid WSGI application. """ settings["sqlalchemy.url"] = env("SQLALCHEMY_URL", settings["sqlalchemy.url"]) with Configurator(settings=settings) as config: config.include('.models') config.include('pyramid_jinja2') config.include('.routes') config.scan() return config.make_wsgi_app()
from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import create_engine, MetaData from decouple import config as env DATABASES = { 'default': 'postgres://{}:{}@{}:{}/{}'.format(env("POSTGRES_USER"), env("POSTGRES_PASSWORD"), env("POSTGRES_ADDRESS"), env("POSTGRES_PORT"), env("POSTGRES_NAME")) } engine = create_engine(DATABASES['default']) meta = MetaData(engine) Base = declarative_base()
from decouple import config as env import os BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) SECRET_KEY = env('SECRET_KEY') DEBUG = env('DEBUG', default=False, cast=bool) ALLOWED_HOSTS = [] INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'rest_framework', 'rest_framework.authtoken' ] MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] ROOT_URLCONF = 'config.urls' TEMPLATES = [ {
# SECURITY WARNING: don't run with debug turned on in production! env_file = os.path.join(BASE_DIR.parent, ".env") if not os.path.isfile(env_file): import environ from google.cloud import secretmanager as sm SETTINGS_NAME = "application_settings_etl" _, project = google.auth.default() client = sm.SecretManagerServiceClient() name = f"projects/{project}/secrets/{SETTINGS_NAME}/versions/latest" payload = client.access_secret_version( name=name).payload.data.decode("UTF-8") env = environ.Env() env.read_env(io.StringIO(payload)) else: aut_file = env('KEY_JSON_FILE') GOOGLE_APPLICATION_CREDENTIALS = pathdir.join(BASE_DIR, aut_file) #os.environ["_PROXI"] = 'yes' os.environ[ "GOOGLE_APPLICATION_CREDENTIALS"] = GOOGLE_APPLICATION_CREDENTIALS _, _ = google.auth.default() try: IP_PROXI_EXT = env('_IP_PROXI_EXT') except: IP_PROXI_EXT = None DEBUG = bool(int(env('DEBUG'))) PROXI = 'no' if os.getenv('_PROXI') is None else os.getenv( '_PROXI') #env('_PROXI') PORT_PROXI = env('_PORT_PROXI')
https://docs.djangoproject.com/en/3.0/ref/settings/ """ import datetime import os from decouple import config as env from dj_database_url import parse as db_parse, config as db_url # 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! SECRET_KEY = env('SECRET_KEY') # SECURITY WARNING: don't run with debug turned on in production! DEBUG = env('DEBUG', cast=bool, default=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',
app.add_middleware(DBSessionMiddleware, db_url=DATABASES['default']) origins = [ "*", ] app.add_middleware( CORSMiddleware, allow_origins=origins, allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) JWT_CONFIG = { 'exp_days': 2, } SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) SECRET_KEY = env('SECRET_KEY') # Dependency def get_db(): db = SessionLocal() try: yield db finally: db.close()
""" import os import django_heroku from unipath import Path from decouple import config as env # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = Path(__file__).parent.parent # 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('SECRET_KEY') # SECURITY WARNING: don't run with debug turned on in production! DEBUG = env('DEBUG', cast=bool) ALLOWED_HOSTS = ['https://minitube-deeper.herokuapp.com/', '*',] # Application definition INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages',
https://docs.djangoproject.com/en/3.1/ref/settings/ """ import datetime from pathlib import Path from decouple import config as env from dj_database_url import parse as db_url from django.conf.global_settings import DATABASES # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent # 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('SECRET_KEY') # SECURITY WARNING: don't run with debug turned on in production! DEBUG = env('DEBUG', cast=bool, default=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', 'rest_framework', 'rest_framework.authtoken', 'rest_framework_swagger', 'drf_yasg', 'corsheaders', 'apps.user', 'apps.core' ]
"""Pyramid bootstrap environment. """ from alembic import context from decouple import config as env from faker.models.meta import Base from sqlalchemy import engine_from_config from pyramid.paster import get_appsettings from pyramid.paster import setup_logging config = context.config setup_logging(config.config_file_name) settings = get_appsettings(config.config_file_name) settings["sqlalchemy.url"] = env("SQLALCHEMY_URL", settings["sqlalchemy.url"]) target_metadata = Base.metadata def run_migrations_offline(): """Run migrations in 'offline' mode. This configures the context with just a URL and not an Engine, though an Engine is acceptable here as well. By skipping the Engine creation we don't even need a DBAPI to be available. Calls to context.execute() here emit the given string to the script output. """ context.configure(url=settings['sqlalchemy.url'])