Add server-install plugin configuration support
authorSimo Sorce <simo@redhat.com>
Fri, 14 Mar 2014 22:08:49 +0000 (18:08 -0400)
committerSimo Sorce <simo@redhat.com>
Thu, 20 Mar 2014 15:34:08 +0000 (11:34 -0400)
Automatically find plugins installed in the system and exposes their
installation and configuration functions through the installer.

Signed-off-by: Simo Sorce <simo@redhat.com>
ipsilon/install/server.py
ipsilon/login/authkrb.py
ipsilon/login/authpam.py
ipsilon/login/common.py
ipsilon/providers/common.py
ipsilon/util/plugin.py

index f5d06b6..0018e10 100755 (executable)
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+from ipsilon.login.common import LoginMgrsInstall
+from ipsilon.providers.common import ProvidersInstall
 import argparse
+import sys
 
 
-def parse_args():
+def find_plugins():
+    plugins = {
+        'Login Managers': LoginMgrsInstall().plugins,
+        'Auth Providers': ProvidersInstall().plugins
+    }
+    return plugins
+
+
+def parse_args(plugins):
     parser = argparse.ArgumentParser(description='Ipsilon Install Options')
     parser.add_argument('--version',
                         action='version', version='%(prog)s 0.1')
+    parser.add_argument('-o', '--login-managers-order', dest='lm_order',
+                        help='Comma separated list of login managers')
+    parser.add_argument('--ipa', choices=['yes', 'no'], default='yes',
+                        help='Detect and use an IPA server for authentication')
+
+    lms = []
+
+    for plugin_group in plugins:
+        group = parser.add_argument_group(plugin_group)
+        for plugin_name in plugins[plugin_group]:
+            plugin = plugins[plugin_group][plugin_name]
+            if plugin.ptype == 'login':
+                lms.append(plugin.name)
+            plugin.install_args(group)
 
     args = vars(parser.parse_args())
 
+    if args['lm_order'] is None:
+        args['lm_order'] = []
+        for name in lms:
+            if args[name] == 'yes':
+                args['lm_order'].append(name)
+    else:
+        args['lm_order'] = args['lm_order'].split(',')
+
+    if len(args['lm_order']) == 0:
+        #force the basic pam provider if nothing else is selected
+        if 'pam' not in args:
+            parser.print_help()
+            sys.exit(-1)
+        args['lm_order'] = ['pam']
+        args['pam'] = 'yes'
+
     return args
 
 if __name__ == '__main__':
-    opts = parse_args()
+    found_plugins = find_plugins()
+    opts = parse_args(found_plugins)
     print opts
index 8069c6a..5b9163d 100755 (executable)
@@ -79,3 +79,18 @@ plugin for actual authentication. """
         self.page.__dict__['negotiate'] = KrbAuth(site, self)
         self.page.__dict__['unauthorized'] = KrbError(site, self)
         return self.page
+
+
+class Installer(object):
+
+    def __init__(self):
+        self.name = 'krb'
+        self.ptype = 'login'
+
+    def install_args(self, group):
+        group.add_argument('--krb', choices=['yes', 'no'], default='no',
+                           help='Configure Kerberos authentication')
+
+    def configure(self, opts):
+        if opts['krb'] != 'yes':
+            return
index 496a774..1eb697b 100755 (executable)
@@ -143,3 +143,24 @@ for authentication. """
     def get_tree(self, site):
         self.page = Pam(site, self)
         return self.page
+
+
+class Installer(object):
+
+    def __init__(self):
+        self.name = 'pam'
+        self.ptype = 'login'
+
+    def install_args(self, group):
+        group.add_argument('--pam', choices=['yes', 'no'], default='no',
+                           help='Configure PAM authentication')
+        group.add_argument('--pam-service', action='store', default='remote',
+                           help='PAM service name to use for authentication')
+
+    def configure(self, opts):
+        if opts['pam'] != 'yes':
+            return
+
+        if opts['pam_service'] != 'remote':
+            #TODO: add service_name in the database
+            return
index b7000b2..d290521 100755 (executable)
@@ -20,6 +20,7 @@
 from ipsilon.util.page import Page
 from ipsilon.util.user import UserSession
 from ipsilon.util.plugin import PluginLoader, PluginObject
+from ipsilon.util.plugin import PluginInstaller
 import cherrypy
 
 
@@ -124,3 +125,10 @@ class Logout(Page):
     def root(self, *args, **kwargs):
         UserSession().logout(self.user)
         return self._template('logout.html', title='Logout')
+
+
+class LoginMgrsInstall(object):
+
+    def __init__(self):
+        pi = PluginInstaller(LoginMgrsInstall)
+        self.plugins = pi.get_plugins()
index f8819c7..3b2072c 100755 (executable)
@@ -18,6 +18,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 from ipsilon.util.plugin import PluginLoader, PluginObject
+from ipsilon.util.plugin import PluginInstaller
 from ipsilon.util.page import Page
 import cherrypy
 
@@ -99,3 +100,10 @@ class LoadProviders(object):
     def _debug(self, fact):
         if cherrypy.config.get('debug', False):
             cherrypy.log(fact)
+
+
+class ProvidersInstall(object):
+
+    def __init__(self):
+        pi = PluginInstaller(ProvidersInstall)
+        self.plugins = pi.get_plugins()
index 5a517e4..fce058d 100755 (executable)
@@ -92,6 +92,16 @@ class PluginLoader(object):
         return self._plugins
 
 
+class PluginInstaller(object):
+    def __init__(self, baseobj):
+        (pathname, dummy) = os.path.split(inspect.getfile(baseobj))
+        self._pathname = pathname
+
+    def get_plugins(self):
+        p = Plugins()
+        return p.get_plugins(self._pathname, 'Installer')
+
+
 class PluginObject(object):
 
     def __init__(self):