summaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
authorNico von Geyso <Nico.Geyso@FU-Berlin.de>2012-09-29 03:14:07 +0200
committerNico von Geyso <Nico.Geyso@FU-Berlin.de>2012-09-29 03:14:07 +0200
commit914ba3f28741ed6da2b7a05b43f47799e1967ee8 (patch)
tree6266473eb417627de7849bf0026ff331e0b0cd37 /contrib
parentc9e4ab447c06cbcc929f9c77bdd63a7bd10ba71b (diff)
downloadweb-914ba3f28741ed6da2b7a05b43f47799e1967ee8.tar.gz
web-914ba3f28741ed6da2b7a05b43f47799e1967ee8.tar.bz2
web-914ba3f28741ed6da2b7a05b43f47799e1967ee8.zip
added script to add new services to ldap backend
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/create_service.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/contrib/create_service.py b/contrib/create_service.py
new file mode 100755
index 0000000..1da956a
--- /dev/null
+++ b/contrib/create_service.py
@@ -0,0 +1,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()