2020-08-19 08:32:44 +00:00
|
|
|
"""passbook Proxy Provider Forms"""
|
|
|
|
from django import forms
|
|
|
|
|
2020-09-02 22:04:12 +00:00
|
|
|
from passbook.crypto.models import CertificateKeyPair
|
|
|
|
from passbook.flows.models import Flow, FlowDesignation
|
2020-08-19 08:32:44 +00:00
|
|
|
from passbook.providers.proxy.models import ProxyProvider
|
|
|
|
|
|
|
|
|
|
|
|
class ProxyProviderForm(forms.ModelForm):
|
|
|
|
"""Security Gateway Provider form"""
|
|
|
|
|
|
|
|
instance: ProxyProvider
|
|
|
|
|
2020-09-02 22:04:12 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
self.fields["authorization_flow"].queryset = Flow.objects.filter(
|
|
|
|
designation=FlowDesignation.AUTHORIZATION
|
|
|
|
)
|
|
|
|
self.fields["certificate"].queryset = CertificateKeyPair.objects.filter(
|
|
|
|
key_data__isnull=False
|
|
|
|
)
|
|
|
|
|
2020-08-19 08:32:44 +00:00
|
|
|
def save(self, *args, **kwargs):
|
2020-09-02 22:04:12 +00:00
|
|
|
actual_save = super().save(*args, **kwargs)
|
2020-08-19 08:32:44 +00:00
|
|
|
self.instance.set_oauth_defaults()
|
2020-09-02 22:04:12 +00:00
|
|
|
self.instance.save()
|
|
|
|
return actual_save
|
2020-08-19 08:32:44 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
|
|
|
model = ProxyProvider
|
2020-09-02 22:04:12 +00:00
|
|
|
fields = [
|
|
|
|
"name",
|
|
|
|
"authorization_flow",
|
|
|
|
"internal_host",
|
2020-09-23 10:20:09 +00:00
|
|
|
"internal_host_ssl_validation",
|
2020-09-02 22:04:12 +00:00
|
|
|
"external_host",
|
|
|
|
"certificate",
|
2020-09-19 09:31:48 +00:00
|
|
|
"skip_path_regex",
|
2020-09-02 22:04:12 +00:00
|
|
|
]
|
2020-08-19 08:32:44 +00:00
|
|
|
widgets = {
|
|
|
|
"name": forms.TextInput(),
|
|
|
|
"internal_host": forms.TextInput(),
|
|
|
|
"external_host": forms.TextInput(),
|
|
|
|
}
|