This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
from .celery_settings import app as celery_app
|
||||
|
||||
__all__ = ("celery_app",)
|
||||
@@ -0,0 +1,16 @@
|
||||
"""
|
||||
ASGI config for django_code project.
|
||||
|
||||
It exposes the ASGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings')
|
||||
|
||||
application = get_asgi_application()
|
||||
@@ -0,0 +1,8 @@
|
||||
import os
|
||||
from celery import Celery
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings')
|
||||
|
||||
app = Celery("core")
|
||||
app.config_from_object("django.conf:settings", namespace="CELERY")
|
||||
app.autodiscover_tasks()
|
||||
@@ -0,0 +1,7 @@
|
||||
from django.conf import settings
|
||||
from django_hosts import patterns, host
|
||||
|
||||
host_patterns = patterns('',
|
||||
host(r"django-testing", settings.ROOT_URLCONF, name="django-testing"),
|
||||
host(r"redirect", 'apps.website_redirection.urls', name="redirect"),
|
||||
)
|
||||
@@ -0,0 +1,46 @@
|
||||
# routers.py
|
||||
|
||||
class ProjectDatabaseRouter:
|
||||
"""
|
||||
A router to control all database operations on models in the
|
||||
simpsons and cloudmanager applications.
|
||||
"""
|
||||
|
||||
def db_for_read(self, model, **hints):
|
||||
"""Attempts to read simpsons and cloudmanager models go to their specific dbs."""
|
||||
if model._meta.app_label == 'simpsons':
|
||||
return 'simpsons_db'
|
||||
if model._meta.app_label == 'cloudmanager':
|
||||
return 'cloudmanager_db'
|
||||
return 'default'
|
||||
|
||||
def db_for_write(self, model, **hints):
|
||||
"""Attempts to write simpsons and cloudmanager models go to their specific dbs."""
|
||||
if model._meta.app_label == 'simpsons':
|
||||
return 'simpsons_db'
|
||||
if model._meta.app_label == 'cloudmanager':
|
||||
return 'cloudmanager_db'
|
||||
return 'default'
|
||||
|
||||
def allow_relation(self, obj1, obj2, **hints):
|
||||
"""Allow relations if both models are in the same database."""
|
||||
# Prevents accidental foreign key relationships across different physical DBs
|
||||
if (
|
||||
obj1._meta.app_label in ['simpsons', 'cloudmanager'] or
|
||||
obj2._meta.app_label in ['simpsons', 'cloudmanager']
|
||||
):
|
||||
return obj1._meta.app_label == obj2._meta.app_label
|
||||
return None
|
||||
|
||||
def allow_migrate(self, db, app_label, model_name=None, **hints):
|
||||
"""Ensure the app's models only show up in the designated database."""
|
||||
if app_label == 'simpsons':
|
||||
return db == 'simpsons_db'
|
||||
if app_label == 'cloudmanager':
|
||||
return db == 'cloudmanager_db'
|
||||
|
||||
# Ensure default Django apps (auth, sessions, etc.) don't migrate into simpsons/cloudmanager
|
||||
if db in ['simpsons_db', 'cloudmanager_db']:
|
||||
return False
|
||||
|
||||
return None
|
||||
@@ -0,0 +1,179 @@
|
||||
"""
|
||||
Django settings for django_code project.
|
||||
|
||||
Generated by 'django-admin startproject' using Django 4.2.5.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.2/topics/settings/
|
||||
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/4.2/ref/settings/
|
||||
"""
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = 'django-insecure-71%)_#e#o9-dl2o^6mfud-*rw+4+8vy-nd*bzeier&(34ap-p9'
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
#DEBUG = os.getenv("DEBUG")
|
||||
DEBUG = os.getenv("DEBUG", "False").lower() in ("true", "1", "t")
|
||||
|
||||
|
||||
ALLOWED_HOSTS = os.getenv("ALLOWED_HOSTS").split(",")
|
||||
CSRF_TRUSTED_ORIGINS=[]
|
||||
for ALLOWED_HOST in os.getenv("ALLOWED_HOSTS").split(","):
|
||||
CSRF_TRUSTED_ORIGINS.append("https://"+str(ALLOWED_HOST))
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'bootstrap5',
|
||||
'django_hosts',
|
||||
'apps.cloudmanager.apps.CloudmanagerConfig',
|
||||
'apps.random_simpsons.apps.RandomSimpsonsConfig',
|
||||
'import_export',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django_hosts.middleware.HostsRequestMiddleware',
|
||||
'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',
|
||||
'django_hosts.middleware.HostsResponseMiddleware',
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'core.urls'
|
||||
ROOT_HOSTCONF = 'core.hosts'
|
||||
DEFAULT_HOST = 'django-testing'
|
||||
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
#'DIRS': ["/code/core/templates","/code/core/dashboard/templates/"],
|
||||
'DIRS': [
|
||||
BASE_DIR / "templates"
|
||||
],
|
||||
'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/4.2/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.postgresql',
|
||||
'NAME': 'django',
|
||||
'USER': os.environ.get('DB_USERNAME'),
|
||||
'PASSWORD': os.environ.get('DB_PASSWORD'),
|
||||
'HOST': os.environ.get('DB_HOST'),
|
||||
'PORT': os.environ.get('DB_PORT'),
|
||||
},
|
||||
'cloudmanager_db': {
|
||||
'ENGINE': 'django.db.backends.postgresql',
|
||||
'NAME': 'cloudmanager',
|
||||
'USER': os.environ.get('DB_USERNAME'),
|
||||
'PASSWORD': os.environ.get('DB_PASSWORD'),
|
||||
'HOST': os.environ.get('DB_HOST'),
|
||||
'PORT': os.environ.get('DB_PORT'),
|
||||
},
|
||||
'simpsons_db': {
|
||||
'ENGINE': 'django.db.backends.postgresql',
|
||||
'NAME': 'simpsons',
|
||||
'USER': os.environ.get('DB_USERNAME'),
|
||||
'PASSWORD': os.environ.get('DB_PASSWORD'),
|
||||
'HOST': os.environ.get('DB_HOST'),
|
||||
'PORT': os.environ.get('DB_PORT'),
|
||||
},
|
||||
}
|
||||
DATABASE_ROUTERS = ['core.routers.ProjectDatabaseRouter']
|
||||
#DATABASE_ROUTERS = []
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/4.2/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/4.2/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
|
||||
TIME_ZONE = 'UTC'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/4.2/howto/static-files/
|
||||
|
||||
STATIC_URL = '/static/'
|
||||
|
||||
STATICFILES_DIRS = [
|
||||
BASE_DIR / "templates/cloudmanager/css",
|
||||
BASE_DIR / "templates/cloudmanager/fonts",
|
||||
BASE_DIR / "templates/cloudmanager/images",
|
||||
BASE_DIR / "templates/cloudmanager/js"
|
||||
]
|
||||
|
||||
STATIC_ROOT = BASE_DIR / "templates/static"
|
||||
|
||||
# Default primary key field type
|
||||
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||
#
|
||||
# Celery settings
|
||||
CELERY_BROKER_URL = "redis://django-redis-svc:6379"
|
||||
CELERY_RESULT_BACKEND = "redis://django-redis-svc:6379"
|
||||
|
||||
CELERY_IMPORTS = [
|
||||
'apps.stash_management.apps', # This line imports the tasks.py file
|
||||
# Add other app tasks here if needed
|
||||
]
|
||||
@@ -0,0 +1,92 @@
|
||||
"""
|
||||
URL configuration for django_code project.
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/4.2/topics/http/urls/
|
||||
Examples:
|
||||
Function views
|
||||
1. Add an import: from my_app import views
|
||||
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||
Class-based views
|
||||
1. Add an import: from other_app.views import Home
|
||||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||
Including another URLconf
|
||||
1. Import the include() function: from django.urls import include, path
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.contrib import admin
|
||||
from django.urls import path
|
||||
#from apps.cloudmanager import (credentials,db_interaction)
|
||||
from apps.cloudmanager import apps as cloudmanager_apps
|
||||
from apps.cloudmanager import views as cloudmanager_views
|
||||
from apps.random_simpsons import views as random_simpsons
|
||||
from apps.dashboard import apps as dashboardapp
|
||||
from apps.dashboard import views as dashboardview
|
||||
from apps.kubernetes_connection import apps as kubernetes_connection
|
||||
from apps.stash_management import apps as stashapp
|
||||
from apps.stash_management import views as stashview
|
||||
from apps.website_redirection import apps as website_redirectionapp
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
|
||||
################### Simpsons ###################
|
||||
path('hello/', random_simpsons.hello),
|
||||
path('simpsons/', random_simpsons.episode_generator),
|
||||
path('download_file/', random_simpsons.download_file),
|
||||
|
||||
################### Redirect ###################
|
||||
path('redirect/hello/', website_redirectionapp.hello),
|
||||
path('redirect/set/', website_redirectionapp.redirect),
|
||||
path('redirect/get/<str:key>', website_redirectionapp.display_key),
|
||||
path('redirect/go/<str:key>', website_redirectionapp.redirect_to_key),
|
||||
path('redirect/redirect-form/', website_redirectionapp.redirect_process, name='submit_form'),
|
||||
path('redirect/clearkey/', website_redirectionapp.clearkey_process, name='submit_form'),
|
||||
|
||||
################### onenote ###################
|
||||
path('dashboard/hello/', dashboardapp.hello),
|
||||
path('dashboard/view/about', dashboardview.about),
|
||||
path('dashboard/view/home', dashboardview.home),
|
||||
path('dashboard/view/success', dashboardview.success),
|
||||
path('dashboard/scale_up/<str:namespace_name>/<str:deploy_name>', dashboardview.scale_up),
|
||||
path('dashboard/scale_down/<str:namespace_name>/<str:deploy_name>', dashboardview.scale_down),
|
||||
|
||||
|
||||
|
||||
################## kubernetes_connection#####
|
||||
path('kubernetes_connection/hello/', kubernetes_connection.hello),
|
||||
path('kubernetes_connection/nodes/', kubernetes_connection.nodes),
|
||||
path('kubernetes_connection/backup_job/', kubernetes_connection.backup_job),
|
||||
path('kubernetes_connection/backup_job_yaml/', kubernetes_connection.backup_job_yaml),
|
||||
path('kubernetes_connection/scale_up/<str:namespace_name>/<str:deploy_name>', kubernetes_connection.scale_up),
|
||||
path('kubernetes_connection/scale_down/<str:namespace_name>/<str:deploy_name>', kubernetes_connection.scale_down),
|
||||
|
||||
################## stash#####
|
||||
path('stash/', stashview.home),
|
||||
path('stash/hello/', stashapp.hello),
|
||||
path('stash/form/', stashapp.form),
|
||||
path('stash/incremental/', stashapp.incremental),
|
||||
path('stash/album/', stashapp.album),
|
||||
path('stash/album-form/', stashapp.album_form, name='submit_form'),
|
||||
path('stash/simple/', stashapp.simple),
|
||||
path('stash/simple-form/', stashapp.simple_form, name='submit_form'),
|
||||
path('stash/submit-form/', stashapp.handle_survey_form, name='submit_form'),
|
||||
path('stash/incremental-form/', stashapp.incremental_form, name='submit_form'),
|
||||
|
||||
# path('bookstack/', docker_connection.apps.hello),
|
||||
# path('test/', docker_connection.apps.http_call_test),
|
||||
# path('proxmox/', docker_connection.apps.proxmox),
|
||||
# path('simpsons/', random_simpsons.hello),
|
||||
# path('docker/<str:action>/<str:id_docker>', docker_connection.apps.docker_call),
|
||||
|
||||
################### cloudmanager ###################
|
||||
path('cmm/', cloudmanager_apps.redirect),
|
||||
path('cmm/hello', cloudmanager_apps.hello, name='hello'),
|
||||
path('cmm/coucou', cloudmanager_views.coucou, name='coucou'),
|
||||
path('cmm/display', cloudmanager_views.display, name='display'),
|
||||
#path('cmm/run-action/', cloudmanager_views.trigger_my_action, name='run_my_action_url'),
|
||||
#path('change-schedule/', cloudmanager_views.change_schedule, name='change_schedule'),
|
||||
#path('cmm/main/', db_interaction.main),
|
||||
|
||||
]
|
||||
@@ -0,0 +1,23 @@
|
||||
"""
|
||||
WSGI config for django_code project.
|
||||
|
||||
It exposes the WSGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings')
|
||||
|
||||
application = get_wsgi_application()
|
||||
https_proxy = "gluetun-svc.gluetun.svc:8888"
|
||||
|
||||
proxyDict = {
|
||||
"https" : https_proxy,
|
||||
}
|
||||
|
||||
#os.environ["PROXIES"] = proxyDict
|
||||
Reference in New Issue
Block a user