Browse Source

url para visualizar variables de entorno y de settings

politica
Celestino Rey 1 year ago
parent
commit
20f20c180b
6 changed files with 38 additions and 25 deletions
  1. +1
    -1
      JugarAlPadel/K8S/Makefile.local
  2. +1
    -1
      JugarAlPadel/K8S/env-prod-configmap-local.yaml
  3. +0
    -3
      JugarAlPadel/gestion_reservas/eventos/urls.py
  4. +1
    -20
      JugarAlPadel/gestion_reservas/eventos/views.py
  5. +4
    -0
      JugarAlPadel/gestion_reservas/gestion_reservas/urls.py
  6. +31
    -0
      JugarAlPadel/gestion_reservas/gestion_reservas/views.py

+ 1
- 1
JugarAlPadel/K8S/Makefile.local View File

@ -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


+ 1
- 1
JugarAlPadel/K8S/env-prod-configmap-local.yaml View File

@ -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"


+ 0
- 3
JugarAlPadel/gestion_reservas/eventos/urls.py View File

@ -15,7 +15,4 @@ urlpatterns = [
path('reservar/<int:evento_id>/',
views.reservar_evento, name='reservar_evento'),
path('entorno/', views.ver_variables_entorno, name='ver_variables_entorno'),
]

+ 1
- 20
JugarAlPadel/gestion_reservas/eventos/views.py View File

@ -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)


+ 4
- 0
JugarAlPadel/gestion_reservas/gestion_reservas/urls.py View File

@ -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)

+ 31
- 0
JugarAlPadel/gestion_reservas/gestion_reservas/views.py View File

@ -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)

Loading…
Cancel
Save