# HG changeset patch # User Daniele Nicolodi # Date 1321526772 -3600 # Node ID f8f898b3905809ecdc7e335866aa1a39edf636f1 # Parent dd5e5fc17a6231adccca4e4fafc90b6a6af484e1 Add unprivileged user creation to install procedure. diff -r dd5e5fc17a62 -r f8f898b39058 src/ltpdarepo/admin.py --- a/src/ltpdarepo/admin.py Thu Nov 17 11:45:11 2011 +0100 +++ b/src/ltpdarepo/admin.py Thu Nov 17 11:46:12 2011 +0100 @@ -331,6 +331,7 @@ # install install = install cmd = commands.add(install) + cmd.add_argument('--create-user', '-c', action='store_true', dest='createuser') cmd.add_argument('--user', '-u', dest='_username', metavar='USER') cmd.add_argument('--passwd', '-p', dest='_password', metavar='PASSWORD', default='') @@ -409,7 +410,7 @@ def setup(self): """setup test environment""" - self.install() + self.install(createuser=True) self.useradd('u1', admin=True) self.passwd('u1', 'u1') self.createdb('db1', description=u'Test database One') diff -r dd5e5fc17a62 -r f8f898b39058 src/ltpdarepo/install.py --- a/src/ltpdarepo/install.py Thu Nov 17 11:45:11 2011 +0100 +++ b/src/ltpdarepo/install.py Thu Nov 17 11:46:12 2011 +0100 @@ -3,9 +3,35 @@ # This software may be used and distributed according to the terms of # the GNU Affero General Public License version 3 or any later version. -def install(instance): + +def createuser(instance): + + conn = instance.connect() + curs = conn.cursor() + + # create user + curs.execute("""CREATE USER %s@'localhost' IDENTIFIED BY %s""", + (instance.USERNAME, instance.PASSWORD)) + + # permissions on all databases + curs.execute("""GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, CREATE VIEW, CREATE USER + ON *.* TO %s@'localhost' WITH GRANT OPTION""", instance.USERNAME) + + # permissions on the administrative database + curs.execute("""GRANT EXECUTE, CREATE TEMPORARY TABLES + ON `%s`.* TO %%s@'localhost'""" % instance.DATABASE, instance.USERNAME) + + conn.commit() + conn.close() + + +def install(instance, **kwargs): """initialize database environment""" + # create user + if kwargs.get('createuser', False) and instance.USERNAME != 'root': + createuser(instance) + conn = instance.connect() curs = conn.cursor()