From 20f20c180bd92d0e734a2b1063edf097d7863df9 Mon Sep 17 00:00:00 2001 From: Celestino Rey Date: Mon, 4 Nov 2024 20:34:24 +0000 Subject: [PATCH] url para visualizar variables de entorno y de settings --- JugarAlPadel/K8S/Makefile.local | 2 +- .../K8S/env-prod-configmap-local.yaml | 2 +- JugarAlPadel/gestion_reservas/eventos/urls.py | 3 -- .../gestion_reservas/eventos/views.py | 21 +------------ .../gestion_reservas/gestion_reservas/urls.py | 4 +++ .../gestion_reservas/views.py | 31 +++++++++++++++++++ 6 files changed, 38 insertions(+), 25 deletions(-) create mode 100644 JugarAlPadel/gestion_reservas/gestion_reservas/views.py diff --git a/JugarAlPadel/K8S/Makefile.local b/JugarAlPadel/K8S/Makefile.local index 4d095a7..3e7af09 100644 --- a/JugarAlPadel/K8S/Makefile.local +++ b/JugarAlPadel/K8S/Makefile.local @@ -2,7 +2,7 @@ export ARQUITECTURA := $(shell lscpu |grep itectur | tr -d ' '| cut -f2 -d':') export REGISTRY=localhost:30500 #export REGISTRY=registry.reymota.es -export IMG_VERSION = 0.95 +export IMG_VERSION = 0.98 export IMG_NGINX_VERSION = 2.4 # limpia todo diff --git a/JugarAlPadel/K8S/env-prod-configmap-local.yaml b/JugarAlPadel/K8S/env-prod-configmap-local.yaml index bda857f..065ab18 100644 --- a/JugarAlPadel/K8S/env-prod-configmap-local.yaml +++ b/JugarAlPadel/K8S/env-prod-configmap-local.yaml @@ -1,6 +1,6 @@ apiVersion: v1 data: - DEBUG: "False" + DEBUG: "True" ENTORNO: "Pruebas" DJANGO_ALLOWED_HOSTS: "jugaralpadel.ddns.net vmcluster reymota.es k8s-server localhost 127.0.0.1 [::1]" CSRF_TRUSTED_ORIGINS: "https://jugaralpadel.ddns.net http://vmcluster" diff --git a/JugarAlPadel/gestion_reservas/eventos/urls.py b/JugarAlPadel/gestion_reservas/eventos/urls.py index bccf950..0d6fa22 100644 --- a/JugarAlPadel/gestion_reservas/eventos/urls.py +++ b/JugarAlPadel/gestion_reservas/eventos/urls.py @@ -15,7 +15,4 @@ urlpatterns = [ path('reservar//', views.reservar_evento, name='reservar_evento'), - - path('entorno/', views.ver_variables_entorno, name='ver_variables_entorno'), - ] diff --git a/JugarAlPadel/gestion_reservas/eventos/views.py b/JugarAlPadel/gestion_reservas/eventos/views.py index 932c578..6195300 100644 --- a/JugarAlPadel/gestion_reservas/eventos/views.py +++ b/JugarAlPadel/gestion_reservas/eventos/views.py @@ -1,33 +1,14 @@ -import os from django.shortcuts import render, get_object_or_404, redirect from django.contrib.auth.decorators import login_required, user_passes_test from django.contrib import messages from django.core.mail import EmailMultiAlternatives from django.conf import settings from django.template.loader import render_to_string -from django.http import HttpResponseForbidden -from .models import Evento, Reserva, ListaEspera, ReyMotaUser +from .models import Evento, Reserva, ListaEspera from .forms import ListaEsperaForm, EventoForm -@user_passes_test(lambda u: u.is_staff) -def ver_variables_entorno(request): - # Obtiene todas las variables de entorno - entorno = {key: os.getenv(key) for key in os.environ.keys()} - - # Obtiene todas las variables de settings que no son métodos - configuracion = {key: getattr(settings, key) for key in dir(settings) if key.isupper()} - - # Combina ambas en un solo diccionario - contexto = { - 'entorno': entorno, - 'configuracion': configuracion - } - - return render(request, 'ver_entorno.html', contexto) - - @login_required def reservar_evento(request, evento_id): evento = get_object_or_404(Evento, id=evento_id) diff --git a/JugarAlPadel/gestion_reservas/gestion_reservas/urls.py b/JugarAlPadel/gestion_reservas/gestion_reservas/urls.py index 17022c0..b4bdd22 100644 --- a/JugarAlPadel/gestion_reservas/gestion_reservas/urls.py +++ b/JugarAlPadel/gestion_reservas/gestion_reservas/urls.py @@ -20,6 +20,8 @@ from django.conf.urls.static import static from django.conf import settings from django.views.generic.base import TemplateView # new +from . import views + urlpatterns = [ path('obreros/', admin.site.urls), @@ -31,5 +33,7 @@ urlpatterns = [ path("", TemplateView.as_view(template_name="index.html"), name="principal"), # new + path('entorno/', views.ver_variables_entorno, name='ver_variables_entorno'), + ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/JugarAlPadel/gestion_reservas/gestion_reservas/views.py b/JugarAlPadel/gestion_reservas/gestion_reservas/views.py new file mode 100644 index 0000000..621798e --- /dev/null +++ b/JugarAlPadel/gestion_reservas/gestion_reservas/views.py @@ -0,0 +1,31 @@ +import os +from django.conf import settings +from django.contrib.auth.decorators import user_passes_test +from django.shortcuts import render +from django.http import HttpResponseForbidden + + +@user_passes_test(lambda u: u.is_staff) +def ver_variables_entorno(request): + if not settings.DEBUG: + return HttpResponseForbidden("Acceso prohibido") + + # Variables a excluir por motivos de seguridad + variables_excluidas = {'SECRET_KEY', 'DATABASES', 'EMAIL_HOST_PASSWORD', 'API_KEY'} + + # Obtiene todas las variables de entorno + entorno = {key: os.getenv(key) for key in os.environ.keys() if key not in variables_excluidas} + + # Obtiene todas las variables de settings excluyendo las confidenciales + configuracion = { + key: getattr(settings, key) for key in dir(settings) + if key.isupper() and key not in variables_excluidas + } + + # Combina ambas en un solo diccionario + contexto = { + 'entorno': entorno, + 'configuracion': configuracion + } + + return render(request, 'ver_entorno.html', contexto)