source: TI12-security/branches/0.9.2_dev_r3994/python/bin/MyProxyAdmin.py @ 2909

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/branches/0.9.2_dev_r3994/python/bin/MyProxyAdmin.py@6647
Revision 2909, 3.0 KB checked in by pjkersha, 13 years ago (diff)

Updated for epydoc: added double underscore vars module info

  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2
3"""NDG MyProxy admin command line interface - enables new users to be
4registered with NDG CA and added to the MyProxy repository.  This command
5must be run from the MyProxy host.
6
7NERC Data Grid Project
8"""
9__author__ = "P J Kershaw"
10__date__ = "19/05/06"
11__copyright__ = "(C) 2007 STFC & NERC"
12__license__ = \
13"""This software may be distributed under the terms of the Q Public
14License, version 1.0 or later."""
15__contact__ = "P.J.Kershaw@rl.ac.uk"
16__revision__ = "$Id"
17
18# Handle socket errors from WS
19import socket 
20
21# Command line processing
22import sys
23import os
24import optparse
25import getpass
26
27
28from ndg.security.MyProxy import *
29
30
31#_____________________________________________________________________________
32if __name__ == '__main__':
33
34    parser = optparse.OptionParser()
35    parser.add_option("-n", 
36                      "--add-user", 
37                      dest="newUserName",
38                      help=\
39                      "add a new user to MyProxy with the username given")
40
41    parser.add_option("-f", 
42                      "--properties-file",
43                      dest="propFilePath",
44                      help=\
45"file path for MyProxy properties file - default is ./myProxyProperties.xml")
46
47    parser.add_option("-p",
48                      "--pass-phrase-from-stdin",
49                      action="store_true",
50                      dest="bPassPhraseFromStdin",
51                      default=False,
52                      help="""\
53Take user's pass-phrase from stdin.  If this flag is omitted, pass-phrase is
54prompted for from tty""")
55
56    (options, args) = parser.parse_args()
57
58
59    if not options.newUserName:
60        sys.stderr.write("No new username set.\n\n")
61        parser.print_help()
62        sys.exit(1)
63       
64       
65    if options.propFilePath is None:
66        # Check in installation area otherwise assume local directory
67        options.propFilePath = os.path.join(".", 'myProxyProperties.xml')
68
69
70    if options.bPassPhraseFromStdin:
71        # Read from standard input
72        passPhrase = sys.stdin.read().strip()           
73    else:
74        # Obtain from prompt
75        try:
76            passPhrase = getpass.getpass(prompt="New user pass-phrase: ") 
77            confirmPassPhrase = \
78                            getpass.getpass(prompt="Confirm pass-phrase: ")
79           
80            if confirmPassPhrase != passPhrase:
81                sys.stderr.write("Pass-phrases are not the same - exiting.\n")
82                sys.exit(1)
83               
84        except KeyboardInterrupt:
85            sys.exit(1)
86
87
88    # Create server instance at start up
89    try:
90        myPx = MyProxy(propFilePath=options.propFilePath)
91
92    except Exception, e:
93        sys.stderr.write("Initialising MyProxy client: %s\n\n" % str(e))
94        parser.print_help()
95        sys.exit(1)
96   
97    try:
98         myPx.addUser(options.newUserName, passPhrase)
99
100    except Exception, e:
101        sys.stderr.write("MyProxy client: %s\n\n" % str(e))
102        parser.print_help()
103        sys.exit(1)
104       
105    sys.exit(0)
Note: See TracBrowser for help on using the repository browser.