Restore ability to run from checkout
authorSimo Sorce <simo@redhat.com>
Mon, 25 Aug 2014 20:40:21 +0000 (16:40 -0400)
committerPatrick Uiterwijk <puiterwijk@redhat.com>
Wed, 27 Aug 2014 22:15:03 +0000 (18:15 -0400)
also adds quickrun.py script to make it easy.

Signed-off-by: Simo Sorce <simo@redhat.com>
Reviewed-by: Patrick Uiterwijk <puiterwijk@redhat.com>
ipsilon/providers/saml2/admin.py
quickrun.py [new file with mode: 0755]

index 5d97126..1c62cac 100755 (executable)
@@ -309,12 +309,13 @@ class AdminPage(Page):
     def mount(self, page):
         self.menu = page.menu
         self.url = '%s/%s' % (page.url, self.name)
-        for p in self.cfg.idp.get_providers():
-            try:
-                sp = ServiceProvider(self.cfg, p)
-                self.add_sp(sp.name, sp)
-            except Exception, e:  # pylint: disable=broad-except
-                self._debug("Failed to find provider %s: %s" % (p, str(e)))
+        if self.cfg.idp:
+            for p in self.cfg.idp.get_providers():
+                try:
+                    sp = ServiceProvider(self.cfg, p)
+                    self.add_sp(sp.name, sp)
+                except Exception, e:  # pylint: disable=broad-except
+                    self._debug("Failed to find provider %s: %s" % (p, str(e)))
         self.add_subtree('new', NewSPAdminPage(self._site, self))
         page.add_subtree(self.name, self)
 
diff --git a/quickrun.py b/quickrun.py
new file mode 100755 (executable)
index 0000000..caa9627
--- /dev/null
@@ -0,0 +1,98 @@
+#!/usr/bin/python
+#
+# Copyright (C) 2014  Simo Sorce <simo@redhat.com>
+#
+# see file 'COPYING' for use and warranty information
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+import argparse
+import os
+import subprocess
+from string import Template
+
+
+logger = None
+
+
+def parse_args():
+    parser = argparse.ArgumentParser(description=\
+        'Run a test Ipsilon instance from the checkout directory')
+    parser.add_argument('--workdir', default=os.path.join(os.getcwd(), 'tmp'),
+                        help="Directory in which db/session files are stored")
+    return vars(parser.parse_args())
+
+
+CONF_TEMPLATE='''
+[global]
+debug = True
+
+log.screen = True
+base.mount = "/idp"
+base.dir = "${BASEDIR}"
+admin.config.db = "${ADMINDB}"
+user.prefs.db = "${USERSDB}"
+
+tools.sessions.on = True
+tools.sessions.storage_type = "file"
+tools.sessions.storage_path = "${WORKDIR}/sessions"
+tools.sessions.timeout = 60
+'''
+
+ADMIN_TEMPLATE='''
+CREATE TABLE login_config (name TEXT,option TEXT,value TEXT);
+INSERT INTO login_config VALUES('global', 'order', 'testauth');
+'''
+
+USERS_TEMPLATE='''
+CREATE TABLE users(name TEXT, option TEXT, value TEXT);
+INSERT INTO users VALUES('admin', 'is_admin', '1');
+'''
+
+if __name__ == '__main__':
+
+    args = parse_args()
+
+    penv = dict()
+    penv.update(os.environ)
+    penv['PYTHONPATH'] = './'
+
+    if not os.path.exists(args['workdir']):
+        os.makedirs(args['workdir'])
+        os.makedirs(os.path.join(args['workdir'], 'sessions'))
+
+    admin_db = os.path.join(args['workdir'], 'adminconfig.sqlite')
+    sql = os.path.join(args['workdir'], 'admin.sql')
+    with open(sql, 'w+') as f:
+        f.write(ADMIN_TEMPLATE)
+    subprocess.call(['sqlite3', '-init', sql, admin_db, '.quit'])
+
+    users_db = os.path.join(args['workdir'], 'users.sqlite')
+    sql = os.path.join(args['workdir'], 'users.sql')
+    with open(sql, 'w+') as f:
+        f.write(USERS_TEMPLATE)
+    subprocess.call(['sqlite3', '-init', sql, users_db, '.quit'])
+
+    t = Template(CONF_TEMPLATE)
+    text = t.substitute({'BASEDIR': os.getcwd(),
+                         'WORKDIR': args['workdir'],
+                         'ADMINDB': admin_db,
+                         'USERSDB': users_db})
+    conf = os.path.join(args['workdir'], 'ipsilon.conf')
+    with open(conf, 'w+') as f:
+        f.write(text)
+
+
+    p = subprocess.Popen(['./ipsilon/ipsilon', conf], env=penv)
+    p.wait()