source: security/trunk/python/AttAuthorityServer.py @ 537

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/security/trunk/python/AttAuthorityServer.py@537
Revision 537, 4.4 KB checked in by pjkersha, 14 years ago (diff)

Fixed typo: NDG.attauthority_services_server ->
NDG.attAuthority_services_server

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
RevLine 
[415]1#!/usr/bin/env python
2
3"""NDG Attribute Authority Web Services server interface
4
5NERC Data Grid Project
6
7P J Kershaw 05/05/05
8
9Copyright (C) 2005 CCLRC & NERC
10
11This software may be distributed under the terms of the Q Public License,
12version 1.0 or later.
13"""
14
15cvsID = '$Id$'
16
[485]17# Handle socket errors from WS
18import socket 
[457]19
[452]20# Command line processing
[433]21import sys
[452]22import os
23import getopt
[415]24
[532]25# Web service interface
26from ZSI import dispatch
27from ZSI.ServiceContainer import ServiceContainer, SOAPRequestHandler
28
29# Attribute Authority Web Services stub code generated by wsdl2py and
30# wsdl2dispatch
31from NDG.attAuthority_services import *
[537]32from NDG.attAuthority_services_server import attAuthority
[532]33
[452]34# Attribute Authority
[493]35from NDG.AttAuthority import *
[415]36
37
[532]38#_____________________________________________________________________________
39class SessionMgrSOAPRequestHandler(SOAPRequestHandler):
40     """Add a do_GET method to return the WSDL on HTTP GET requests.
41     Please note that the path to the wsdl file is derived from what
42     the HTTP invocation delivers (which is put into the self.path
43     attribute), so you might want to change this addressing scheme.
44     """
45     def do_GET(self):
46           """Return the WSDL file. We expect to get the location from the
47           invocation URL ("path").
48           """
49           wsdlfile = os.path.join('.', 
50                                   self.path.replace('/', "", 1) + ".wsdl")
51           print "> > > > > using wsdlfile", wsdlfile
52           wsdl = open(wsdlfile).read()
53           self.send_xml(wsdl)
54       
55       
56#_____________________________________________________________________________
57# Copied from ZSI.ServiceContainer, extended to instantiate with a custom
58# request handler
59def AsServer(port=80, services=(), RequestHandlerClass=SOAPRequestHandler):
60      """port --
61          services -- list of service instances
62       """
63      address = ("127.0.0.1", port)
64      sc = ServiceContainer(address, RequestHandlerClass=RequestHandlerClass)
65      for service in services:
66           path = service.getPost()
67           sc.setNode(service, path)
68      sc.serve_forever()
[460]69
[474]70
[452]71def usage():
[474]72    """Describes how to call AttAuthorityServer from the command line"""
[452]73    print "usage: %s " % sys.argv[0].split(os.sep)[-1]
74    print """   
75[-h | --help]
76    print usage summary
77   
78[-f <properties file path> | --file=<properties file path>]
79
[457]80[-p <port #> | --port=<port #>
81    specify a port number to override the default
82   
[452]83[-d | --debug]
84    set to stop in debugger on receipt of WS request
85"""
86
87
[532]88#_____________________________________________________________________________
[415]89if __name__ == '__main__':
[452]90
91    try:
92        opts, args = getopt.getopt(sys.argv[1:],
[456]93                                   "hf:p:d",
94                                   ["help", "file=", "port=", "debug"])       
[452]95    except getopt.GetoptError:
96        usage()
97        sys.exit(1)
98
99
100    propFilePath = None
[456]101    port = 5000 #80 # temporary port for testing
[475]102    debug = False
[433]103   
[452]104    for opt, arg in opts:
105        if opt in ("-h", "--help"):
106            usage()                     
107            sys.exit(0)
108           
109        elif opt in ("-d", "--debug"):
[475]110            debug = True
[452]111           
112        elif opt in ("-f", "--file"):
113            propFilePath = arg
114
[456]115        elif opt in ("-p", "--port"):
[464]116            port = int(arg)
[452]117
118    if propFilePath is None:
119        # Check in installation area otherwise assume local directory
120        if 'NDG_DIR' in os.environ:
[495]121            propFileDir = os.path.join(os.environ['NDG_DIR'], "conf")
[452]122        else:
[495]123            propFileDir = "."
[452]124
[495]125        propFilePath = os.path.join(propFileDir, 'attAuthorityProperties.xml')
[452]126
127       
128    # Create server instance at start up
129    try:
[474]130        aa = AttAuthority(propFilePath)
[457]131
[452]132    except Exception, e:
133        sys.stderr.write("Initialising Attribute Authority: %s\n" % e)
134        sys.exit(1)
135   
136    print "Attribute Authority Server listening..."
137    try:
[532]138         AsServer(port=port, 
139                  services=[attAuthority(aa, debug=debug)], 
140                  RequestHandlerClass=SessionMgrSOAPRequestHandler)
[452]141
142    except KeyboardInterrupt:
[456]143        sys.exit(0)
[452]144
[485]145    except socket.error, e:
146        sys.stderr.write("Attribute Authority Server socket error: %s\n" % \
147                         e[1])
148        sys.exit(1)
149       
[452]150    except Exception, e:
[464]151        sys.stderr.write("Attribute Authority Server: %s\n" % e)
[452]152        sys.exit(1)
153       
Note: See TracBrowser for help on using the repository browser.