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

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/python/Tests/MyProxyClient/MyProxyAdmin.py@4839
Revision 4839, 3.0 KB checked in by pjkersha, 12 years ago (diff)

Changed licence from Q Public to BSD

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