diff options
Diffstat (limited to 'src/laas_dashboard')
-rw-r--r-- | src/laas_dashboard/__init__.py | 13 | ||||
-rw-r--r-- | src/laas_dashboard/celery.py | 31 | ||||
-rw-r--r-- | src/laas_dashboard/model_test.py | 110 | ||||
-rw-r--r-- | src/laas_dashboard/settings.py | 254 | ||||
-rw-r--r-- | src/laas_dashboard/urls.py | 49 | ||||
-rw-r--r-- | src/laas_dashboard/wsgi.py | 26 |
6 files changed, 0 insertions, 483 deletions
diff --git a/src/laas_dashboard/__init__.py b/src/laas_dashboard/__init__.py deleted file mode 100644 index f104c4d..0000000 --- a/src/laas_dashboard/__init__.py +++ /dev/null @@ -1,13 +0,0 @@ -############################################################################## -# Copyright (c) 2016 Max Breitenfeldt and others. -# -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################## - - -# This will make sure the app is always imported when -# Django starts so that shared_task will use this app. -from .celery import app as celery_app # noqa diff --git a/src/laas_dashboard/celery.py b/src/laas_dashboard/celery.py deleted file mode 100644 index 362bbdb..0000000 --- a/src/laas_dashboard/celery.py +++ /dev/null @@ -1,31 +0,0 @@ -############################################################################## -# Copyright (c) 2016 Max Breitenfeldt and others. -# -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################## - - -import os - -from celery import Celery - -# set the default Django settings module for the 'celery' program. -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'laas_dashboard.settings') - -from django.conf import settings # noqa - -app = Celery('laas_dashboard') - -# Using a string here means the worker will not have to -# pickle the object when using Windows. -app.config_from_object('django.conf:settings') -app.autodiscover_tasks(lambda: settings.INSTALLED_APPS) -app.config_from_object('django.conf:settings', namespace='CELERY') - - -@app.task(bind=True) -def debug_task(self): - print('Request: {0!r}'.format(self.request)) diff --git a/src/laas_dashboard/model_test.py b/src/laas_dashboard/model_test.py deleted file mode 100644 index ba3ef35..0000000 --- a/src/laas_dashboard/model_test.py +++ /dev/null @@ -1,110 +0,0 @@ -############################################################################## -# Copyright (c) 2020 Sawyer Bergeron, Parker Berberian, Sean Smith, and others. -# -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################## - - -from resource_inventory.models import ( - ResourceProfile, - ResourceQuery, - Image, - DiskProfile, - CpuProfile, - RamProfile, - InterfaceProfile, -) - - -def rp_has_all_components(): - """ - Check that every ResourceProfile has an InterfaceProfile, - DiskProfile, CpuProfile, and RamProfile. - """ - - result = True - - for rp in ResourceProfile.objects.all(): - ip = InterfaceProfile.objects.filter(host=rp).exists() - dp = DiskProfile.objects.filter(host=rp).exists() - cp = CpuProfile.objects.filter(host=rp).exists() - ram = RamProfile.objects.filter(host=rp).exists() - - if not ip: - print("No InterfaceProfiles for host", rp.name) - result = False - - if not dp: - print("No DiskProfile for host", rp.name) - result = False - - if not cp: - print("No CpuProfile for host", rp.name) - result = False - - if not ram: - print("No RamProfile for host", rp.name) - result = False - - return result - - -def ip_for_all_ifaces(): - """ - Check that every InterfaceProfile for a Resource has - an Interface. - """ - - result = True - - for res in ResourceQuery.filter(): - iface_set = res.get_interfaces() - iface_profile_set = InterfaceProfile.objects.filter(host=res.profile) - - # find out what profiles we have - curr_profiles = [iface.profile for iface in iface_set] - missing_profiles = set(iface_profile_set) - set(curr_profiles) - - if missing_profiles: - print('No interface for profiles', missing_profiles, 'for host', res.name) - result = False - - return result - - -def rp_has_image(): - """ - Make sure every ResourceProfile has an Image. - """ - - result = True - - rp_set = ResourceProfile.objects.all() - image_set = Image.objects.all() - image_profiles = set([image.host_type for image in image_set]) - - for rp in rp_set: - if rp not in image_profiles: - print("ResourceProfile", rp.name, "has no image associated with it.") - result = False - return result - - -def run_test(test): - print('RUNNING TEST', test) - result = test() - if result: - print(test, 'WAS A SUCCESS!') - else: - print(test, 'FAILED') - print('============================================') - - -def run_tests(): - tests = [rp_has_all_components, ip_for_all_ifaces, rp_has_image] - - for test in tests: - run_test(test) diff --git a/src/laas_dashboard/settings.py b/src/laas_dashboard/settings.py deleted file mode 100644 index 7e27c8d..0000000 --- a/src/laas_dashboard/settings.py +++ /dev/null @@ -1,254 +0,0 @@ -############################################################################## -# Copyright (c) 2018 Sawyer Bergeron and others. -# -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################## -import os -from datetime import timedelta - -# Build paths inside the project like this: os.path.join(BASE_DIR, ...) -BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - -# SECURITY WARNING: don't run with debug turned on in production! -# NOTE: os.environ only returns strings, so making a comparison to -# 'True' here will convert it to the correct Boolean value. -DEBUG = os.environ.get('DEBUG') == 'True' -TESTING = os.environ.get('TEST') == 'True' - -# Application definition - -INSTALLED_APPS = [ - 'dashboard', - 'resource_inventory', - 'booking', - 'account', - 'notifier', - 'workflow', - 'api', - 'analytics', - 'django.contrib.admin', - 'django.contrib.auth', - 'mozilla_django_oidc', # needs to be defined after auth - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.messages', - 'django.contrib.staticfiles', - 'django.contrib.humanize', - 'bootstrap4', - 'rest_framework', - 'rest_framework.authtoken', -] - -MIDDLEWARE = [ - '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', - 'account.middleware.TimezoneMiddleware', -] - - -# AUTHENTICATION_BACKENDS = ['django.contrib.auth.backends.ModelBackend', 'account.views.MyOIDCAB'] -AUTHENTICATION_BACKENDS = ['django.contrib.auth.backends.ModelBackend'] - -AUTH_SETTING = os.environ.get('AUTH_SETTING') - -if AUTH_SETTING == 'LFID': - # OpenID Authentications - AUTHENTICATION_BACKENDS.append('account.views.MyOIDCAB') - OIDC_RP_CLIENT_ID = os.environ.get('OIDC_CLIENT_ID') - OIDC_RP_CLIENT_SECRET = os.environ.get('OIDC_CLIENT_SECRET') - - OIDC_OP_AUTHORIZATION_ENDPOINT = os.environ.get('OIDC_AUTHORIZATION_ENDPOINT') - OIDC_OP_TOKEN_ENDPOINT = os.environ.get('OIDC_TOKEN_ENDPOINT') - OIDC_OP_USER_ENDPOINT = os.environ.get('OIDC_USER_ENDPOINT') - - LOGIN_REDIRECT_URL = os.environ.get('DASHBOARD_URL') - LOGOUT_REDIRECT_URL = os.environ.get('DASHBOARD_URL') - - OIDC_RP_SIGN_ALGO = os.environ.get("OIDC_RP_SIGN_ALGO") - - if OIDC_RP_SIGN_ALGO == "RS256": - OIDC_OP_JWKS_ENDPOINT = os.environ.get("OIDC_OP_JWKS_ENDPOINT") -else: - raise Exception('AUTH_SETTING set to invalid value') - -# This is for LFID auth setups w/ an HTTPS proxy -if os.environ.get('EXPECT_HOST_FORWARDING') == 'True': - SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', "https") - USE_X_FORWARDED_HOST = True - -ROOT_URLCONF = 'laas_dashboard.urls' - -TEMPLATE_OVERRIDE = os.environ.get("TEMPLATE_OVERRIDE_DIR", "") # the user's custom template dir -TEMPLATE_DIRS = ["base"] # where all the base templates are - -# If the user has a custom template directory, -# We should search that first. Then we search the -# root template directory so that we can extend the base -# templates within the custom template dir. -if TEMPLATE_OVERRIDE: - TEMPLATE_DIRS = [TEMPLATE_OVERRIDE, ""] + TEMPLATE_DIRS - -# all template dirs are relative to /project_root/templates/ -dirs = [os.path.join(BASE_DIR, "templates", d) for d in TEMPLATE_DIRS] - -TEMPLATES = [ - { - 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': dirs, - 'APP_DIRS': True, - 'OPTIONS': { - 'context_processors': [ - 'dashboard.context_processors.debug', - 'django.template.context_processors.debug', - 'django.template.context_processors.request', - 'django.contrib.auth.context_processors.auth', - 'django.contrib.messages.context_processors.messages', - ], - }, - }, -] - -TEMPLATE_CONTEXT_PROCESSORS = [ - 'dashboard.context_processors.debug', -] - -WSGI_APPLICATION = 'laas_dashboard.wsgi.application' - -# Password validation -# https://docs.djangoproject.com/en/1.10/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/1.10/topics/i18n/ - -LANGUAGE_CODE = 'en-us' - -TIME_ZONE = 'UTC' - -USE_I18N = True - -USE_L10N = True - -USE_TZ = True - -# Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/1.10/howto/static-files/ -MEDIA_URL = '/media/' -STATIC_URL = '/static/' - -# Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/1.10/howto/static-files/ -STATICFILES_DIRS = [ - os.path.join(BASE_DIR, "static"), -] - -LOGIN_REDIRECT_URL = '/' - -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = os.environ.get('SECRET_KEY') - -BOOTSTRAP3 = { - 'set_placeholder': False, -} - -ALLOWED_HOSTS = ['*'] - -# Database -# https://docs.djangoproject.com/en/1.10/ref/settings/#databases -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.postgresql', - 'NAME': os.environ.get('DB_NAME'), - 'USER': os.environ.get('DB_USER'), - 'PASSWORD': os.environ.get('DB_PASS'), - 'HOST': os.environ.get('DB_SERVICE'), - 'PORT': os.environ.get('DB_PORT') - } -} - -# Rest API Settings -REST_FRAMEWORK = { - 'DEFAULT_PERMISSION_CLASSES': [ - 'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly' - ], - 'DEFAULT_FILTER_BACKENDS': ('django_filters.rest_framework.FilterSet',), - 'DEFAULT_AUTHENTICATION_CLASSES': ( - 'rest_framework.authentication.SessionAuthentication', - 'rest_framework.authentication.TokenAuthentication', - ) -} - -MEDIA_ROOT = '/media' -STATIC_ROOT = '/static' - -OAUTH_CONSUMER_KEY = os.environ.get('OAUTH_CONSUMER_KEY') -OAUTH_CONSUMER_SECRET = os.environ.get('OAUTH_CONSUMER_SECRET') - -OAUTH_CALLBACK_URL = os.environ.get('DASHBOARD_URL') + '/accounts/authenticated' - -# Celery Settings -CELERY_TIMEZONE = 'UTC' - -RABBITMQ_URL = 'rabbitmq' -# RABBITMQ_DEFAULT_USER = os.environ['DEFAULT_USER'] -# RABBITMQ_DEFAULT_PASS = os.environ['DEFAULT_PASS'] -RABBITMQ_DEFAULT_USER = os.environ['RABBITMQ_DEFAULT_USER'] -RABBITMQ_DEFAULT_PASS = os.environ['RABBITMQ_DEFAULT_PASS'] - -CELERY_BROKER_URL = 'amqp://' + RABBITMQ_DEFAULT_USER + ':' + RABBITMQ_DEFAULT_PASS + '@rabbitmq:5672//' - -CELERY_BEAT_SCHEDULE = { - 'booking_poll': { - 'task': 'dashboard.tasks.booking_poll', - 'schedule': timedelta(minutes=1) - }, - 'free_hosts': { - 'task': 'dashboard.tasks.free_hosts', - 'schedule': timedelta(minutes=1) - }, - 'notify_expiring': { - 'task': 'notifier.tasks.notify_expiring', - 'schedule': timedelta(hours=1) - }, - 'query_vpn_users': { - 'task': 'dashboard.tasks.query_vpn_users', - 'schedule': timedelta(hours=1) - }, - 'dispatch_emails': { - 'task': 'notifier.tasks.dispatch_emails', - 'schedule': timedelta(minutes=10) - } -} - -# Notifier Settings -EMAIL_HOST = os.environ.get('EMAIL_HOST') -EMAIL_PORT = os.environ.get('EMAIL_PORT') -EMAIL_HOST_USER = os.environ.get('EMAIL_HOST_USER') -EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_HOST_PASSWORD') -EMAIL_USE_TLS = True -DEFAULT_EMAIL_FROM = os.environ.get('DEFAULT_EMAIL_FROM', 'webmaster@localhost') -SESSION_ENGINE = "django.contrib.sessions.backends.signed_cookies" -EXPIRE_LIFETIME = 12 # Minimum lifetime of booking to send notification -EXPIRE_HOURS = 48 # Notify when booking is expiring within this many hours diff --git a/src/laas_dashboard/urls.py b/src/laas_dashboard/urls.py deleted file mode 100644 index 7a37d7e..0000000 --- a/src/laas_dashboard/urls.py +++ /dev/null @@ -1,49 +0,0 @@ -############################################################################## -# Copyright (c) 2016 Max Breitenfeldt and others. -# Copyright (c) 2018 Sawyer Bergeron, Parker Berberian, and others. -# -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################## - - -""" -laas_dashboard URL Configuration. - -The `urlpatterns` list routes URLs to views. For more information please see: - https://docs.djangoproject.com/en/1.10/topics/http/urls/ -Examples: -Function views - 1. Add an import: from my_app import views - 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') -Class-based views - 1. Add an import: from other_app.views import Home - 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') -Including another URLconf - 1. Import the include() function: from django.conf.urls import url, include - 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) -""" -from django.conf import settings -from django.conf.urls import url, include -from django.conf.urls.static import static -from django.contrib import admin - - -urlpatterns = [ - - url(r'^workflow/', include('workflow.urls', namespace='workflow')), - url(r'^', include('dashboard.urls', namespace='dashboard')), - url(r'^booking/', include('booking.urls', namespace='booking')), - url(r'^accounts/', include('account.urls', namespace='account')), - url(r'^resource/', include('resource_inventory.urls', namespace='resource')), - url(r'^admin/', admin.site.urls), - url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')), - url(r'^api/', include('api.urls')), - url(r'^messages/', include('notifier.urls', namespace='notifier')), - url(r'^oidc/', include('mozilla_django_oidc.urls')), -] - -if settings.DEBUG is True: - urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/src/laas_dashboard/wsgi.py b/src/laas_dashboard/wsgi.py deleted file mode 100644 index 6858d3c..0000000 --- a/src/laas_dashboard/wsgi.py +++ /dev/null @@ -1,26 +0,0 @@ -############################################################################## -# Copyright (c) 2016 Max Breitenfeldt and others. -# -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################## - - -""" -WSGI config for laas_dashboard 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/1.10/howto/deployment/wsgi/ -""" - -import os - -from django.core.wsgi import get_wsgi_application - -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "laas_dashboard.settings") - -application = get_wsgi_application() |