general improvements + swaped sudsds for suds (untested)

migr_to_spyne
idziubenko 3 years ago
parent 3407d3420f
commit bdbe108991

@ -5,7 +5,8 @@ INSTALL
calculate-api needs the following library version installed, in order to run:
python >= 2.6
soaplib = 1.0
soaplib = 2.13
calculate-lib >= 3.0.0_beta2.0
To install calculate-api, just execute the install script 'setup.py'.

@ -98,7 +98,8 @@ def client_post_request(cert_path, by_host):
return 1
url = "https://%s:%d/?wsdl" % (by_host, port)
print url + '\n' + _("connecting...")
from sudsds.client import Client
# from sudsds.client import Client
from suds.client import Client
# try:
client = Client(url, transport=HTTPSClientCertTransport(None, None,
cert_path))
@ -152,7 +153,8 @@ def client_get_cert(cert_path, args):
url = "https://%s:%d/?wsdl" % (args.from_host, port)
print url + '\n' + _("connecting...")
from sudsds.client import Client
# from sudsds.client import Client
from suds.client import Client
try:
client = Client(url, transport=HTTPSClientCertTransport(None, None,

@ -14,8 +14,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from sudsds import WebFault
from sudsds.transport import TransportError
# from sudsds import WebFault
# from sudsds.transport import TransportError
from suds.transport import TransportError
from suds import WebFault
import logging
from calculate.console.application.client_class import Client_suds

@ -17,8 +17,9 @@
import urllib2 as u2
import os
import sys
from sudsds.transport.http import HttpTransport
import httplib
# from sudsds.transport.http import HttpTransport
from suds.transport.http import HttpTransport
import httplib #http.client in python3
from httplib import HTTPConnection
import socket
import ssl
@ -26,7 +27,8 @@ import hashlib
from calculate.core.datavars import DataVarsCore
from calculate.lib.datavars import DataVars
from calculate.lib.utils.files import readFile
from sudsds.client import Client
# from sudsds.client import Client
from suds.client import Client
from cert_verify import verify, get_CRL
if hasattr(ssl, "PROTOCOL_TLSv1_2"):

@ -16,9 +16,9 @@
import os
import sys
import sudsds
# import sudsds
from suds import MethodNotFound
from calculate.core.server.cert_cmd import getHwAddr, getIpLocal
_ = lambda x: x
from calculate.lib.cl_lang import setLocalTranslate
@ -77,7 +77,7 @@ def create_obj(client, method_name):
info = operation.methods.get(method_name)
if not info:
raise sudsds.MethodNotFound(method_name)
raise MethodNotFound(method_name)
type_op = info.binding.input.param_defs(info)[param][inf_param]
str_type = type_op.type[param_type]

@ -17,17 +17,11 @@
import os
import sys
# from soaplib.service import rpc
from spyne import rpc
# from soaplib.service import DefinitionBase
from spyne import Service
# from soaplib.serializers.primitive import String, Integer
from spyne import String, Integer
# from soaplib.serializers.clazz import Array
from spyne import Array
from spyne import String, Integer, Array
from calculate.core.server.core_interfaces import CoreServiceInterface
from calculate.lib.utils.files import readFile
@ -228,41 +222,7 @@ class Basic(Service, CoreServiceInterface):
print '\n' + _('All processes are closed.')
return 0
time.sleep(0.5)
# #for debugging:
# knock_answer = "who's there?"
# @rpc(_returns=String)
# def knock(ctx):
# return Basic.comb_class_ref.knock_answer
# test_global_number = 1
# @classmethod
# def get_global_number(cls):
# return cls.test_global_number
# @classmethod
# def set_global_number(cls, num):
# if(not num):
# cls.test_global_number = 0
# else:
# cls.test_global_number = num
# return cls.test_global_number
# @rpc(Integer, _returns=Integer)
# def set_test_number(ctx, num):
# return Basic.set_global_number(num)
# @rpc(_returns=Integer)
# def get_test_number(ctx):
# return Basic.get_global_number()
# @rpc(_returns=String)
# def whoami(ctx): # ctx is the 'context' parameter used by Spyne
# """
# Dummy test method.
# """
# return "Hello I am " + ctx.descriptor.service_class.__name__ + "!"
@rpc(_returns=Array(Integer))
def post_cert(ctx):

@ -170,7 +170,8 @@ def check_server_certificate(cert, key, cert_path, args, port, auto=False):
elif args.host:
url = "https://%s:%d/?wsdl" % (args.host, port)
print url + '\n' + _("connecting...")
from sudsds.client import Client
# from sudsds.client import Client
from suds.client import Client
from client_class import HTTPSClientsCertTransport
from urllib2 import URLError
@ -216,7 +217,8 @@ def check_server_certificate(cert, key, cert_path, args, port, auto=False):
url = "https://%s:%d/?wsdl" % (args.root_host, port)
print url + '\n' + _("connecting...")
from sudsds.client import Client
# from sudsds.client import Client
from suds.client import Client
from client_class import HTTPSClientsCertTransport
try:

@ -131,7 +131,6 @@ def main(*args, **keywords):
# debug
if args.debug:
logging.basicConfig(level=logging.DEBUG)
# logger = logging.getLogger('soaplib.wsgi')
logger = logging.getLogger('spyne.server.wsgi')
logger.setLevel(logging.DEBUG)
except IOError:

@ -17,7 +17,8 @@
import urllib2 as u2
import os
import sys
from sudsds.transport.http import HttpTransport
# from sudsds.transport.http import HttpTransport
from suds.transport.http import HttpTransport
from httplib import HTTPConnection, HTTPSConnection
import socket
from calculate.core.datavars import DataVarsCore

@ -14,8 +14,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# from soaplib.wsgi import Application
# from spyne import Application
from spyne.server.wsgi import WsgiApplication
import re
@ -295,8 +293,10 @@ class ClApplication(WsgiApplication):
logger.critical("Couldn't get method name from HTTP_SOAPACTION")
return retval
#rips sid param from soap request (if there is one)
def get_sid_from_soap(self, http_req_env):
"""
rips sid param from soap request (if there is one)
"""
if (not "wsgi.input" in http_req_env):
return None
length = http_req_env.get("CONTENT_LENGTH")
@ -313,8 +313,11 @@ class ClApplication(WsgiApplication):
else:
return None
def handle_rpc(self, req_env, start_response):
"""
Overriding spyne.wsgiApplication method
"""
import OpenSSL
import threading
http_resp_headers = {
@ -331,21 +334,10 @@ class ClApplication(WsgiApplication):
if method_name is None:
resp = "Could not extract method name from the request!"
http_resp_headers['Content-Length'] = str(len(resp))
# print("Method name could not be resolved")
start_response(HTTP_500, http_resp_headers.items())
return [resp]
# print(method_name)
service = self.app.services[0]
# descriptor = service.public_methods.get(method_name)
# service1 = self.app.services[0]
# service2 = self.app.services[1]
# a = service1.public_methods.get(method_name)
# b = service2.public_methods.get(method_name)
# descriptor = a if a else b
# service = service1 if a else service2
import threading
curthread = threading.currentThread()
@ -366,7 +358,6 @@ class ClApplication(WsgiApplication):
method_name[5:]))
resp = "Permission denied: " + method_name
http_resp_headers['Content-Length'] = str(len(resp))
# print("PERMISSION DENIED")
start_response(HTTP_403, http_resp_headers.items())
return [resp]
if sid:

@ -6,13 +6,14 @@ from spyne.protocol._outbase import OutProtocolBase
from api_types import LazyString
#monkey patch:
#we add a check for a lazy string
def to_unicode(self, cls, value, *args, **kwargs):
if value is None:
return None
#### PATCH ####################
if isinstance(value, LazyString):
value = str(value)
###############################
handler = self._to_unicode_handlers[cls]
retval = handler(cls, value, *args, **kwargs)
@ -25,7 +26,8 @@ OutProtocolBase.to_unicode = to_unicode
class ServiceMetaAdapter(ServiceMeta):
#ref to the created class
global_class_ref = None
#this is used for a localCall
class CoreInnerWsdl(ServiceMeta, WsdlMeta):
pass
@ -52,7 +54,7 @@ def make_rpc_func_vars(func_to_call):
return func_to_call(ServiceMetaAdapter.global_class_ref, dv, params)
_function.__name__ = func_to_call.__name__
return staticmethod(_function)
def make_rpc_func_caller(func_to_call):
def _function(ctx, sid, params):
return func_to_call(ServiceMetaAdapter.global_class_ref, sid, params)
@ -80,6 +82,7 @@ def make_service(basic_class, wsdl_core_class_list, outer_wsdl_class_list, servi
functions_to_add.update({"__metaclass__" : ServiceMetaAdapter})
ClService = ServiceMetaAdapter(service_name, tuple([basic_class] + wsdl_core_class_list), functions_to_add)
ClService.public_methods.update(saved_pub_methods)
#TODO replace with a single ref
ServiceMetaAdapter.global_class_ref = ClService
basic_class.set_comb_class_ref(ClService)
return ClService
Loading…
Cancel
Save