Exemple #1
0
def inicializar_database():
    global DATABASE
    try:
        env = environ.Env()
        environ.Env.read_env(env_file=os.path.join(BASE_DIR, '.env'))

        DATABASE = psycopg2.connect(user=env('DATABASE_USER'),
                                    password=env('DATABASE_PASSWORD'),
                                    host=env('DATABASE_HOST'),
                                    port=env('DATABASE_PORT'),
                                    database=env('DATABASE_NAME'))
    except (ValueError, Exception):
        DATABASE = None
        utils.logger('e', 'No ha sido posible incializar la base de datos',
                     ValueError, Exception)
Exemple #2
0
def test_get_db_config(monkeypatch):
    """Make sure we resolve relative db path."""
    env = environ.Env()

    def mock_database_url(env_vars):
        env_vars['DATABASE_URL'] = 'sqlite:///db.sqlite3'
        return env_vars

    monkeypatch.setattr(env, 'ENVIRON', mock_database_url(env.ENVIRON))

    option = env.str('DATABASE_URL')

    assert isinstance(option, str)
    assert not os.path.isabs(option)

    options = get_db_config('DATABASE_URL')
    assert 'NAME' in options
    assert os.path.isabs(options['NAME'])
Exemple #3
0
Generated by 'django-admin startproject' using Django 3.1.2.

For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""
from datetime import timedelta
from pathlib import Path
from environ import environ

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

env = environ.Env(DEBUG=(bool, False),
                  REDIS_URL=(str, 'redis://127.0.0.1:6379'))
env.read_env(str(BASE_DIR / '.env'))

# 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')

ALLOWED_HOSTS = ['*']

# CORS_ALLOWED_ORIGINS = [
#     '*'
Exemple #4
0
# -*- coding: utf-8 -*-

import json
import boto3

from environ import environ

env = environ.Env()


class SNS:

    SNS_VEHICLE_STATE_TOPIC = env('SNS_VEHICLE_STATE_TOPIC', default=None)

    @classmethod
    def publish_vehicle_state(cls, vehicle_profile):
        cls.publish_message(
            topic=cls.SNS_VEHICLE_STATE_TOPIC,
            message={
                'label': vehicle_profile.label,
                'state': vehicle_profile.state,
            }
        )

    @classmethod
    def publish_message(cls, topic, message):
        sns = boto3.client('sns')
        sns.publish(
            TopicArn=topic,
            Message=json.dumps({'default': json.dumps(message)}),
            MessageStructure='json',
https://docs.djangoproject.com/en/3.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""
import os
from pathlib import Path

import sentry_sdk
from environ import environ, ImproperlyConfigured
from sentry_sdk.integrations.django import DjangoIntegration

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

env = environ.Env(DEBUG=(bool, False), )
dotenv_file = BASE_DIR / ".env"
if dotenv_file.exists():
    environ.Env.read_env(str(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("SECRET_KEY")

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = env("DEBUG", cast=bool)

DEBUG_SQL_QUERIES = env("DEBUG_SQL_QUERIES", cast=bool)
Exemple #6
0
https://docs.djangoproject.com/en/3.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""
import os
from pathlib import Path
from environ import environ

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

env = environ.Env(
    SECRET_KEY=str,
    DEBUG=(bool, False),
    APP_ENVIRONMENT=str,
    ALLOWED_HOSTS=list,
    CORS_ORIGIN_WHITELIST=list,
)

# 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")

ALLOWED_HOSTS = env("ALLOWED_HOSTS")
CORS_ORIGIN_WHITELIST = env("CORS_ORIGIN_WHITELIST")
Exemple #7
0
BASE_DIR = Path(__file__).resolve().parent.parent

# Set VAR=(casting, default value)
env = environ.Env(
    DEBUG=(bool, False),
    ALLOW_ROBOTS=(bool, False),
    USE_SSL=(bool, False),
    COMPRESS_OFFLINE=(bool, False),
    ALLOWED_HOSTS=(list, []),
    INTERNAL_IPS=(list, []),
    ADMINS=(list, []),

    SECURE_SSL_REDIRECT=(bool, False),
    SECURE_HSTS_SECONDS=(int, 3600),
    SECURE_HSTS_INCLUDE_SUBDOMAINS=(bool, False),
    SECURE_HSTS_PRELOAD=(bool, False),
    SESSION_COOKIE_SECURE=(bool, False),
    CSRF_COOKIE_SECURE=(bool, False),

    # Celery
    CELERY_ALWAYS_EAGER=(bool, True),
    CELERY_USE_SSL=(bool, False),
    CELERY_RESULT_BACKEND=(str, None),
    CELERY_TIMEZONE=(str, 'Europe/Kiev'),
    CELERYD_CONCURRENCY=(int, 1),
    CELERYD_POOL=(str, 'prefork'),
    BROKER_URL=(str, None),
    BROKER_CONNECTION_TIMEOUT=(float, 4.0),
)

# Reading environment file.
if os.path.exists(BASE_DIR / '.env'):
Exemple #8
0
https://docs.djangoproject.com/en/3.0/ref/settings/
"""

import os

# noinspection PyPackageRequirements
from environ import environ

# 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 = environ.Env(
    DJANGO_SECRET_KEY=str,
    DEBUG=(bool, False),
    RMQ_USER=str,
    RMQ_PASS=str,
    RMQ_VHOST=str,
    RMQ_HOST=(str, '127.0.0.1'),
    RMQ_PORT=(int, 5672),
    NPM=str,
)

if os.path.exists(os.path.join(BASE_DIR, '..', '.env')):
    env.read_env(os.path.join(BASE_DIR, '..', '.env'))

# 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('DJANGO_SECRET_KEY')

# SECURITY WARNING: don't run with debug turned on in production!
Exemple #9
0
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""
import os
from pathlib import Path

import dj_database_url
# noinspection PyPackageRequirements
from environ import environ

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve(strict=True).parent.parent

env = environ.Env(SECRET_KEY=str,
                  ENV=(str, 'DEVELOPMENT'),
                  REDIS_URL=str,
                  DATABASE_URL=(str, None))

if os.path.isfile(BASE_DIR / '.env'):
    env.read_env(str(BASE_DIR / '.env'))

# 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('ENV') == 'DEVELOPMENT'

ALLOWED_HOSTS = [
Exemple #10
0
import sentry_sdk
from environ import environ
from sentry_sdk.integrations.django import DjangoIntegration

ROOT_DIR = environ.Path(__file__) - 2
APPS_DIR = ROOT_DIR.path('store_apps')

env = environ.Env(
    DJANGO_DEBUG=(bool, True),
    DJANGO_SECRET_KEY=(str, ''),
    DJANGO_ADMINS=(list, []),
    DJANGO_ALLOWED_HOSTS=(list, ['*']),
    DJANGO_STATIC_ROOT=(str, str(APPS_DIR('staticfiles'))),
    DJANGO_MEDIA_ROOT=(str, str(APPS_DIR('media'))),
    DJANGO_DATABASE_URL=(str, f'sqlite:////{str(ROOT_DIR)}\\django_sqlite.db'),
    DJANGO_EMAIL_URL=(environ.Env.email_url_config, 'consolemail://'),
    DJANGO_DEFAULT_FROM_EMAIL=(str, '*****@*****.**'),
    DJANGO_SERVER_EMAIL=(str, '*****@*****.**'),
    DJANGO_STRIPE_PUBLIC_KEY=(str, ''),
    DJANGO_STRIPE_SECRET_KEY=(str, ''),
    DJANGO_TEST_RUN=(bool, False),
    DJANGO_HEALTH_CHECK_BODY=(str, 'Success'),
)

environ.Env.read_env(env_file=os.path.join(str(ROOT_DIR), '.env'))

DEBUG = env.bool("DJANGO_DEBUG", default=False)

SECRET_KEY = env('DJANGO_SECRET_KEY')

ALLOWED_HOSTS = env.list('DJANGO_ALLOWED_HOSTS')
Exemple #11
0
"""
import os
from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
from environ import environ

BASE_DIR = Path(__file__).resolve().parent.parent

# SECURITY WARNING: don't run with debug turned on in production!
env = environ.Env(ALLOWED_HOSTS=(list, []),
                  DEBUG=(bool, False),
                  SENTRY_DSN=(str, None),
                  SENTRY_PII=(bool, False),
                  ELASTIC_APM=(bool, False),
                  DEBUG_TOOLBAR_ENABLED=(bool, False),
                  CORS_ORIGIN_ALLOW_ALL=(bool, False),
                  CORS_ORIGIN_WHITELIST=(list, []),
                  EMAIL_USE_SSL=(bool, False),
                  EMAIL_USE_TLS=(bool, False),
                  MEDIA_ROOT=(str, os.path.join(BASE_DIR, "mediafiles")))

# SECURITY WARNING: don't run with debug turned on in production!
ALLOWED_HOSTS = env('ALLOWED_HOSTS')
DEBUG = env('DEBUG')

CORS_ORIGIN_ALLOW_ALL = env("CORS_ORIGIN_ALLOW_ALL")
CORS_ORIGIN_WHITELIST = env("CORS_ORIGIN_WHITELIST")

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