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-04 12:01:38 +00:00
|
|
|
from passbook.outposts.models import (
|
|
|
|
DockerServiceConnection,
|
|
|
|
KubernetesServiceConnection,
|
|
|
|
Outpost,
|
|
|
|
)
|
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-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"""
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
|
|
|
model = DockerServiceConnection
|
|
|
|
fields = ["name", "local", "url", "tls"]
|
|
|
|
widgets = {
|
|
|
|
"name": forms.TextInput,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
}
|