From 8ce63d14b6e7d46ed6b31d7cd1a32a1e102f406b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoha=C3=AF-Eliel=20BERREBY?= Date: Thu, 21 May 2020 18:08:20 +0200 Subject: [PATCH] radius: fix settings_local.py --- roles/radius/tasks/main.yml | 8 +++--- roles/radius/templates/local_routers.py.j2 | 28 +++++++++++++++++++++ roles/radius/templates/settings_local.py.j2 | 19 +++++++++++--- 3 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 roles/radius/templates/local_routers.py.j2 diff --git a/roles/radius/tasks/main.yml b/roles/radius/tasks/main.yml index 574a3ef..dfdeac8 100644 --- a/roles/radius/tasks/main.yml +++ b/roles/radius/tasks/main.yml @@ -20,9 +20,11 @@ - name: Template local re2o settings template: - src: settings_local.py.j2 - dest: "/var/www/re2o/re2o/settings_local.py" - + src: "{{ item }}.j2" + dest: "/var/www/re2o/re2o/{{ item }}" + loop: + - settings_local.py + - local_routers.py # What follows is a hideous abomination. diff --git a/roles/radius/templates/local_routers.py.j2 b/roles/radius/templates/local_routers.py.j2 new file mode 100644 index 0000000..ce42020 --- /dev/null +++ b/roles/radius/templates/local_routers.py.j2 @@ -0,0 +1,28 @@ +class DbRouter(object): + """ + A router to control all database operations on models in the + auth application. + """ + def db_for_read(self, model, **hints): + """ + Attempts to read remote models go to local database. + """ + return 'default' + + def db_for_write(self, model, **hints): + """ + Attempts to write remote models go to the remote database. + """ + return 'master' + + def allow_relation(self, obj1, obj2, **hints): + """ + Allow relations involving the remote database + """ + return True + + def allow_migrate(self, db, app_label, model_name=None, **hints): + """ + Allow migrations on the remote database + """ + return True diff --git a/roles/radius/templates/settings_local.py.j2 b/roles/radius/templates/settings_local.py.j2 index 1a6308e..01d9043 100644 --- a/roles/radius/templates/settings_local.py.j2 +++ b/roles/radius/templates/settings_local.py.j2 @@ -44,14 +44,14 @@ DEBUG = False ADMINS = [('AURORE', 'monitoring.aurore@lists.crans.org'), ('Gabriel Detraz', 'detraz@crans.org')] # The list of hostname the server will respond to. -ALLOWED_HOSTS = ['radius-pacaterie.adm.auro.re'] +ALLOWED_HOSTS = ['{{ inventory_hostname }}'] # The time zone the server is runned in TIME_ZONE = 'Europe/Paris' # The storage systems parameters to use DATABASES = { - 'default': { # The DB + 'master': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 're2o', 'USER': 're2o', @@ -62,7 +62,18 @@ DATABASES = { 'COLLATION': 'utf8_general_ci' } }, - 'ldap': { # The LDAP + 'default': { + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': 're2o', + 'USER': 're2o_ro', + 'PASSWORD': "{{ radius_pg_re2o_ro_password }}", + 'HOST': 'localhost', + 'TEST': { + 'CHARSET': 'utf8', + 'COLLATION': 'utf8_general_ci' + } + }, + 'ldap': { 'ENGINE': 'ldapdb.backends.ldap', 'NAME': 'ldap://10.128.0.11/', 'USER': 'cn=admin,dc=auro,dc=re', @@ -114,3 +125,5 @@ OPTIONNAL_APPS_RE2O = () # Some Django apps you want to add in you local project OPTIONNAL_APPS = OPTIONNAL_APPS_RE2O + () + +LOCAL_ROUTERS = ["re2o.local_routers.DbRouter"]