2020-09-02 22:04:12 +00:00
|
|
|
"""Outpost forms"""
|
|
|
|
|
|
|
|
from django import forms
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
|
|
|
|
from passbook.admin.fields import CodeMirrorWidget, YAMLField
|
2020-11-18 23:53:33 +00:00
|
|
|
from passbook.crypto.models import CertificateKeyPair
|
2020-11-04 12:01:38 +00:00
|
|
|
from passbook.outposts.models import (
|
|
|
|
DockerServiceConnection,
|
|
|
|
KubernetesServiceConnection,
|
|
|
|
Outpost,
|
2020-11-11 13:34:43 +00:00
|
|
|
OutpostServiceConnection,
|
2020-11-04 12:01:38 +00:00
|
|
|
)
|
2020-09-18 19:46:14 +00:00
|
|
|
from passbook.providers.proxy.models import ProxyProvider
|
2020-09-02 22:04:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
class OutpostForm(forms.ModelForm):
|
|
|
|
"""Outpost Form"""
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
2020-09-18 19:46:14 +00:00
|
|
|
self.fields["providers"].queryset = ProxyProvider.objects.all()
|
2020-11-11 13:34:43 +00:00
|
|
|
self.fields[
|
|
|
|
"service_connection"
|
|
|
|
].queryset = OutpostServiceConnection.objects.select_subclasses()
|
2020-09-02 22:04:12 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
|
|
|
model = Outpost
|
|
|
|
fields = [
|
|
|
|
"name",
|
|
|
|
"type",
|
2020-11-04 09:41:18 +00:00
|
|
|
"service_connection",
|
2020-09-02 22:04:12 +00:00
|
|
|
"providers",
|
|
|
|
"_config",
|
|
|
|
]
|
|
|
|
widgets = {
|
|
|
|
"name": forms.TextInput(),
|
|
|
|
"_config": CodeMirrorWidget,
|
|
|
|
}
|
|
|
|
field_classes = {
|
|
|
|
"_config": YAMLField,
|
|
|
|
}
|
|
|
|
labels = {"_config": _("Configuration")}
|
2020-11-04 12:01:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
class DockerServiceConnectionForm(forms.ModelForm):
|
|
|
|
"""Docker service-connection form"""
|
|
|
|
|
2020-11-18 23:53:33 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
self.fields["tls_authentication"].queryset = CertificateKeyPair.objects.filter(
|
|
|
|
key_data__isnull=False
|
|
|
|
)
|
|
|
|
|
2020-11-04 12:01:38 +00:00
|
|
|
class Meta:
|
|
|
|
|
|
|
|
model = DockerServiceConnection
|
2020-11-18 23:53:33 +00:00
|
|
|
fields = ["name", "local", "url", "tls_verification", "tls_authentication"]
|
2020-11-04 12:01:38 +00:00
|
|
|
widgets = {
|
|
|
|
"name": forms.TextInput,
|
2020-11-08 20:31:27 +00:00
|
|
|
"url": forms.TextInput,
|
|
|
|
}
|
|
|
|
labels = {
|
|
|
|
"url": _("URL"),
|
2020-11-18 23:53:33 +00:00
|
|
|
"tls_verification": _("TLS Verification Certificate"),
|
|
|
|
"tls_authentication": _("TLS Authentication Certificate"),
|
2020-11-04 12:01:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class KubernetesServiceConnectionForm(forms.ModelForm):
|
|
|
|
"""Kubernetes service-connection form"""
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
|
|
|
model = KubernetesServiceConnection
|
|
|
|
fields = [
|
|
|
|
"name",
|
|
|
|
"local",
|
|
|
|
"kubeconfig",
|
|
|
|
]
|
|
|
|
widgets = {
|
|
|
|
"name": forms.TextInput,
|
|
|
|
"kubeconfig": CodeMirrorWidget,
|
|
|
|
}
|
|
|
|
field_classes = {
|
|
|
|
"kubeconfig": YAMLField,
|
|
|
|
}
|