def test_secret_value(self):
        self.assertRaises(ValueError, SecretValue, "default")

        value = SecretValue()
        self.assertRaises(ValueError, value.setup, "TEST")
        with env(DJANGO_SECRET_KEY="123"):
            self.assertEqual(value.setup("SECRET_KEY"), "123")

        value = SecretValue(environ_name="FACEBOOK_API_SECRET", environ_prefix=None, late_binding=True)
        self.assertRaises(ValueError, value.setup, "TEST")
        with env(FACEBOOK_API_SECRET="123"):
            self.assertEqual(value.setup("TEST"), "123")
    def test_secret_value(self):
        self.assertRaises(ValueError, SecretValue, 'default')

        value = SecretValue()
        self.assertRaises(ValueError, value.setup, 'TEST')
        with env(DJANGO_SECRET_KEY='123'):
            self.assertEqual(value.setup('SECRET_KEY'), '123')

        value = SecretValue(environ_name='FACEBOOK_API_SECRET',
                            environ_prefix=None)
        self.assertRaises(ValueError, value.setup, 'TEST')
        with env(FACEBOOK_API_SECRET='123'):
            self.assertEqual(value.setup('TEST'), '123')
Exemple #3
0
class Development(Config):

    # Base settings
    DEBUG = True

    # Security settings
    SECRET_KEY = '2!j5*n=5^u+tlrq^d5c52ww*$*c7qgdv&2d*kv$=37rvh%nio6'

    # Databases
    DATABASES = {
        'default': {
            'ENGINE':
            'django.db.backends.mysql',
            'HOST':
            'localhost',
            'NAME':
            SecretValue(environ_name='REL_NAME', environ_prefix='RHEA'),
            'USER':
            SecretValue(environ_name='REL_USER', environ_prefix='RHEA'),
            'PASSWORD':
            SecretValue(environ_name='REL_PASSWD', environ_prefix='RHEA')
        }
    }

    # Static files
    STATIC_ROOT = join(Config.BASE_DIR, 'static')

    # Logging
    LOGGING = {
        'version': 1,
        'disable_existing_loggers': False,
        'handlers': {
            'file': {
                'level': 'DEBUG',
                'class': 'logging.FileHandler',
                'filename': join(Config.BASE_DIR, 'development.log')
            }
        },
        'loggers': {
            'django': {
                'handlers': ['file'],
                'level': 'DEBUG',
                'propagate': True
            }
        }
    }

    # Email
    EMAIL_BACKEND = 'django.core.mail.backends.filebased.EmailBackend'
    EMAIL_FILE_PATH = join(Config.BASE_DIR, 'emails')
Exemple #4
0
    def test_secret_value(self):
        # no default allowed, only environment values are
        self.assertRaises(ValueError, SecretValue, 'default')

        value = SecretValue()
        self.assertRaises(ValueError, value.setup, 'TEST')
        with env(DJANGO_SECRET_KEY='123'):
            self.assertEqual(value.setup('SECRET_KEY'), '123')

        value = SecretValue(environ_name='FACEBOOK_API_SECRET',
                            environ_prefix=None,
                            late_binding=True)
        self.assertRaises(ValueError, value.setup, 'TEST')
        with env(FACEBOOK_API_SECRET='123'):
            self.assertEqual(value.setup('TEST'), '123')
Exemple #5
0
    def test_secret_value(self):
        self.assertRaises(ValueError, SecretValue, 'default')

        value = SecretValue()
        self.assertRaises(ValueError, value.setup, 'TEST')
        with env(DJANGO_SECRET_KEY='123'):
            self.assertEqual(value.setup('SECRET_KEY'), '123')

        value = SecretValue(environ_name='FACEBOOK_API_SECRET',
                            environ_prefix=None)
        self.assertRaises(ValueError, value.setup, 'TEST')
        with env(FACEBOOK_API_SECRET='123'):
            self.assertEqual(value.setup('TEST'), '123')
Exemple #6
0
    def test_secret_value(self):
        # no default allowed, only environment values are
        self.assertRaises(ValueError, SecretValue, 'default')

        value = SecretValue()
        self.assertRaises(ValueError, value.setup, 'TEST')
        with env(DJANGO_SECRET_KEY='123'):
            self.assertEqual(value.setup('SECRET_KEY'), '123')

        value = SecretValue(environ_name='FACEBOOK_API_SECRET',
                            environ_prefix=None,
                            late_binding=True)
        self.assertRaises(ValueError, value.setup, 'TEST')
        with env(FACEBOOK_API_SECRET='123'):
            self.assertEqual(value.setup('TEST'), '123')
Exemple #7
0
class Base(Configuration):
    SECRET_KEY = SecretValue(environ_prefix=None,
                             environ_required=True,
                             environ_name="SECRET_KEY")

    DEBUG = BooleanValue(environ_prefix=None,
                         environ_name="DEBUG",
                         default=True)

    ALLOWED_HOSTS = ListValue(environ_prefix=None,
                              environ_required=True,
                              environ_name="ALLOWED_HOSTS")

    # Application definition

    INSTALLED_APPS = [
        "django.contrib.admin",
        "django.contrib.auth",
        "django.contrib.contenttypes",
        "django.contrib.sessions",
        "django.contrib.messages",
        "django.contrib.staticfiles",
        "cryptprice",
    ]

    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 = "core.urls"

    TEMPLATES = [
        {
            "BACKEND": "django.template.backends.django.DjangoTemplates",
            "DIRS": [],
            "APP_DIRS": True,
            "OPTIONS": {
                "context_processors": [
                    "django.template.context_processors.debug",
                    "django.template.context_processors.request",
                    "django.contrib.auth.context_processors.auth",
                    "django.contrib.messages.context_processors.messages",
                ],
            },
        },
    ]

    WSGI_APPLICATION = "core.wsgi.application"

    DATABASES = {"default": {}}

    AUTH_PASSWORD_VALIDATORS = [
        {
            "NAME":
            "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
        },
        {
            "NAME":
            "django.contrib.auth.password_validation.MinimumLengthValidator",
        },
        {
            "NAME":
            "django.contrib.auth.password_validation.CommonPasswordValidator",
        },
        {
            "NAME":
            "django.contrib.auth.password_validation.NumericPasswordValidator",
        },
    ]

    LANGUAGE_CODE = "en-us"

    TIME_ZONE = "UTC"

    USE_I18N = True

    USE_L10N = True

    USE_TZ = True

    STATIC_URL = "/static/"

    # ----> SLACK CONFIGURATION <------

    SLACK_BOT_USER_OAUTH_ACCESS_TOKEN = SecretValue(
        environ_prefix=None,
        environ_required=True,
        environ_name="SLACK_BOT_USER_OAUTH_ACCESS_TOKEN",
    )

    SLACK_CLIENT_ID = SecretValue(environ_prefix=None,
                                  environ_required=True,
                                  environ_name="SLACK_CLIENT_ID")

    SLACK_CLIENT_SECRET = SecretValue(environ_prefix=None,
                                      environ_required=True,
                                      environ_name="SLACK_CLIENT_SECRET")

    SLACK_VERIFICATION_TOKEN = SecretValue(
        environ_prefix=None,
        environ_required=True,
        environ_name="SLACK_VERIFICATION_TOKEN",
    )
Exemple #8
0
class Base(Configuration):
    # SECURITY WARNING: keep the secret key used in production secret!
    SECRET_KEY = "=hp0a+m%bzc13e*9x73q%21nm+$drt$6!3fbbbxmhv(6rbp&)z"

    # SECURITY WARNING: don't run with debug turned on in production!
    DEBUG = True

    ALLOWED_HOSTS = []

    # Application definition

    INSTALLED_APPS = [
        "crypto",
        "rest_framework",
        "django.contrib.admin",
        "django.contrib.auth",
        "django.contrib.contenttypes",
        "django.contrib.sessions",
        "django.contrib.messages",
        "django.contrib.staticfiles",
    ]

    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 = "core.urls"

    TEMPLATES = [
        {
            "BACKEND": "django.template.backends.django.DjangoTemplates",
            "DIRS": [],
            "APP_DIRS": True,
            "OPTIONS": {
                "context_processors": [
                    "django.template.context_processors.debug",
                    "django.template.context_processors.request",
                    "django.contrib.auth.context_processors.auth",
                    "django.contrib.messages.context_processors.messages",
                ],
            },
        },
    ]

    WSGI_APPLICATION = "core.wsgi.application"

    # Database
    # https://docs.djangoproject.com/en/3.0/ref/settings/#databases

    DATABASES = {
        "default": {
            "ENGINE": "django.db.backends.sqlite3",
            "NAME": os.path.join(BASE_DIR, "db.sqlite3"),
        }
    }

    # Password validation
    # https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators

    AUTH_PASSWORD_VALIDATORS = [
        {
            "NAME":
            "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
        },
        {
            "NAME":
            "django.contrib.auth.password_validation.MinimumLengthValidator",
        },
        {
            "NAME":
            "django.contrib.auth.password_validation.CommonPasswordValidator",
        },
        {
            "NAME":
            "django.contrib.auth.password_validation.NumericPasswordValidator",
        },
    ]

    # Internationalization
    # https://docs.djangoproject.com/en/3.0/topics/i18n/

    LANGUAGE_CODE = "en-us"

    TIME_ZONE = "UTC"

    USE_I18N = True

    USE_L10N = True

    USE_TZ = True

    # Static files (CSS, JavaScript, Images)
    # https://docs.djangoproject.com/en/3.0/howto/static-files/

    STATIC_URL = "/static/"

    REST_FRAMEWORK = {
        "EXCEPTION_HANDLER":
        "crypto.exceptions.exception_handler.custom_exception_handler"
    }

    # Twitter AUTH Credentials
    TWITTER_CONSUMER_KEY = SecretValue(environ_name="TWITTER_CONSUMER_KEY",
                                       environ_prefix=None)
    TWITTER_CONSUMER_SECRET = SecretValue(
        environ_name="TWITTER_CONSUMER_SECRET", environ_prefix=None)
    TWITTER_ACCESS_TOKEN = SecretValue(environ_name="TWITTER_ACCESS_TOKEN",
                                       environ_prefix=None)
    TWITTER_ACCESS_TOKEN_SECRET = SecretValue(
        environ_name="TWITTER_ACCESS_TOKEN_SECRET", environ_prefix=None)

    NUMBER_OF_TWEETS = 500
class Production(Configuration):
    SECRET_KEY = SecretValue(environ_name="SECRET_KEY",
                             environ_prefix=None,
                             environ_required=True)

    DEBUG = BooleanValue(environ_name="DEBUG",
                         environ_prefix=None,
                         default=False)

    ALLOWED_HOSTS = []

    # Application definition

    INSTALLED_APPS = [
        "django.contrib.auth", "django.contrib.contenttypes",
        "django.contrib.messages", "django.contrib.staticfiles",
        "rest_framework", "inistock", "corsheaders"
    ]

    MIDDLEWARE = [
        "corsheaders.middleware.CorsMiddleware",
        "django.middleware.security.SecurityMiddleware",
        "django.middleware.common.CommonMiddleware",
        "django.contrib.sessions.middleware.SessionMiddleware",
        "django.contrib.auth.middleware.AuthenticationMiddleware",
        "django.contrib.messages.middleware.MessageMiddleware",
        "django.middleware.clickjacking.XFrameOptionsMiddleware",
    ]

    ROOT_URLCONF = "core.urls"

    TEMPLATES = [
        {
            "BACKEND": "django.template.backends.django.DjangoTemplates",
            "DIRS": [],
            "APP_DIRS": True,
            "OPTIONS": {
                "context_processors": [
                    "django.template.context_processors.debug",
                    "django.template.context_processors.request",
                    "django.contrib.auth.context_processors.auth",
                    "django.contrib.messages.context_processors.messages",
                ],
            },
        },
    ]

    WSGI_APPLICATION = "core.wsgi.application"

    DATABASES = {
        "default": {
            "ENGINE":
            "django.db.backends.postgresql_psycopg2",
            "NAME":
            SecretValue(
                environ_name="POSTGRES_DB_NAME",
                environ_prefix=None,
                environ_required=True,
            ),
            "USER":
            SecretValue(
                environ_name="POSTGRES_DB_USERNAME",
                environ_prefix=None,
                environ_required=True,
            ),
            "PASSWORD":
            SecretValue(
                environ_name="POSTGRES_DB_PASSWORD",
                environ_prefix=None,
                environ_required=True,
            ),
            "HOST":
            SecretValue(environ_name="POSTGRES_HOST",
                        environ_prefix=None,
                        environ_required=True),
            "PORT":
            SecretValue(environ_name="POSTGRES_PORT",
                        environ_prefix=None,
                        environ_required=True),
        }
    }

    AUTH_PASSWORD_VALIDATORS = [
        {
            "NAME":
            "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
        },
        {
            "NAME":
            "django.contrib.auth.password_validation.MinimumLengthValidator",
        },
        {
            "NAME":
            "django.contrib.auth.password_validation.CommonPasswordValidator",
        },
        {
            "NAME":
            "django.contrib.auth.password_validation.NumericPasswordValidator",
        },
    ]

    REST_FRAMEWORK = {
        "EXCEPTION_HANDLER":
        "inistock.exceptions.exception_handler.custom_exception_handler"
    }

    LANGUAGE_CODE = "en-us"

    TIME_ZONE = "UTC"

    USE_I18N = True

    USE_L10N = True

    USE_TZ = True

    STATIC_URL = "/static/"

    CORS_ORIGIN_ALLOW_ALL = True
    CORS_ALLOW_CREDENTIALS = True

    CORS_ALLOW_HEADERS = [
        'accept', 'accept-encoding', 'authorization', 'content-type', 'dnt',
        'origin', "person-id"
    ]