Add server-install plugin configuration support
[cascardo/ipsilon.git] / ipsilon / install / server.py
1 #!/usr/bin/python
2 #
3 # Copyright (C) 2014  Simo Sorce <simo@redhat.com>
4 #
5 # see file 'COPYING' for use and warranty information
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20 from ipsilon.login.common import LoginMgrsInstall
21 from ipsilon.providers.common import ProvidersInstall
22 import argparse
23 import sys
24
25
26 def find_plugins():
27     plugins = {
28         'Login Managers': LoginMgrsInstall().plugins,
29         'Auth Providers': ProvidersInstall().plugins
30     }
31     return plugins
32
33
34 def parse_args(plugins):
35     parser = argparse.ArgumentParser(description='Ipsilon Install Options')
36     parser.add_argument('--version',
37                         action='version', version='%(prog)s 0.1')
38     parser.add_argument('-o', '--login-managers-order', dest='lm_order',
39                         help='Comma separated list of login managers')
40     parser.add_argument('--ipa', choices=['yes', 'no'], default='yes',
41                         help='Detect and use an IPA server for authentication')
42
43     lms = []
44
45     for plugin_group in plugins:
46         group = parser.add_argument_group(plugin_group)
47         for plugin_name in plugins[plugin_group]:
48             plugin = plugins[plugin_group][plugin_name]
49             if plugin.ptype == 'login':
50                 lms.append(plugin.name)
51             plugin.install_args(group)
52
53     args = vars(parser.parse_args())
54
55     if args['lm_order'] is None:
56         args['lm_order'] = []
57         for name in lms:
58             if args[name] == 'yes':
59                 args['lm_order'].append(name)
60     else:
61         args['lm_order'] = args['lm_order'].split(',')
62
63     if len(args['lm_order']) == 0:
64         #force the basic pam provider if nothing else is selected
65         if 'pam' not in args:
66             parser.print_help()
67             sys.exit(-1)
68         args['lm_order'] = ['pam']
69         args['pam'] = 'yes'
70
71     return args
72
73 if __name__ == '__main__':
74     found_plugins = find_plugins()
75     opts = parse_args(found_plugins)
76     print opts