env variables handling
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 4s
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 4s
This commit is contained in:
parent
fa3e637ab1
commit
3667626eb2
@ -1,19 +1,36 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
|
|
||||||
import os, environ
|
import os
|
||||||
|
import environ
|
||||||
|
import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
VERSION = "0.1.1"
|
VERSION = "0.1.1"
|
||||||
|
|
||||||
# BASE_DIR is the root of the project, all paths should be constructed from it using pathlib
|
# BASE_DIR is the root of the project, all paths should be constructed from it using pathlib
|
||||||
BASE_DIR = Path(__file__).parent.parent
|
BASE_DIR = Path(__file__).parent.parent
|
||||||
|
|
||||||
# Create an environment and read variables from .env file
|
# Create an environment and read variables from .env file
|
||||||
env = environ.Env(DEBUG=(bool, True))
|
env = environ.Env(
|
||||||
|
DEBUG=(bool, True),
|
||||||
|
BOT_TOKEN=(str, None),
|
||||||
|
|
||||||
|
)
|
||||||
environ.Env.read_env(BASE_DIR / ".env")
|
environ.Env.read_env(BASE_DIR / ".env")
|
||||||
|
|
||||||
|
required_env_vars = (
|
||||||
|
"BOT_TOKEN", "DISCORD_KEY", "DISCORD_SECRET", "DISCORD_REDIRECT_URL", "DISCORD_API_URL",
|
||||||
|
"DISCORD_OAUTH2_URL", "SUPERUSER_IDS"
|
||||||
|
)
|
||||||
|
|
||||||
|
for var in required_env_vars:
|
||||||
|
if not env(var, default=None):
|
||||||
|
log.warn("Required environment variable %s is not set, the application will fail!", var)
|
||||||
|
|
||||||
# SECURITY WARNING: This is sensitive data, keep secure!
|
# SECURITY WARNING: This is sensitive data, keep secure!
|
||||||
SECRET_KEY = env('SECRET_KEY', default="unsecure-default-secret-key")
|
SECRET_KEY = env('SECRET_KEY', default="unsecure-default-secret-key")
|
||||||
|
|
||||||
@ -107,18 +124,10 @@ else:
|
|||||||
# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators
|
# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators
|
||||||
|
|
||||||
AUTH_PASSWORD_VALIDATORS = [
|
AUTH_PASSWORD_VALIDATORS = [
|
||||||
{
|
{ "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator" },
|
||||||
'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" }
|
||||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
|
||||||
},
|
|
||||||
]
|
]
|
||||||
|
|
||||||
AUTHENTICATION_BACKENDS = [
|
AUTHENTICATION_BACKENDS = [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user