From ddb0fdee98e5c82e52ea7e6cdb4137e51866d76a Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sun, 26 Jul 2020 22:01:37 +0200 Subject: [PATCH] providers/app_gw: generate docker-compose in code --- passbook/providers/app_gw/models.py | 21 ++---- .../templates/app_gw/docker-compose.yml | 14 ---- .../app_gw/templates/app_gw/setup_modal.html | 2 +- passbook/providers/app_gw/views.py | 65 +++++++++++++++++-- 4 files changed, 66 insertions(+), 36 deletions(-) delete mode 100644 passbook/providers/app_gw/templates/app_gw/docker-compose.yml diff --git a/passbook/providers/app_gw/models.py b/passbook/providers/app_gw/models.py index 02f852d8b..3f9cefe00 100644 --- a/passbook/providers/app_gw/models.py +++ b/passbook/providers/app_gw/models.py @@ -1,17 +1,13 @@ """passbook app_gw models""" -import string -from random import SystemRandom from typing import Optional, Type from django.core.validators import URLValidator from django.db import models from django.forms import ModelForm from django.http import HttpRequest -from django.shortcuts import reverse from django.utils.translation import gettext as _ from oidc_provider.models import Client -from passbook import __version__ from passbook.core.models import Provider from passbook.lib.utils.template import render_to_string @@ -33,21 +29,12 @@ class ApplicationGatewayProvider(Provider): def html_setup_urls(self, request: HttpRequest) -> Optional[str]: """return template and context modal with URLs for authorize, token, openid-config, etc""" - cookie_secret = "".join( - SystemRandom().choice(string.ascii_uppercase + string.digits) - for _ in range(50) - ) - full_issuer_user = request.build_absolute_uri( - reverse("passbook_providers_oidc:authorize") - ) + from passbook.providers.app_gw.views import DockerComposeView + + docker_compose_yaml = DockerComposeView(request=request).get_compose(self) return render_to_string( "app_gw/setup_modal.html", - { - "provider": self, - "cookie_secret": cookie_secret, - "version": __version__, - "full_issuer_user": full_issuer_user, - }, + {"provider": self, "docker_compose": docker_compose_yaml}, ) def __str__(self): diff --git a/passbook/providers/app_gw/templates/app_gw/docker-compose.yml b/passbook/providers/app_gw/templates/app_gw/docker-compose.yml deleted file mode 100644 index d1fdfd455..000000000 --- a/passbook/providers/app_gw/templates/app_gw/docker-compose.yml +++ /dev/null @@ -1,14 +0,0 @@ -version: "3.5" - -services: - passbook_gatekeeper: - image: beryju/passbook-gatekeeper:{{ version }} - ports: - - 4180:4180 - environment: - OAUTH2_PROXY_CLIENT_ID: {{ provider.client.client_id }} - OAUTH2_PROXY_CLIENT_SECRET: {{ provider.client.client_secret }} - OAUTH2_PROXY_REDIRECT_URL: https://{{ provider.external_host }}/oauth2/callback - OAUTH2_PROXY_OIDC_ISSUER_URL: {{ full_issuer_user }} - OAUTH2_PROXY_COOKIE_SECRET: {{ cookie_secret }} - OAUTH2_PROXY_UPSTREAMS: http://{{ provider.internal_host }} diff --git a/passbook/providers/app_gw/templates/app_gw/setup_modal.html b/passbook/providers/app_gw/templates/app_gw/setup_modal.html index d18eebaf1..ef3bdea99 100644 --- a/passbook/providers/app_gw/templates/app_gw/setup_modal.html +++ b/passbook/providers/app_gw/templates/app_gw/setup_modal.html @@ -26,7 +26,7 @@
{% trans 'Add the following snippet to your docker-compose file.' %} - +