From 10744209ced9b76eddcd3911a47a187474549813 Mon Sep 17 00:00:00 2001 From: RafaUC Date: Wed, 17 Jul 2024 10:00:08 -0600 Subject: [PATCH 1/2] Implementado el uso de variables de entorno --- cosiap_api/cosiap_api/settings.py | 38 ++++++++++++++++--------------- cosiap_api/requirements.txt | 1 + 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/cosiap_api/cosiap_api/settings.py b/cosiap_api/cosiap_api/settings.py index ac1f99c..f3b8a9c 100644 --- a/cosiap_api/cosiap_api/settings.py +++ b/cosiap_api/cosiap_api/settings.py @@ -12,20 +12,24 @@ https://docs.djangoproject.com/en/5.0/ref/settings/ import os from datetime import timedelta +import environ +# Initialise environment variables +env = environ.Env() +environ.Env.read_env() # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -BASE_URL = 'http://localhost:8000/' # Cambiar esto por la URL base de la aplicación en producción +BASE_URL = env('BASE_URL') # Cambiar esto por la URL base de la aplicación en producción # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'django-insecure-*8(5essozyzi_b&fz((8j5xxpjra!$_jj$5=q=7ic3tw&x^sa8' +SECRET_KEY = env('SECRET_KEY') # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = env('DEBUG') ALLOWED_HOSTS = [] @@ -94,11 +98,11 @@ WSGI_APPLICATION = 'cosiap_api.wsgi.application' DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', - 'NAME': 'db-cosiap', - 'USER': 'root', - 'PASSWORD': 'cosiap_root_password', - 'HOST': 'db-cosiap', - 'PORT': '3306', + 'NAME': env('DATABASES_DEFAULT_NAME'), + 'USER': env('DATABASES_DEFAULT_USER'), + 'PASSWORD': env('DATABASES_DEFAULT_PASSWORD'), + 'HOST': env('DATABASES_DEFAULT_HOST'), + 'PORT': env('DATABASES_DEFAULT_PORT') } } @@ -137,12 +141,12 @@ USE_TZ = True #Email settings EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' -EMAIL_HOST = 'smtp.gmail.com' -EMAIL_FROM = '35164744@uaz.edu.mx' -EMAIL_HOST_USER = '35164744@uaz.edu.mx' -EMAIL_HOST_PASSWORD = 'adekkdajdqkuqxcb' -EMAIL_PORT = 587 -EMAIL_USE_TLS = True +EMAIL_HOST = env('EMAIL_HOST') +EMAIL_FROM = env('EMAIL_FROM') +EMAIL_HOST_USER = env('EMAIL_HOST_USER') +EMAIL_HOST_PASSWORD = env('EMAIL_HOST_PASSWORD') +EMAIL_PORT = env('EMAIL_PORT') +EMAIL_USE_TLS = env('EMAIL_USE_TLS') # Static files (CSS, JavaScript, Images) @@ -170,7 +174,7 @@ CHANNEL_LAYERS = { "default": { "BACKEND": "channels_redis.core.RedisChannelLayer", "CONFIG": { - "hosts": [('redis-cosiap', 6379)], + "hosts": env('CHANNEL_LAYERS_CONFIG_HOSTS'), }, }, } @@ -218,6 +222,4 @@ SPECTACULAR_SETTINGS = { } CORS_ALLOW_CREDENTIALS = True -CORS_ALLOWED_ORIGINS = [ - "http://localhost:5173" -] +CORS_ALLOWED_ORIGINS = [origin.strip() for origin in env("CORS_ALLOWED_ORIGINS").split(",")] diff --git a/cosiap_api/requirements.txt b/cosiap_api/requirements.txt index daf3087..9665704 100644 --- a/cosiap_api/requirements.txt +++ b/cosiap_api/requirements.txt @@ -7,6 +7,7 @@ pillow>=10.3.0,<10.4.0 django-filter>=24.2,<24.3 django-model-utils>=4.5.1,<4.6.0 mysqlclient>=2.2.4,<2.3.0 +django-environ>=0.11.2,<0.12.0 django-crontab>=0.7.1,<0.8.0 -- GitLab From 90718e753cad7acd1b9ddee87d053cf4ba84816e Mon Sep 17 00:00:00 2001 From: RafaUC Date: Wed, 17 Jul 2024 16:07:05 +0000 Subject: [PATCH 2/2] Upload New File --- cosiap_api/cosiap_api/.env | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 cosiap_api/cosiap_api/.env diff --git a/cosiap_api/cosiap_api/.env b/cosiap_api/cosiap_api/.env new file mode 100644 index 0000000..b5782c3 --- /dev/null +++ b/cosiap_api/cosiap_api/.env @@ -0,0 +1,21 @@ +DEBUG=True +SECRET_KEY="django-insecure-*8(5essozyzi_b&fz((8j5xxpjra!$_jj$=ic3tw&x^sa8" + +BASE_URL="http://localhost:8000/" + +DATABASES_DEFAULT_NAME="db-cosiap" +DATABASES_DEFAULT_USER="root" +DATABASES_DEFAULT_PASSWORD="cosiap_root_password" +DATABASES_DEFAULT_HOST="db-cosiap" +DATABASES_DEFAULT_PORT="3306" + +EMAIL_HOST="sandbox.smtp.mailtrap.io" +EMAIL_FROM="cosiap@example.com" +EMAIL_HOST_USER="2456f598d9da38" +EMAIL_HOST_PASSWORD="2c2051e768ff8c" +EMAIL_PORT="2525" +EMAIL_USE_TLS=True + +CORS_ALLOWED_ORIGINS="http://localhost:5173" + +CHANNEL_LAYERS_CONFIG_HOSTS="[('redis-cosiap', 6379)]" \ No newline at end of file -- GitLab