From 914ba3f28741ed6da2b7a05b43f47799e1967ee8 Mon Sep 17 00:00:00 2001 From: Nico von Geyso Date: Sat, 29 Sep 2012 03:14:07 +0200 Subject: added script to add new services to ldap backend --- contrib/create_service.py | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100755 contrib/create_service.py (limited to 'contrib') 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() -- cgit v1.2.3-1-g7c22