source: TI12-security/trunk/python/NDG/GatekeeperClient.py @ 968

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/python/NDG/GatekeeperClient.py@968
Revision 968, 5.1 KB checked in by pjkersha, 13 years ago (diff)

Tests/GatekeeperClientTest?.py: test Gatekeeper WS client.

Tests/AttAuthorityClientTest?.py: renamed methods so that called automatically when script is
invoked with no args.

Tests/SecurityClientTest?.py: set user to 'laurence' in order to get ACs with more roles set.

bin/LogServer.py: typo fix logs -> log

bin/GatekeeperServer.py: working version

NDG/TestGatekeeperResrc.py: test harness for Gatekeeper resource interface

NDG/gatekeeper_services_server.py: working but logic for returning matching roles needs fixing.

NDG/GatekeeperClient.py: client interface class to Gatekeeper WS.

NDG/Gatekeeper.py: working version

NDG/gatekeeper_services.py: regenerated following changes to WSDL.

Line 
1#!/usr/bin/env python
2
3"""NDG Gatekeeper client - client interface class to NDG Gatekeeper WS
4
5NERC Data Grid Project
6
7P J Kershaw 19/05/06
8
9Copyright (C) 2006 CCLRC & NERC
10
11This software may be distributed under the terms of the Q Public License,
12version 1.0 or later.
13"""
14
15from ZSI import ServiceProxy
16import sys
17import os
18
19from NDG.AttCert import *
20
21
22#_____________________________________________________________________________
23class GatekeeperClientError(Exception):
24    """Exception handling for Gatekeeper class"""
25    def __init__(self, msg):
26        self.__msg = msg
27         
28    def __str__(self):
29        return self.__msg
30
31
32#_____________________________________________________________________________
33class GatekeeperClient(object):
34   
35    #_________________________________________________________________________
36    def __init__(self, wsdl=None, traceFile=None):
37        """
38        wsdl:                  WSDL URI for Gatekeeper WS.  Setting
39                               it will set the Service Proxy
40        traceFile:             set to file object such as sys.stderr to
41                               give extra WS debug information"""
42
43        self.__srvPx = None
44        self.__wsdl = None
45       
46           
47        self.__traceFile = traceFile
48       
49        if wsdl: 
50            self.__setWSDL(wsdl)
51           
52            # Instantiate Gatekeeper WS proxy
53            self.serviceProxy()
54       
55
56    #_________________________________________________________________________
57    def __setWSDL(self, wsdl):
58       
59        if not isinstance(wsdl, basestring):
60            raise GatekeeperClientError(\
61                        "Gatekeeper WSDL URI must be a valid string")
62       
63        self.__wsdl = wsdl
64       
65    wsdl = property(fset=__setWSDL,doc="Set Gatekeeper WSDL URI")
66   
67       
68    #_________________________________________________________________________
69    def serviceProxy(self, wsdl=None):
70        """Set the WS proxy for the Gatekeeper"""
71        if wsdl:
72            self.__setWSDL(wsdl)
73
74        try:
75            self.__srvPx = ServiceProxy(self.__wsdl, 
76                                        use_wsdl=True, 
77                                        tracefile=self.__traceFile)
78        except Exception, e:
79            raise GatekeeperClientError(\
80                    "Initialising WSDL Service Proxy: " + str(e))
81
82                                   
83    #_________________________________________________________________________
84    def readAccess(self, attCert=None, attCertFilePath=None):
85        """Check Gatekeeper for read access to resource
86       
87        Pass attCert as an AttCert instance, a string containing XML or set
88        a file path to attCertFilePath"""
89
90        try:
91            if attCertFilePath:
92                attCert = AttCertRead(attCertFilePath)
93               
94            # str call allows an AttCert type to be passed as well as string
95            # version
96            resp = self.__srvPx.readAccess(attCert=str(attCert))
97           
98        except Exception, e:
99            raise GatekeeperClientError("Error checking read access: "+str(e))
100                             
101        if resp['errMsg']:
102            raise GatekeeperClientError(resp['errMsg'])
103       
104        return resp['matchingRole']
105
106                                   
107    #_________________________________________________________________________
108    def writeAccess(self, attCert=None, attCertFilePath=None):
109        """Check Gatekeeper for write access to resource
110       
111        Pass attCert as an AttCert instance, a string containing XML or set
112        a file path to attCertFilePath"""
113
114        try:
115            if attCertFilePath:
116                attCert = AttCertRead(attCertFilePath)
117               
118            # str call allows an AttCert type to be passed as well as string
119            # version
120            resp = self.__srvPx.writeAccess(attCert=str(attCert))
121           
122        except Exception, e:
123            raise GatekeeperClientError,"Error checking write access: "+str(e)
124                             
125        if resp['errMsg']:
126            raise GatekeeperClientError(resp['errMsg'])
127       
128        return resp['matchingRole']
129
130                                   
131    #_________________________________________________________________________
132    def executeAccess(self, attCert=None, attCertFilePath=None):
133        """Check Gatekeeper for execute access to resource
134       
135        Pass attCert as an AttCert instance, a string containing XML or set
136        a file path to attCertFilePath"""
137
138        try:
139            if attCertFilePath:
140                attCert = AttCertRead(attCertFilePath)
141               
142            # str call allows an AttCert type to be passed as well as string
143            # version
144            resp = self.__srvPx.executeAccess(attCert=str(attCert))
145           
146        except Exception, e:
147            raise GatekeeperClientError,\
148                                    "Error checking execute access: " + str(e)
149                             
150        if resp['errMsg']:
151            raise GatekeeperClientError(resp['errMsg'])
152       
153        return resp['matchingRole']
154 
Note: See TracBrowser for help on using the repository browser.