Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE3
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
5
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
c486bc51
authored
Jul 25, 2022
by
Karsa Zoltán István
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
validation ci data
parent
5c8fa224
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
13 deletions
+23
-13
circle/dashboard/forms.py
+6
-7
circle/dashboard/validators.py
+17
-0
circle/vm/models/instance.py
+0
-6
No files found.
circle/dashboard/forms.py
View file @
c486bc51
...
...
@@ -60,7 +60,7 @@ from vm.models import (
InstanceTemplate
,
Lease
,
InterfaceTemplate
,
Node
,
Trait
,
Instance
)
from
.models
import
Profile
,
GroupProfile
,
Message
from
.validators
import
domain_validator
from
.validators
import
domain_validator
,
meta_data_validator
,
user_data_validator
LANGUAGES_WITH_CODE
=
((
l
[
0
],
ugettext_lazy
(
l
[
1
],
" ("
,
l
[
0
],
")"
))
for
l
in
LANGUAGES
)
...
...
@@ -569,6 +569,9 @@ class TemplateForm(forms.ModelForm):
self
.
fields
[
'raw_data'
]
.
validators
.
append
(
domain_validator
)
self
.
fields
[
'ci_user_data'
]
.
validators
.
append
(
user_data_validator
)
self
.
fields
[
'ci_meta_data'
]
.
validators
.
append
(
meta_data_validator
)
def
clean_owner
(
self
):
if
self
.
instance
.
pk
is
not
None
:
return
User
.
objects
.
get
(
pk
=
self
.
instance
.
owner
.
pk
)
...
...
@@ -1535,9 +1538,11 @@ class RawDataForm(forms.ModelForm):
class
CIDataForm
(
forms
.
ModelForm
):
ci_meta_data
=
forms
.
CharField
(
disabled
=
True
,
help_text
=
'meta-data'
,
validators
=
[
meta_data_validator
],
widget
=
forms
.
Textarea
(
attrs
=
{
'rows'
:
5
}),
required
=
False
)
ci_user_data
=
forms
.
CharField
(
disabled
=
True
,
help_text
=
'user-data'
,
validators
=
[
user_data_validator
],
widget
=
forms
.
Textarea
(
attrs
=
{
'rows'
:
5
}),
required
=
False
)
...
...
@@ -1551,12 +1556,6 @@ class CIDataForm(forms.ModelForm):
helper
.
form_show_labels
=
False
return
helper
def
clean
(
self
):
cleaned_data
=
super
(
forms
.
ModelForm
,
self
)
.
clean
()
Instance
.
validate_meta_data
(
cleaned_data
[
'ci_meta_data'
])
Instance
.
validate_user_data
(
cleaned_data
[
'ci_user_data'
])
return
cleaned_data
class
GroupPermissionForm
(
forms
.
ModelForm
):
permissions
=
forms
.
ModelMultipleChoiceField
(
...
...
circle/dashboard/validators.py
View file @
c486bc51
...
...
@@ -20,6 +20,9 @@ from django.utils.translation import ugettext_lazy as _
from
lxml
import
etree
as
ET
import
logging
import
yaml
from
vm.models
import
Instance
rng_file
=
"/usr/share/libvirt/schemas/domain.rng"
...
...
@@ -50,6 +53,20 @@ def domain_validator(value):
raise
ValidationError
(
e
.
message
)
def
meta_data_validator
(
value
):
try
:
Instance
.
validate_meta_data
(
value
)
except
yaml
.
YAMLError
as
exc
:
raise
ValidationError
(
exc
.
problem_mark
)
def
user_data_validator
(
value
):
try
:
Instance
.
validate_user_data
(
value
)
except
yaml
.
YAMLError
as
exc
:
raise
ValidationError
(
exc
.
problem_mark
)
def
connect_command_template_validator
(
value
):
"""Validate value as a connect command template.
...
...
circle/vm/models/instance.py
View file @
c486bc51
...
...
@@ -376,10 +376,7 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
def
validate_user_data
(
cls
,
user_data
):
data
=
user_data
.
replace
(
'{{user}}'
,
'user'
)
data
=
data
.
replace
(
'{{password}}'
,
'passwd'
)
try
:
yaml
.
dump
(
yaml
.
load
(
data
,
Loader
=
yaml
.
Loader
))
except
yaml
.
YAMLError
as
exc
:
raise
forms
.
ValidationError
(
exc
.
problem_mark
)
return
True
@property
...
...
@@ -390,10 +387,7 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
@classmethod
def
validate_meta_data
(
cls
,
meta_data
):
data
=
meta_data
.
replace
(
'{{hostname}}'
,
'hostname'
)
try
:
yaml
.
dump
(
yaml
.
load
(
data
,
Loader
=
yaml
.
Loader
))
except
yaml
.
YAMLError
as
exc
:
raise
forms
.
ValidationError
(
exc
.
problem_mark
)
return
True
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment