Skip to content

Commit 3d08f13

Browse files
committed
Add separate script to supply any site configured OpenID 2.0 discovery information as needed by the relying party verification mechanism. Deprecate old inline module execution way to extract the same as it's ugly and fragile. Minor polish on readconfval, which was used as a template for genoiddiscovery script.
git-svn-id: svn+ssh://svn.code.sf.net/p/migrid/code/trunk@6057 b75ad72c-e7d7-11dd-a971-7dbc132099af
1 parent a69107d commit 3d08f13

File tree

3 files changed

+124
-4
lines changed

3 files changed

+124
-4
lines changed

mig/server/genoiddiscovery.py

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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)

mig/server/readconfval.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# --- BEGIN_HEADER ---
55
#
66
# readconfval - Helper to easily lookup specific configuration values
7-
# Copyright (C) 2003-2023 The MiG Project lead by Brian Vinter
7+
# Copyright (C) 2003-2024 The MiG Project lead by Brian Vinter
88
#
99
# This file is part of MiG.
1010
#
@@ -29,6 +29,7 @@
2929
active MiGserver.conf . Used for extracting e.g. core paths in init scripts and
3030
other components outside the actual python code.
3131
"""
32+
3233
from __future__ import print_function
3334
from __future__ import absolute_import
3435

@@ -39,7 +40,7 @@
3940
from mig.shared.conf import get_configuration_object
4041

4142

42-
def usage(name='chkenabled.py'):
43+
def usage(name='readconfval.py'):
4344
"""Usage help"""
4445

4546
print("""Lookup a evaluated configuration value using MiGserver.conf.
@@ -58,7 +59,6 @@ def usage(name='chkenabled.py'):
5859
conf_path = None
5960
force = False
6061
verbose = False
61-
feature = 'UNSET'
6262
opt_args = 'c:fhv'
6363
try:
6464
(opts, args) = getopt.getopt(args, opt_args)

mig/shared/httpsclient.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# --- BEGIN_HEADER ---
55
#
66
# httpsclient - Shared functions for all HTTPS clients
7-
# Copyright (C) 2003-2022 The MiG Project lead by Brian Vinter
7+
# Copyright (C) 2003-2024 The MiG Project lead by Brian Vinter
88
#
99
# This file is part of MiG.
1010
#
@@ -624,8 +624,15 @@ def generate_openid_discovery_doc(configuration):
624624

625625

626626
if __name__ == "__main__":
627+
import time
627628
from mig.shared.conf import get_configuration_object
628629
conf = get_configuration_object()
630+
print()
631+
print("*** DEPRECATION WARNING ***")
632+
print("Please use dedicated mig/server/genoiddiscovery.py instead of %s!"
633+
% __file__)
634+
print()
635+
time.sleep(30)
629636
print("""OpenID discovery infomation XML which may be pasted into
630637
state/wwwpublic/oiddiscover.xml if site uses OpenId but doesn't enable the
631638
SID vhost:

0 commit comments

Comments
 (0)