|
| 1 | +#!/usr/bin/python |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | +# |
| 4 | +# --- BEGIN_HEADER --- |
| 5 | +# |
| 6 | +# genoiddiscovery - Helper to easily generate openid discovery info xml |
| 7 | +# Copyright (C) 2003-2024 The MiG Project by the Science HPC Center at UCPH |
| 8 | +# |
| 9 | +# This file is part of MiG. |
| 10 | +# |
| 11 | +# MiG is free software: you can redistribute it and/or modify |
| 12 | +# it under the terms of the GNU General Public License as published by |
| 13 | +# the Free Software Foundation; either version 2 of the License, or |
| 14 | +# (at your option) any later version. |
| 15 | +# |
| 16 | +# MiG is distributed in the hope that it will be useful, |
| 17 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | +# GNU General Public License for more details. |
| 20 | +# |
| 21 | +# You should have received a copy of the GNU General Public License |
| 22 | +# along with this program; if not, write to the Free Software |
| 23 | +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 24 | +# |
| 25 | +# -- END_HEADER --- |
| 26 | +# |
| 27 | + |
| 28 | +"""Helper to generate the discovery information for the OpenID 2.0 relying |
| 29 | +party verification mechanism. Please refer to the generate_openid_discovery_doc |
| 30 | +helper function for details. |
| 31 | +""" |
| 32 | + |
| 33 | +from __future__ import print_function |
| 34 | +from __future__ import absolute_import |
| 35 | + |
| 36 | +import getopt |
| 37 | +import os |
| 38 | +import sys |
| 39 | + |
| 40 | +from mig.shared.conf import get_configuration_object |
| 41 | +from mig.shared.httpsclient import generate_openid_discovery_doc |
| 42 | + |
| 43 | + |
| 44 | +def usage(name='genoiddiscovery.py'): |
| 45 | + """Usage help""" |
| 46 | + |
| 47 | + print("""Generate OpenID 2.0 discovery information for this site. |
| 48 | +Usage: |
| 49 | +%(name)s [OPTIONS] NAME |
| 50 | +Where OPTIONS may be one or more of: |
| 51 | + -c CONF_FILE Use CONF_FILE as server configuration |
| 52 | + -f Force operations to continue past errors |
| 53 | + -h Show this help |
| 54 | + -v Verbose output |
| 55 | +""" % {'name': name}) |
| 56 | + |
| 57 | + |
| 58 | +if '__main__' == __name__: |
| 59 | + args = sys.argv[1:] |
| 60 | + conf_path = None |
| 61 | + force = False |
| 62 | + verbose = False |
| 63 | + opt_args = 'c:fhv' |
| 64 | + try: |
| 65 | + (opts, args) = getopt.getopt(args, opt_args) |
| 66 | + except getopt.GetoptError as err: |
| 67 | + print('Error: ', err.msg) |
| 68 | + usage() |
| 69 | + sys.exit(1) |
| 70 | + |
| 71 | + for (opt, val) in opts: |
| 72 | + if opt == '-c': |
| 73 | + conf_path = val |
| 74 | + elif opt == '-f': |
| 75 | + force = True |
| 76 | + elif opt == '-h': |
| 77 | + usage() |
| 78 | + sys.exit(0) |
| 79 | + elif opt == '-v': |
| 80 | + verbose = True |
| 81 | + else: |
| 82 | + print('Error: %s not supported!' % opt) |
| 83 | + |
| 84 | + if conf_path and not os.path.isfile(conf_path): |
| 85 | + print('Failed to read configuration file: %s' % conf_path) |
| 86 | + sys.exit(1) |
| 87 | + |
| 88 | + if verbose: |
| 89 | + if conf_path: |
| 90 | + print('using configuration in %s' % conf_path) |
| 91 | + else: |
| 92 | + print('using configuration from MIG_CONF (or default)') |
| 93 | + |
| 94 | + if args: |
| 95 | + print('Got unexpected non-option arguments!') |
| 96 | + usage() |
| 97 | + sys.exit(1) |
| 98 | + |
| 99 | + if verbose: |
| 100 | + print("""OpenID discovery information XML which may be pasted into |
| 101 | +state/wwwpublic/oiddiscover.xml if site uses OpenId but doesn't enable the |
| 102 | +SID vhost: |
| 103 | +""") |
| 104 | + retval = 42 |
| 105 | + try: |
| 106 | + configuration = get_configuration_object(skip_log=True) |
| 107 | + print(generate_openid_discovery_doc(configuration)) |
| 108 | + retval = 0 |
| 109 | + except Exception as err: |
| 110 | + print(err) |
| 111 | + sys.exit(1) |
| 112 | + |
| 113 | + sys.exit(retval) |
0 commit comments