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
98a0d2ee
authored
Jul 28, 2022
by
Karsa Zoltán István
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jinja hash filter
parent
d8ffc349
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
8 deletions
+15
-8
circle/vm/models/instance.py
+15
-8
No files found.
circle/vm/models/instance.py
View file @
98a0d2ee
...
...
@@ -78,8 +78,8 @@ ACCESS_METHODS = [(key, name) for key, (name, port, transport)
in
list
(
ACCESS_PROTOCOLS
.
items
())]
CI_META_DATA_DEF
=
"""
instance-id: {{
hostname
}}
local-hostname: {{
hostname
}}
instance-id: {{
hostname
}}
local-hostname: {{
hostname
}}
"""
.
strip
()
CI_USER_DATA_DEF
=
"""
...
...
@@ -87,14 +87,14 @@ CI_USER_DATA_DEF = """
users:
- default
- name: {{
sysuser
}}
- name: {{
sysuser
}}
sudo: ['ALL=(ALL) NOPASSWD:ALL']
groups: sudo
shell: /bin/bash
ssh_pwauth: True
chpasswd: { expire: False }
lock-passwd: false
passwd: "{{
password
}}"
passwd: "{{
password | hash
}}"
"""
.
strip
()
try
:
...
...
@@ -254,11 +254,18 @@ class InstanceTemplate(AclBase, VirtualMachineDescModel, TimeStampedModel):
return
'template.
%
d'
%
self
.
pk
class
CITemplate
:
def
rndstr
(
self
,
len
):
return
''
.
join
(
random
.
choice
(
string
.
ascii_letters
)
for
i
in
range
(
int
(
len
)))
def
j2_hash
(
value
,
hash
=
'sha512'
):
return
sha512_crypt
.
hash
(
value
)
env
=
jinja2
.
Environment
(
trim_blocks
=
True
,
lstrip_blocks
=
True
)
env
.
filters
[
"hash"
]
=
j2_hash
class
AclTemplate
:
def
__init__
(
self
,
instance
):
self
.
user_levels
=
list
({
'username'
:
u
.
username
,
'level'
:
l
}
for
u
,
l
in
instance
.
get_users_with_level
())
...
...
@@ -408,7 +415,7 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
datas
=
{
"sysuser"
:
"cloud"
,
"hostname"
:
self
.
short_hostname
,
"password"
:
s
ha512_crypt
.
hash
(
self
.
pw
)
,
"password"
:
s
elf
.
pw
,
"owner"
:
str
(
self
.
owner
.
username
),
"net"
:
NetTemplate
(
self
),
"acl"
:
AclTemplate
(
self
),
...
...
@@ -421,19 +428,19 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
def
get_user_data
(
self
):
data
=
str
(
self
.
ci_user_data
)
ci_datas
=
self
.
get_ci_data_dict
()
template
=
jinja2
.
Template
(
data
,
trim_blocks
=
True
,
lstrip_blocks
=
True
)
template
=
env
.
from_string
(
data
)
return
template
.
render
(
ci_datas
)
@property
def
get_meta_data
(
self
):
data
=
str
(
self
.
ci_meta_data
)
ci_datas
=
self
.
get_ci_data_dict
()
template
=
jinja2
.
Template
(
data
,
trim_blocks
=
True
,
lstrip_blocks
=
True
)
template
=
env
.
from_string
(
data
)
return
template
.
render
(
ci_datas
)
def
validate_ci_data
(
self
,
data
):
ci_datas
=
self
.
get_ci_data_dict
()
template
=
jinja2
.
Template
(
data
,
trim_blocks
=
True
,
lstrip_blocks
=
True
)
template
=
env
.
from_string
(
data
)
data
=
template
.
render
(
ci_datas
)
yaml
.
dump
(
yaml
.
load
(
data
,
Loader
=
yaml
.
Loader
))
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