def new_client(service_type):
    """ Make a `suds` client, accounting for ?wsdl suffixes, failing to import appropriate schemas, and http auth

        Args:
            service_type: type of service to ping (usually 'procurement_service' or 'grant_service')

        Returns:
            Client for FSRS service
    """
    config = service_config(service_type)
    wsdl_url = config.get('wsdl', '')
    options = {'url': wsdl_url}

    if wsdl_url.endswith('?wsdl'):
        options['location'] = wsdl_url[:-len('?wsdl')]

    # The WSDL is missing an import; it's so common that suds has a work around
    parsed_wsdl = urlparse(wsdl_url)
    import_fix = doctor.Import('http://schemas.xmlsoap.org/soap/encoding/')
    # Main namespace is the wsdl domain
    import_fix.filter.add('{}://{}/'.format(parsed_wsdl.scheme, parsed_wsdl.netloc))

    options['doctor'] = doctor.ImportDoctor(import_fix)
    options['plugins'] = [ControlFilter(), ZeroDateFilter()]

    if config.get('username') and config.get('password'):
        options['transport'] = HttpAuthenticated(
            username=config['username'],
            password=config['password'],
            timeout=300)

    return Client(**options)
Exemplo n.º 2
0
    def createClient(self):
        # The following dictionary has the targetNamespace as the key and a list
        # of namespaces that need to be imported as the value for that key
        patches = {
            "urn:SecurityServer": [
                "http://authentication.integration.crowd.atlassian.com",
                "http://soap.integration.crowd.atlassian.com",
                "http://exception.integration.crowd.atlassian.com",
                "http://rmi.java"
            ],
            "http://soap.integration.crowd.atlassian.com":
            ["urn:SecurityServer"]
        }

        # Create an ImportDoctor to use
        doctor = dr.ImportDoctor()

        # Patch all the imports into the proper targetNamespaces
        for targetNamespace in patches:
            for ns_import in patches[targetNamespace]:
                imp = dr.Import(ns_import)
                imp.filter.add(targetNamespace)
                doctor.add(imp)

            # Create the SOAP client, doctoring it to fix imports
        return Client(settings.SERVER_URI, doctor=doctor)
Exemplo n.º 3
0
    def __init__(self,
                 wsdl,
                 ns_import_location=None,
                 location=None,
                 username=None,
                 password=None,
                 faults=False,
                 plugins=None,
                 cache=None):
        super(BaseSoapClient, self).__init__()
        logging.getLogger('suds').setLevel(logging.CRITICAL)

        # Fix import for parsing most WSDLs
        if ns_import_location is None:
            ns_import_location = 'http://schemas.xmlsoap.org/soap/encoding/'
        ns_import = suds_doctor.Import(ns_import_location)
        doctor = suds_doctor.ImportDoctor(ns_import)

        if plugins is None:
            plugins = [doctor]
        else:
            plugins.extend([doctor])
        self.client = suds.client.Client(wsdl,
                                         location=location,
                                         username=username,
                                         password=password,
                                         faults=faults,
                                         plugins=plugins,
                                         cache=cache)
Exemplo n.º 4
0
    def __init__(self, configname='default'):

        wsdl = None
        importdoctor = None
        config = pyaxl.configuration.registry.get(configname)
        if config.schema_path is None:
            modpath = os.path.dirname(pyaxl.__file__)
            cachefiles = os.path.join(get_cache_path(configname), 'files')
            if not os.path.exists(cachefiles):
                print(
                    'Cache for configuration "%s" doesn\'t exist. Use pyaxl_import_wsdl_to create it first!'
                    % configname,
                    file=sys.stderr)
                raise Exception('Path for cache doesn\'t exist')
            with open(cachefiles) as f:
                wsdl = f.readline().strip()
                importdoctor = doctor.ImportDoctor(
                    *[doctor.Import(l.strip()) for l in f.readlines()])
        else:
            schema_path = config.schema_path
            wsdl = os.path.join(schema_path, AXLAPI)
            if not os.path.exists(wsdl):
                raise ValueError(
                    'The version %s is not supported. WSDL was not found.' %
                    config.version)
            wsdl = FILE_PREFIX % wsdl
            importdoctor = AXLImportDoctor(schema_path)
        httpconfig = dict(username=config.user,
                          password=config.passwd,
                          proxy=config.proxy)
        transport = HttpAuthenticated(**httpconfig)
        plugins = list()
        if config.transport_debugger:
            plugins.append(DebugTransportPlugin())

        kwargs = dict(cache=get_cache(configname),
                      location='%s/%s' % (config.host, config.path),
                      doctor=importdoctor,
                      plugins=plugins,
                      transport=transport)
        kwargs.update(config.suds_config)
        super(AXLClient, self).__init__(wsdl, **kwargs)
Exemplo n.º 5
0
def newClient(serviceType):
    """Make a `suds` client, accounting for ?wsdl suffixes, failing to import
    appropriate schemas, and http auth"""
    config = serviceConfig(serviceType)
    wsdlUrl = config.get('wsdl', '')
    options = {'url': wsdlUrl}

    if wsdlUrl.endswith('?wsdl'):
        options['location'] = wsdlUrl[:-len('?wsdl')]

    # The WSDL is missing an import; it's so common that suds has a work around
    parsedWsdl = urlparse(wsdlUrl)
    importFix = doctor.Import('http://schemas.xmlsoap.org/soap/encoding/')
    importFix.filter.add(  # Main namespace is the wsdl domain
        '{}://{}/'.format(parsedWsdl.scheme, parsedWsdl.netloc))

    options['doctor'] = doctor.ImportDoctor(importFix)
    options['plugins'] = [ControlFilter()]

    if config.get('username') and config.get('password'):
        options['transport'] = HttpAuthenticated(username=config['username'],
                                                 password=config['password'])

    return Client(**options)
import suds.xsd.doctor as dr

wsdlurl = 'http://hoff.coremedia.com:8095/crowd/services/SecurityServer?wsdl'
# The following dictionary has the targetNamespace as the key and a list
# of namespaces that need to be imported as the value for that key
patches = {
    "urn:SecurityServer": [
        "http://authentication.integration.crowd.atlassian.com",
        "http://soap.integration.crowd.atlassian.com",
        "http://exception.integration.crowd.atlassian.com", "http://rmi.java"
    ],
    "http://soap.integration.crowd.atlassian.com": ["urn:SecurityServer"]
}

# Create an ImportDoctor to use
doctor = dr.ImportDoctor()

# Patch all the imports into the proper targetNamespaces
for targetNamespace in patches:
    for ns_import in patches[targetNamespace]:
        imp = dr.Import(ns_import)
        imp.filter.add(targetNamespace)
        doctor.add(imp)

# Create the SOAP client, doctoring it to fix imports
client = Client(wsdlurl, doctor=doctor)
print(client)

auth_context = client.factory.create('ns1:ApplicationAuthenticationContext')

auth_context.name = "django"