Merge branch '34-parsed-url-cached' into 'master'
Resolve "InvalidUpstream: Upstream URL scheme must be either 'http' or 'https' (https://ory1-esxi-prod-1.ory1.beryju.org)." Closes #34 See merge request BeryJu.org/passbook!19
This commit is contained in:
commit
80e6d59382
|
@ -1,4 +1,5 @@
|
||||||
"""passbook Application Security Gateway Forms"""
|
"""passbook Application Security Gateway Forms"""
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.contrib.admin.widgets import FilteredSelectMultiple
|
from django.contrib.admin.widgets import FilteredSelectMultiple
|
||||||
|
@ -19,9 +20,18 @@ class ApplicationGatewayProviderForm(forms.ModelForm):
|
||||||
if ApplicationGatewayProvider.objects \
|
if ApplicationGatewayProvider.objects \
|
||||||
.filter(server_name__overlap=current) \
|
.filter(server_name__overlap=current) \
|
||||||
.exclude(pk=self.instance.pk).exists():
|
.exclude(pk=self.instance.pk).exists():
|
||||||
raise ValidationError("Server Name already in use.")
|
raise ValidationError(_("Server Name already in use."))
|
||||||
return current
|
return current
|
||||||
|
|
||||||
|
def clean_upstream(self):
|
||||||
|
"""Check that upstream begins with http(s)"""
|
||||||
|
for upstream in self.cleaned_data.get('upstream'):
|
||||||
|
_parsed_url = urlparse(upstream)
|
||||||
|
|
||||||
|
if _parsed_url.scheme not in ('http', 'https'):
|
||||||
|
raise ValidationError(_("URL Scheme must be either http or https"))
|
||||||
|
return self.cleaned_data.get('upstream')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
||||||
model = ApplicationGatewayProvider
|
model = ApplicationGatewayProvider
|
||||||
|
|
|
@ -90,7 +90,6 @@ class ApplicationGatewayMiddleware:
|
||||||
# TODO: How to choose upstream?
|
# TODO: How to choose upstream?
|
||||||
upstream = self.app_gw.upstream[0]
|
upstream = self.app_gw.upstream[0]
|
||||||
|
|
||||||
if not getattr(self, '_parsed_url', None):
|
|
||||||
self._parsed_url = urlparse(upstream)
|
self._parsed_url = urlparse(upstream)
|
||||||
|
|
||||||
if self._parsed_url.scheme not in ('http', 'https'):
|
if self._parsed_url.scheme not in ('http', 'https'):
|
||||||
|
|
Reference in New Issue