1 | #!/usr/local/bin/python |
---|
2 | |
---|
3 | import fedd_abac_services |
---|
4 | #import fedd_services |
---|
5 | import remote_service |
---|
6 | from fedd_services import CreateRequestMessage |
---|
7 | from M2Crypto import SSL |
---|
8 | from remote_service import service_caller |
---|
9 | from service_error import service_error |
---|
10 | from server import soap_handler |
---|
11 | |
---|
12 | # Turn off the matching of hostname to certificate ID |
---|
13 | SSL.Connection.clientPostConnectionCheck = None |
---|
14 | |
---|
15 | class abac_soap_handler(soap_handler): |
---|
16 | """ |
---|
17 | Encapsulate the handler code to unpack and pack SOAP requests and |
---|
18 | responses and call the given method. |
---|
19 | |
---|
20 | The code to decapsulate and encapsulate parameters encoded in SOAP is the |
---|
21 | same modulo a few parameters. This is a functor that calls a fedd service |
---|
22 | trhough a soap interface. The parameters are the typecode of the request |
---|
23 | parameters, the method to call (usually a bound instance of a method on a |
---|
24 | fedd service providing class), the constructor of a response packet and |
---|
25 | name of the body element of that packet. The handler takes a ParsedSoap |
---|
26 | object (the request) and returns an instance of the class created by |
---|
27 | constructor containing the response. Failures of the constructor or badly |
---|
28 | created constructors will result in None being returned. |
---|
29 | """ |
---|
30 | |
---|
31 | def get_class(self, class_name): |
---|
32 | return getattr(fedd_abac_services, class_name, None) or \ |
---|
33 | getattr(fedd_abac_internal_services, class_name, None) |
---|
34 | |
---|
35 | |
---|
36 | class abac_service_caller(service_caller): |
---|
37 | def __init__(self, service_name, request_message=None, |
---|
38 | request_body_name=None, tracefile=None): |
---|
39 | self.service_name = service_name |
---|
40 | |
---|
41 | if getattr(fedd_abac_services.feddABACBindingSOAP, service_name, None): |
---|
42 | self.locator = fedd_abac_services.feddABACServiceLocator |
---|
43 | self.port_name = 'getfeddABACPortType' |
---|
44 | # feddABAC has no internal implementation but might in the future |
---|
45 | # elif getattr(fedd_internal_services.feddInternalBindingSOAP, |
---|
46 | # service_name, None): |
---|
47 | # self.locator = fedd_internal_services.feddInternalServiceLocator |
---|
48 | # self.port_name = 'getfeddABACInternalPortType' |
---|
49 | |
---|
50 | if request_message: self.request_message = request_message |
---|
51 | else: |
---|
52 | request_message_name = "%sRequestMessage" % service_name |
---|
53 | self.request_message = \ |
---|
54 | getattr(fedd_abac_services, request_message_name, None) # or \ |
---|
55 | # getattr(fedd_internal_services, request_message_name, None) |
---|
56 | if not self.request_message: |
---|
57 | raise service_error(service_error.internal, |
---|
58 | "Cannot find class for %s" % request_message_name) |
---|
59 | |
---|
60 | if request_body_name: self.request_body_name = request_body_name |
---|
61 | else: self.request_body_name = "%sRequestBody" % service_name |
---|
62 | |
---|
63 | self.tracefile = tracefile |
---|
64 | self.__call__ = self.call_service |
---|
65 | |
---|