From a06b990c66c32909b8872ac2f5d825c6b7316a3a Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 25 Aug 2014 16:40:21 -0400 Subject: [PATCH] Restore ability to run from checkout also adds quickrun.py script to make it easy. Signed-off-by: Simo Sorce Reviewed-by: Patrick Uiterwijk --- ipsilon/providers/saml2/admin.py | 13 +++-- quickrun.py | 98 ++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+), 6 deletions(-) create mode 100755 quickrun.py diff --git a/ipsilon/providers/saml2/admin.py b/ipsilon/providers/saml2/admin.py index 5d97126..1c62cac 100755 --- a/ipsilon/providers/saml2/admin.py +++ b/ipsilon/providers/saml2/admin.py @@ -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 index 0000000..caa9627 --- /dev/null +++ b/quickrun.py @@ -0,0 +1,98 @@ +#!/usr/bin/python +# +# Copyright (C) 2014 Simo Sorce +# +# 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 . + +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() -- 2.20.1