1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# coding: utf-8
#
from django import forms
from django.utils.translation import ugettext_lazy as _
from terminal.models import ReplayStorage, CommandStorage
__all__ = [
'ReplayStorageAzureForm', 'ReplayStorageOSSForm', 'ReplayStorageS3Form',
'ReplayStorageCephForm', 'ReplayStorageSwiftForm',
'CommandStorageTypeESForm',
]
class BaseStorageForm(forms.Form):
def __init__(self, *args, **kwargs):
super(BaseStorageForm, self).__init__(*args, **kwargs)
self.fields['type'].widget.attrs['disabled'] = True
self.fields.move_to_end('comment')
class BaseReplayStorageForm(BaseStorageForm, forms.ModelForm):
class Meta:
model = ReplayStorage
fields = ['name', 'type', 'comment']
class BaseCommandStorageForm(BaseStorageForm, forms.ModelForm):
class Meta:
model = CommandStorage
fields = ['name', 'type', 'comment']
class ReplayStorageAzureForm(BaseReplayStorageForm):
azure_container_name = forms.CharField(
max_length=128, label=_('Container name'), required=False
)
azure_account_name = forms.CharField(
max_length=128, label=_('Account name'), required=False
)
azure_account_key = forms.CharField(
max_length=128, label=_('Account key'), required=False,
widget=forms.PasswordInput
)
azure_endpoint_suffix = forms.ChoiceField(
choices=(
('core.chinacloudapi.cn', 'core.chinacloudapi.cn'),
('core.windows.net', 'core.windows.net')
),
label=_('Endpoint suffix'), required=False,
)
class ReplayStorageOSSForm(BaseReplayStorageForm):
oss_bucket = forms.CharField(
max_length=128, label=_('Bucket'), required=False
)
oss_access_key = forms.CharField(
max_length=128, label=_('Access key'), required=False,
widget=forms.PasswordInput
)
oss_secret_key = forms.CharField(
max_length=128, label=_('Secret key'), required=False,
widget=forms.PasswordInput
)
oss_endpoint = forms.CharField(
max_length=128, label=_('Endpoint'), required=False,
help_text=_(
"""
OSS: http://{REGION_NAME}.aliyuncs.com <br>
Example: http://oss-cn-hangzhou.aliyuncs.com
"""
)
)
class ReplayStorageS3Form(BaseReplayStorageForm):
s3_bucket = forms.CharField(
max_length=128, label=_('Bucket'), required=False
)
s3_access_key = forms.CharField(
max_length=128, label=_('Access key'), required=False,
widget=forms.PasswordInput
)
s3_secret_key = forms.CharField(
max_length=128, label=_('Secret key'), required=False,
widget=forms.PasswordInput
)
s3_endpoint = forms.CharField(
max_length=128, label=_('Endpoint'), required=False,
help_text=_(
"""
S3: http://s3.{REGION_NAME}.amazonaws.com <br>
S3(China): http://s3.{REGION_NAME}.amazonaws.com.cn <br>
Example: http://s3.cn-north-1.amazonaws.com.cn
"""
)
)
class ReplayStorageCephForm(BaseReplayStorageForm):
ceph_bucket = forms.CharField(
max_length=128, label=_('Bucket'), required=False
)
ceph_access_key = forms.CharField(
max_length=128, label=_('Access key'), required=False,
widget=forms.PasswordInput
)
ceph_secret_key = forms.CharField(
max_length=128, label=_('Secret key'), required=False,
widget=forms.PasswordInput
)
ceph_endpoint = forms.CharField(
max_length=128, label=_('Endpoint'), required=False,
help_text=_(
"""
S3: http://s3.{REGION_NAME}.amazonaws.com <br>
S3(China): http://s3.{REGION_NAME}.amazonaws.com.cn <br>
Example: http://s3.cn-north-1.amazonaws.com.cn
"""
)
)
class ReplayStorageSwiftForm(BaseReplayStorageForm):
swift_bucket = forms.CharField(
max_length=128, label=_('Bucket'), required=False
)
swift_access_key = forms.CharField(
max_length=128, label=_('Access key'), required=False,
widget=forms.PasswordInput
)
swift_secret_key = forms.CharField(
max_length=128, label=_('Secret key'), required=False,
widget=forms.PasswordInput
)
swift_region = forms.CharField(
max_length=128, label=_('Region'), required=False,
)
swift_endpoint = forms.CharField(
max_length=128, label=_('Endpoint'), required=False,
)
class CommandStorageTypeESForm(BaseCommandStorageForm):
es_hosts = forms.CharField(
max_length=128, label=_('Hosts'), required=True,
help_text=_(
"""
Tips: If there are multiple hosts, separate them with a comma (,)
<br>
eg: http://www.jumpserver.a.com,http://www.jumpserver.b.com
"""
)
)
es_index = forms.CharField(
max_length=128, label=_('Index'), required=True
)
es_doc_type = forms.CharField(
max_length=128, label=_('Doc type'), required=True
)