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
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import ldap
from os.path import dirname, abspath
sys.path.append(dirname(dirname(abspath(__file__))))
from account import AccountService
from app import app
"""
Create a new service
With this script you can easily create a new service entry in the ldap
backend.
Usage:
. env/bin/activate
contrib/create_service.py name_of_new_service
"""
if __name__ == "__main__":
if len(sys.argv) < 2:
print(("Usage: %s name" % sys.argv[0]))
exit(-1)
name = sys.argv[1]
service = AccountService(app.config['LDAP_HOST'], app.config['LDAP_BASE_DN'],
app.config['LDAP_ADMIN_USER'], app.config['LDAP_ADMIN_PASS'],
app.all_services)
service._bind_as_admin()
dn = service._format_dn([('cn',name),('ou','services')])
try:
data = service.connection.search_s(dn, ldap.SCOPE_SUBTREE)
print(("'%s' already exists as service." % name))
except ldap.NO_SUCH_OBJECT:
attr = [
('objectClass', ['top','organizationalRole']),
('cn', service._escape(name))
]
service.connection.add_s(dn, attr)
print(("Successfully created '%s' as a new service." % name))
service._unbind()
|