From 013ae4cccf90e7dd3a623d3496a87a7e6dfbfbdb Mon Sep 17 00:00:00 2001
From: Christian Pointner <equinox@spreadspace.org>
Date: Sat, 16 Mar 2019 02:56:09 +0100
Subject: [PATCH] playing around with OIDC settings for tank

---
 Dockerfile                   |  9 ++++-----
 build.sh                     |  3 +++
 cleanup.sh                   |  4 ++++
 prepare.sh                   |  7 +++++++
 pv/oidc_provider_settings.py | 19 +++++++++++++++++++
 pv/settings.py               |  3 ++-
 run.sh                       |  4 ++++
 7 files changed, 43 insertions(+), 6 deletions(-)
 create mode 100755 build.sh
 create mode 100755 cleanup.sh
 create mode 100755 prepare.sh
 create mode 100644 pv/oidc_provider_settings.py
 create mode 100755 run.sh

diff --git a/Dockerfile b/Dockerfile
index 54a65ec5..f95a8b3d 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,12 +1,11 @@
-FROM python:3
+FROM python:3.6
 
-COPY . /tmp/
-RUN chmod +x /tmp/entrypoint.sh
+COPY requirements.txt /tmp/
 
 RUN pip install --no-cache-dir -r /tmp/requirements.txt
 
-RUN python /tmp/manage.py migrate
-ENTRYPOINT ["/tmp/entrypoint.sh"]
+#RUN python /tmp/manage.py migrate
+#ENTRYPOINT ["/tmp/entrypoint.sh"]
 
 # Superuser parameters are --username USERNAME and --email EMAIL but there is no password
 # RUN python /tmp/manage.py createsuperuser
diff --git a/build.sh b/build.sh
new file mode 100755
index 00000000..263476c3
--- /dev/null
+++ b/build.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+exec sudo docker build -t aura/pv .
diff --git a/cleanup.sh b/cleanup.sh
new file mode 100755
index 00000000..da119306
--- /dev/null
+++ b/cleanup.sh
@@ -0,0 +1,4 @@
+#!/bin/bash
+BASE_D=$(realpath "${BASH_SOURCE%/*}/")
+
+rm -f "$BASE_D/pv/dev_data.sqlite"
diff --git a/prepare.sh b/prepare.sh
new file mode 100755
index 00000000..0542405d
--- /dev/null
+++ b/prepare.sh
@@ -0,0 +1,7 @@
+#!/bin/bash
+BASE_D=$(realpath "${BASH_SOURCE%/*}/")
+
+sudo docker run --rm -it -u $UID:$GID -v "$BASE_D":/srv aura/pv /srv/manage.py migrate
+sudo docker run --rm -it -u $UID:$GID -v "$BASE_D":/srv aura/pv bash -c "/srv/manage.py loaddata /srv/program/fixtures/*.yaml"
+sudo docker run --rm -it -u $UID:$GID -v "$BASE_D":/srv aura/pv /srv/manage.py createsuperuser --username equinox --email equinox@helsinki.at
+sudo docker run --rm -it -u $UID:$GID -v "$BASE_D":/srv aura/pv /srv/manage.py creatersakey
diff --git a/pv/oidc_provider_settings.py b/pv/oidc_provider_settings.py
new file mode 100644
index 00000000..481a9072
--- /dev/null
+++ b/pv/oidc_provider_settings.py
@@ -0,0 +1,19 @@
+from django.utils.translation import ugettext as _
+from oidc_provider.lib.claims import ScopeClaims
+
+
+class AuraScopeClaims(ScopeClaims):
+
+    info_aura = (
+        _(u'aura'),
+        _(u'AURA specific auth info (username, shows, etc.).'),
+    )
+
+    def scope_aura(self):
+        show_slugs = list(self.user.shows.all().values_list('slug', flat=True))
+        dic = {
+            'username': self.user.username,
+            'shows': show_slugs
+        }
+
+        return dic
diff --git a/pv/settings.py b/pv/settings.py
index fd964b15..83ae49d3 100644
--- a/pv/settings.py
+++ b/pv/settings.py
@@ -179,6 +179,7 @@ CBA_REST_API_URL = CBA_URL + '/wp-json/wp/v2/'
 # OIDC Provider Settings
 USE_TZ = True # django-oidc-provider needs timezones in database
 LOGIN_URL = '/admin/login/' # Login page OIDC redirects to
+OIDC_EXTRA_SCOPE_CLAIMS = 'pv.oidc_provider_settings.AuraScopeClaims'
 
 #WSGI_APPLICATION = 'pv.wsgi.application';
 
@@ -195,4 +196,4 @@ SPECIAL_PROGRAM_IDS = ()
 try:
     from .local_settings import *
 except ImportError:
-    pass
\ No newline at end of file
+    pass
diff --git a/run.sh b/run.sh
new file mode 100755
index 00000000..4ad27d8f
--- /dev/null
+++ b/run.sh
@@ -0,0 +1,4 @@
+#!/bin/bash
+BASE_D=$(realpath "${BASH_SOURCE%/*}/")
+
+exec sudo docker run --rm -it -u $UID:$GID -p 127.0.0.1:8000:8000 -v "$BASE_D":/srv aura/pv /srv/manage.py runserver 0.0.0.0:8000
-- 
GitLab