Changeset c922f23
- Timestamp:
- Nov 19, 2008 7:24:16 PM (16 years ago)
- Branches:
- axis_example, compt_changes, info-ops, master, version-1.30, version-2.00, version-3.01, version-3.02
- Children:
- 058f58e
- Parents:
- dab4d56
- Location:
- fedd
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
fedd/fedd_access.py
rdab4d56 rc922f23 51 51 "dynamic_projects_cert_pwd", "dynamic_projects_trusted_certs") 52 52 id_list_attrs = ("restricted",) 53 54 proxy_request, proxy_xmlrpc_request = make_service_callers('RequestAccess', 55 'getfeddPortType', RequestAccessRequestMessage, 56 'RequestAccessRequestBody') 53 57 54 58 def __init__(self, config=None): … … 387 391 self.log.warning(("[read_state]: No saved state: " + \ 388 392 "Unpickling failed: %s") % e) 389 390 391 def proxy_xmlrpc_request(self, dt, req):392 """Send an XMLRPC proxy request. Called if the SOAP RPC fails"""393 394 # No retry loop here. Proxy servers must correctly authenticate395 # themselves without help396 try:397 ctx = fedd_ssl_context(self.proxy_cert_file,398 self.proxy_trusted_certs, password=self.proxy_cert_pwd)399 except SSL.SSLError:400 raise service_error(service_error.server_config,401 "Server certificates misconfigured")402 403 # Of all the dumbass things. The XMLRPC library in use here won't404 # properly encode unicode strings, so we make a copy of req with the405 # unicode objects converted. We also convert the destination testbed406 # to a basic string if it isn't one already.407 if isinstance(dt, str): url = dt408 else: url = str(dt)409 410 r = strip_unicode(copy.deepcopy(req))411 412 transport = SSL_Transport(ctx)413 port = xmlrpclib.ServerProxy(url, transport=transport)414 415 # Reconstruct the full request message416 try:417 resp = port.RequestAccess(418 { "RequestAccessRequestBody": r})419 resp, method = xmlrpclib.loads(resp)420 except xmlrpclib.Fault, f:421 se = service_error(None, f.faultString, f.faultCode)422 raise se423 except xmlrpclib.Error, e:424 raise service_error(service_error.proxy,425 "Remote XMLRPC Fault: %s" % e)426 427 if resp[0].has_key('RequestAccessResponseBody'):428 return resp[0]['RequestAccessResponseBody']429 else:430 raise service_error(service_error.proxy,431 "Bad proxy response")432 433 def proxy_request(self, dt, req):434 """435 Send req on to the real destination in dt and return the response436 437 Req is just the requestType object. This function re-wraps it. It438 also rethrows any faults.439 """440 # No retry loop here. Proxy servers must correctly authenticate441 # themselves without help442 try:443 ctx = fedd_ssl_context(self.proxy_cert_file,444 self.proxy_trusted_certs, password=self.proxy_cert_pwd)445 except SSL.SSLError:446 raise service_error(service_error.server_config,447 "Server certificates misconfigured")448 449 loc = feddServiceLocator();450 port = loc.getfeddPortType(dt,451 transport=M2Crypto.httpslib.HTTPSConnection,452 transdict={ 'ssl_context' : ctx })453 454 # Reconstruct the full request message455 msg = RequestAccessRequestMessage()456 msg.set_element_RequestAccessRequestBody(457 pack_soap(msg, "RequestAccessRequestBody", req))458 try:459 resp = port.RequestAccess(msg)460 except ZSI.ParseException, e:461 raise service_error(service_error.proxy,462 "Bad format message (XMLRPC??): %s" %463 str(e))464 r = unpack_soap(resp)465 466 if r.has_key('RequestAccessResponseBody'):467 return r['RequestAccessResponseBody']468 else:469 raise service_error(service_error.proxy,470 "Bad proxy response")471 393 472 394 def permute_wildcards(self, a, p): … … 779 701 try: 780 702 # Proxy the request using SOAP 781 return self.proxy_request(dt, req) 703 self.log.debug("Sending proxy message to %s" % dt) 704 resp = self.proxy_request(dt, req, feddServiceLocator, 705 self.proxy_cert_file, self.proxy_cert_pwd, 706 self.proxy_trusted_certs) 707 if resp.has_key('RequestAccessResponseBody'): 708 return resp['RequestAccessResponseBody'] 709 elif resp.has_key('Fedd_FaultBody'): 710 raise service_error(resp['FeddFaultBody']['code'], 711 resp['FeddFaultBody']['desc']) 782 712 except service_error, e: 783 713 if e.code == service_error.proxy: p_fault = None … … 791 721 # out. 792 722 if p_fault == None: 793 return self.proxy_xmlrpc_request(dt, req) 723 resp = self.proxy_xmlrpc_request(dt, req, self.proxy_cert_file, 724 self.proxy_cert_pwd, self.proxy_trusted_certs) 725 if resp.has_key('RequestAccessResponseBody'): 726 return resp['RequestAccessResponseBody'] 794 727 else: 795 728 # Build the fault -
fedd/fedd_util.py
rdab4d56 rc922f23 5 5 import tempfile 6 6 import logging 7 import copy 7 8 8 9 from M2Crypto import SSL, X509, EVP 10 from M2Crypto.m2xmlrpclib import SSL_Transport 11 import M2Crypto.httpslib 9 12 from pyasn1.codec.der import decoder 10 13 11 from xmlrpclib import Binary 14 from fedd_services import * 15 from fedd_internal_services import * 16 from service_error import * 17 from xmlrpclib import ServerProxy, dumps, loads, Fault, Error, Binary 12 18 13 19 … … 413 419 decap_fedids = (('fedid', lambda x: fedid(bits=x.data)),) 414 420 415 #p = decapsulate_binaries(params[0], input_binaries)416 421 p = apply_to_tags(params[0], decap_fedids) 417 422 msg = method(p, fid) 418 423 419 424 if msg != None: 420 return encapsulate_binaries({ body_name: msg }, ('fedid',))425 return make_unicode(encapsulate_binaries({ body_name: msg }, ('fedid',))) 421 426 else: 422 427 return None … … 424 429 return handler 425 430 431 def make_service_callers(service_name, port_name, request_message, 432 request_body_name): 433 434 def call_xmlrpc_service(self, url, req, cert_file=None, cert_pwd=None, 435 trusted_certs=None): 436 """Send an XMLRPC request. """ 437 decap_fedids = (('fedid', lambda x: fedid(bits=x.data)),) 438 439 # No retry loop here. Proxy servers must correctly authenticate 440 # themselves without help 441 try: 442 ctx = fedd_ssl_context(cert_file, trusted_certs, password=cert_pwd) 443 except SSL.SSLError: 444 raise service_error(service_error.server_config, 445 "Server certificates misconfigured") 446 447 # Of all the dumbass things. The XMLRPC library in use here won't 448 # properly encode unicode strings, so we make a copy of req with the 449 # unicode objects converted. We also convert the url to a basic string 450 # if it isn't one already. 451 r = strip_unicode(copy.deepcopy(req)) 452 url = str(url) 453 454 transport = SSL_Transport(ctx) 455 port = ServerProxy(url, transport=transport) 456 try: 457 remote_method = getattr(port, service_name, None) 458 resp = remote_method(encapsulate_binaries({ request_body_name: r}, 459 ('fedid',))) 460 except Fault, f: 461 raise service_error(None, f.faultString, f.faultCode) 462 except Error, e: 463 raise service_error(service_error.proxy, 464 "Remote XMLRPC Fault: %s" % e) 465 466 return apply_to_tags(resp, decap_fedids) 467 468 def call_soap_service(self, url, req, loc_const, cert_file=None, cert_pwd=None, 469 trusted_certs=None): 470 """ 471 Send req on to the real destination in dt and return the response 472 473 Req is just the requestType object. This function re-wraps it. It 474 also rethrows any faults. 475 """ 476 # No retry loop here. Proxy servers must correctly authenticate 477 # themselves without help 478 try: 479 ctx = fedd_ssl_context(cert_file, trusted_certs, password=cert_pwd) 480 except SSL.SSLError: 481 raise service_error(service_error.server_config, 482 "Server certificates misconfigured") 483 484 loc = loc_const() 485 get_port = getattr(loc, port_name, None) 486 if not get_port: 487 raise service_error(service_error.internal, 488 "Cannot get port %s from locator" % port_name) 489 port = get_port(url, 490 transport=M2Crypto.httpslib.HTTPSConnection, 491 transdict={ 'ssl_context' : ctx }) 492 remote_method = getattr(port, service_name, None) 493 if not remote_method: 494 raise service_error(service_error.internal, 495 "Cannot get service from SOAP port") 496 497 # Reconstruct the full request message 498 msg = request_message() 499 set_element = getattr(msg, "set_element_%s" % request_body_name, None) 500 if not set_element: 501 raise service_error(service_error.internal, 502 "Cannot get element setting method for %s" % \ 503 request_body_name) 504 set_element(pack_soap(msg, request_body_name, req)) 505 try: 506 resp = remote_method(msg) 507 except ZSI.ParseException, e: 508 raise service_error(service_error.proxy, 509 "Bad format message (XMLRPC??): %s" % 510 str(e)) 511 r = unpack_soap(resp) 512 return r 513 514 return (call_soap_service, call_xmlrpc_service) 426 515 427 516 def set_log_level(config, sect, log):
Note: See TracChangeset
for help on using the changeset viewer.