source: TI12-security/trunk/NDGSecurity/python/Tests/MyProxyClient/MyProxyAdmin.py @ 7080

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/NDGSecurity/python/Tests/MyProxyClient/MyProxyAdmin.py@7080
Revision 7080, 3.0 KB checked in by pjkersha, 9 years ago (diff)
  • Property svn:executable set to *
  • Property svn:keywords set to Id
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) 2009 Science and Technology Facilities Council"
12__license__ = "BSD - see LICENSE file in top-level directory"
13__contact__ = "Philip.Kershaw@stfc.ac.uk"
14__revision__ = "$Id"
15
16# Handle socket errors from WS
17import socket 
18
19# Command line processing
20import sys
21import os
22import optparse
23import getpass
24
25
26from ndg.security.MyProxy import *
27
28
29#_____________________________________________________________________________
30if __name__ == '__main__':
31
32    parser = optparse.OptionParser()
33    parser.add_option("-n", 
34                      "--add-user", 
35                      dest="newUserName",
36                      help=\
37                      "add a new user to MyProxy with the username given")
38
39    parser.add_option("-f", 
40                      "--properties-file",
41                      dest="propFilePath",
42                      help=\
43"file path for MyProxy properties file - default is ./myProxyProperties.xml")
44
45    parser.add_option("-p",
46                      "--pass-phrase-from-stdin",
47                      action="store_true",
48                      dest="bPassPhraseFromStdin",
49                      default=False,
50                      help="""\
51Take user's pass-phrase from stdin.  If this flag is omitted, pass-phrase is
52prompted for from tty""")
53
54    (options, args) = parser.parse_args()
55
56
57    if not options.newUserName:
58        sys.stderr.write("No new username set.\n\n")
59        parser.print_help()
60        sys.exit(1)
61       
62       
63    if options.propFilePath is None:
64        # Check in installation area otherwise assume local directory
65        options.propFilePath = os.path.join(".", 'myProxyProperties.xml')
66
67
68    if options.bPassPhraseFromStdin:
69        # Read from standard input
70        passPhrase = sys.stdin.read().strip()           
71    else:
72        # Obtain from prompt
73        try:
74            passPhrase = getpass.getpass(prompt="New user pass-phrase: ") 
75            confirmPassPhrase = \
76                            getpass.getpass(prompt="Confirm pass-phrase: ")
77           
78            if confirmPassPhrase != passPhrase:
79                sys.stderr.write("Pass-phrases are not the same - exiting.\n")
80                sys.exit(1)
81               
82        except KeyboardInterrupt:
83            sys.exit(1)
84
85
86    # Create server instance at start up
87    try:
88        myPx = MyProxy(propFilePath=options.propFilePath)
89
90    except Exception, e:
91        sys.stderr.write("Initialising MyProxy client: %s\n\n" % str(e))
92        parser.print_help()
93        sys.exit(1)
94   
95    try:
96         myPx.addUser(options.newUserName, passPhrase)
97
98    except Exception, e:
99        sys.stderr.write("MyProxy client: %s\n\n" % str(e))
100        parser.print_help()
101        sys.exit(1)
102       
103    sys.exit(0)
Note: See TracBrowser for help on using the repository browser.