diff options
author | Marian Sigler <m@qjym.de> | 2012-09-29 15:12:18 +0200 |
---|---|---|
committer | Marian Sigler <m@qjym.de> | 2012-09-29 15:12:18 +0200 |
commit | 12a6678d280733bd420923b49608d62f8f920ab1 (patch) | |
tree | 057cb7f98d60600373f8056f597199140d836397 /contrib | |
parent | faa5a67b30bcedaf67223d1905036bff806cbf45 (diff) | |
parent | f6b2d051966a232c6227a31e9851fce031d6b9f6 (diff) | |
download | web-12a6678d280733bd420923b49608d62f8f920ab1.tar.gz web-12a6678d280733bd420923b49608d62f8f920ab1.tar.bz2 web-12a6678d280733bd420923b49608d62f8f920ab1.zip |
Merge branch 'master' of ssh://git.spline.de/account-web
Diffstat (limited to 'contrib')
-rwxr-xr-x | contrib/create_service.py | 50 |
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() |