Skip to content

Commit ab2b26f

Browse files
committed
Update ad_utils.py
1 parent 9450b5d commit ab2b26f

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/lib/ad_utils.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sys
44
sys.path.append('.')
55
import paramiko
6-
from jinja2 import FileSystemLoader
6+
from jinja2 import FileSystemLoader,BaseLoader
77
import backend_utils as u
88
import jinja2
99

@@ -38,26 +38,28 @@ def exec_cmd(command):
3838

3939
def compose_dn(entity):
4040
"""Compose the DN of a identity"""
41+
data = {
42+
'e': u.make_entry_array(entity),
43+
'config': u.get_config()
44+
}
45+
4146
rdnValue=u.find_key(entity,'cn')
4247
x=type(rdnValue)
4348
if rdnValue is None:
4449
rdnValue='test'
4550
branchAttr=u.config('branchAttr','')
46-
branch = ''
51+
data['rdnValue']=rdnValue
4752
if branchAttr != '':
4853
branchValue=u.find_key(entity,branchAttr)
49-
50-
match branchValue:
51-
case 'etd':
52-
branch=u.config('branchForEtd','')
53-
case 'esn':
54-
branch = u.config('branchForEsn', '')
55-
case 'adm':
56-
branch = u.config('branchForAdm', '')
57-
if branch != '':
58-
return 'cn=' + rdnValue+ ',' + branch + "," + u.config('base')
54+
key_branch='branchFor' + branchValue
55+
branch=u.config(key_branch,'')
56+
data['branch']=branch
57+
template_string = 'cn={{ rdnValue}},{{ branch }},{{ config.base }}'
5958
else:
60-
return 'cn=' + rdnValue+ "," + u.config('base')
59+
template= 'cn={{ rdnValue}},{{ config.base }}'
60+
template = jinja2.Environment(loader=jinja2.BaseLoader()).from_string(u.config('dnTemplate',template_string))
61+
content = template.render(data)
62+
return content
6163

6264
def dn_superior(dn):
6365
tab=dn.split(',')

0 commit comments

Comments
 (0)