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

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

setup.py, README: altered version info to post Alpha development
NDG/LogClient.py, SimpleCAClient.py and GatekeeperClient?.py: catch HTTPResponse error from ZSI ServiceProxy?. This
allows more error info for file not found type problems.

NDG/Session.py, NDG/CredWallet.py: use AttAuthorityClient? wrapper rather than direct calls to ZSI.

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
16from ZSI.wstools.Utility import HTTPResponse
17import sys
18import os
19
20from NDG.AttCert import *
21
22
23#_____________________________________________________________________________
24class GatekeeperClientError(Exception):
25    """Exception handling for Gatekeeper class"""
26    def __init__(self, msg):
27        self.__msg = msg
28         
29    def __str__(self):
30        return self.__msg
31
32
33#_____________________________________________________________________________
34class GatekeeperClient(object):
35   
36    #_________________________________________________________________________
37    def __init__(self, wsdl=None, traceFile=None):
38        """
39        wsdl:                  WSDL URI for Gatekeeper WS.  Setting
40                               it will set the Service Proxy
41        traceFile:             set to file object such as sys.stderr to
42                               give extra WS debug information"""
43
44        self.__srvPx = None
45        self.__wsdl = None
46       
47           
48        self.__traceFile = traceFile
49       
50        if wsdl: 
51            self.__setWSDL(wsdl)
52           
53            # Instantiate Gatekeeper WS proxy
54            self.serviceProxy()
55       
56
57    #_________________________________________________________________________
58    def __setWSDL(self, wsdl):
59       
60        if not isinstance(wsdl, basestring):
61            raise GatekeeperClientError(\
62                        "Gatekeeper WSDL URI must be a valid string")
63       
64        self.__wsdl = wsdl
65       
66    wsdl = property(fset=__setWSDL,doc="Set Gatekeeper WSDL URI")
67   
68       
69    #_________________________________________________________________________
70    def serviceProxy(self, wsdl=None):
71        """Set the WS proxy for the Gatekeeper"""
72        if wsdl:
73            self.__setWSDL(wsdl)
74
75        try:
76            self.__srvPx = ServiceProxy(self.__wsdl, 
77                                        use_wsdl=True, 
78                                        tracefile=self.__traceFile)
79        except HTTPResponse, e:
80            raise GatekeeperClientError, \
81                "Error initialising WSDL Service Proxy for \"%s\": %s %s" % \
82                (self.__wsdl, e.status, e.reason)
83               
84        except Exception, e:
85            raise GatekeeperClientError, \
86                    "Initialising WSDL Service Proxy: " + str(e)
87
88                                   
89    #_________________________________________________________________________
90    def readAccess(self, attCert=None, attCertFilePath=None):
91        """Check Gatekeeper for read access to resource
92       
93        Pass attCert as an AttCert instance, a string containing XML or set
94        a file path to attCertFilePath"""
95
96        try:
97            if attCertFilePath:
98                attCert = AttCertRead(attCertFilePath)
99               
100            # str call allows an AttCert type to be passed as well as string
101            # version
102            resp = self.__srvPx.readAccess(attCert=str(attCert))
103           
104        except Exception, e:
105            raise GatekeeperClientError("Error checking read access: "+str(e))
106                             
107        if resp['errMsg']:
108            raise GatekeeperClientError(resp['errMsg'])
109       
110        return resp['matchingRole']
111
112                                   
113    #_________________________________________________________________________
114    def writeAccess(self, attCert=None, attCertFilePath=None):
115        """Check Gatekeeper for write access to resource
116       
117        Pass attCert as an AttCert instance, a string containing XML or set
118        a file path to attCertFilePath"""
119
120        try:
121            if attCertFilePath:
122                attCert = AttCertRead(attCertFilePath)
123               
124            # str call allows an AttCert type to be passed as well as string
125            # version
126            resp = self.__srvPx.writeAccess(attCert=str(attCert))
127           
128        except Exception, e:
129            raise GatekeeperClientError,"Error checking write access: "+str(e)
130                             
131        if resp['errMsg']:
132            raise GatekeeperClientError(resp['errMsg'])
133       
134        return resp['matchingRole']
135
136                                   
137    #_________________________________________________________________________
138    def executeAccess(self, attCert=None, attCertFilePath=None):
139        """Check Gatekeeper for execute access to resource
140       
141        Pass attCert as an AttCert instance, a string containing XML or set
142        a file path to attCertFilePath"""
143
144        try:
145            if attCertFilePath:
146                attCert = AttCertRead(attCertFilePath)
147               
148            # str call allows an AttCert type to be passed as well as string
149            # version
150            resp = self.__srvPx.executeAccess(attCert=str(attCert))
151           
152        except Exception, e:
153            raise GatekeeperClientError,\
154                                    "Error checking execute access: " + str(e)
155                             
156        if resp['errMsg']:
157            raise GatekeeperClientError(resp['errMsg'])
158       
159        return resp['matchingRole']
160 
Note: See TracBrowser for help on using the repository browser.