コード例 #1
0
ファイル: http_soap.py プロジェクト: dangnammta/zato
def index(req):
    connection = req.GET.get('connection')
    transport = req.GET.get('transport')
    query = req.GET.get('query', '')
    items = []
    _security = SecurityList()

    if not all((connection, transport)):
        log_msg = "Redirecting to / because at least one of ('connection', 'transport') GET parameters was missing"
        logger.debug(log_msg)
        return HttpResponseRedirect('/')

    create_form = None
    edit_form = None
    meta = None

    colspan = 17

    if transport == 'soap':
        colspan += 2

    if req.zato.cluster_id:
        for def_item in req.zato.client.invoke('zato.security.get-list', {'cluster_id': req.zato.cluster.id}):
            if connection == 'outgoing':
                if transport == URL_TYPE.PLAIN_HTTP and def_item.sec_type not in (
                    SEC_DEF_TYPE.BASIC_AUTH, SEC_DEF_TYPE.TLS_KEY_CERT, SEC_DEF_TYPE.APIKEY):
                    continue
                elif transport == URL_TYPE.SOAP and def_item.sec_type not in (
                    SEC_DEF_TYPE.BASIC_AUTH, SEC_DEF_TYPE.NTLM, SEC_DEF_TYPE.WSS):
                    continue

            _security.append(def_item)

        _soap_versions = SOAP_CHANNEL_VERSIONS if connection == 'channel' else SOAP_VERSIONS

        tls_ca_cert_list = get_tls_ca_cert_list(req.zato.client, req.zato.cluster)

        cache_list = []

        for cache_type in (CACHE.TYPE.BUILTIN, CACHE.TYPE.MEMCACHED):
            service_name = 'zato.cache.{}.get-list'.format(cache_type)
            response = req.zato.client.invoke(service_name, {'cluster_id': req.zato.cluster.id})

            for item in sorted(response, key=itemgetter('name')):
                cache_list.append({'id':item.id, 'name':'{}/{}'.format(CACHE_TYPE[cache_type], item.name)})

        create_form = CreateForm(_security, tls_ca_cert_list, cache_list, _soap_versions, req=req)
        edit_form = EditForm(_security, tls_ca_cert_list, cache_list, _soap_versions, prefix='edit', req=req)

        input_dict = {
            'cluster_id': req.zato.cluster_id,
            'connection': connection,
            'transport': transport,
            'paginate': True,
            'cur_page': req.GET.get('cur_page', 1),
            'query': req.GET.get('query', ''),
        }

        data, meta = parse_response_data(req.zato.client.invoke('zato.http-soap.get-list', input_dict))

        for item in data:
            if query not in item.name:
                continue

            _security_name = item.security_name
            if _security_name:
                security_name = '{0}<br/>{1}'.format(SEC_DEF_TYPE_NAME[item.sec_type], _security_name)
            else:
                if item.sec_use_rbac:
                    security_name = DELEGATED_TO_RBAC
                else:
                    security_name = '<span class="form_hint">---</span>'

            security_id = get_http_channel_security_id(item)

            if item.cache_id:
                cache_name = '{}/{}'.format(CACHE_TYPE[item.cache_type], item.cache_name)
            else:
                cache_name = None

            # New in 3.0, hence optional
            match_slash = item.get('match_slash')
            if match_slash == '':
                match_slash = True

            # New in 3.1
            http_accept = item.get('http_accept') or ''

            http_soap = HTTPSOAP(item.id, item.name, item.is_active, item.is_internal, connection,
                    transport, item.host, item.url_path, item.method, item.soap_action,
                    item.soap_version, item.data_format, item.ping_method,
                    item.pool_size, item.merge_url_params_req, item.url_params_pri, item.params_pri,
                    item.serialization_type, item.timeout, item.sec_tls_ca_cert_id, service_id=item.service_id,
                    service_name=item.service_name, security_id=security_id, has_rbac=item.has_rbac,
                    security_name=security_name, content_type=item.content_type,
                    cache_id=item.cache_id, cache_name=cache_name, cache_type=item.cache_type, cache_expiry=item.cache_expiry,
                    content_encoding=item.content_encoding, match_slash=match_slash, http_accept=http_accept)

            for name in 'is_rate_limit_active', 'rate_limit_type', 'rate_limit_def', 'rate_limit_check_parent_def':
                setattr(http_soap, name, item.get(name))

            items.append(http_soap)

    return_data = {'zato_clusters':req.zato.clusters,
        'cluster_id':req.zato.cluster_id,
        'search_form':SearchForm(req.zato.clusters, req.GET),
        'items':items,
        'create_form':create_form,
        'edit_form':edit_form,
        'connection':connection,
        'transport':transport,
        'connection_label':CONNECTION[connection],
        'connection_label_plural':CONNECTION_PLURAL[connection],
        'transport_label':TRANSPORT[transport],
        'colspan': colspan,
        'default_http_ping_method':DEFAULT_HTTP_PING_METHOD,
        'default_http_pool_size':DEFAULT_HTTP_POOL_SIZE,
        'default_http_timeout':MISC.DEFAULT_HTTP_TIMEOUT,
        'paginate':True,
        'meta': meta,
        'req':req
        }

    return TemplateResponse(req, 'zato/http_soap/index.html', return_data)
コード例 #2
0
def index(req):
    connection = req.GET.get('connection')
    transport = req.GET.get('transport')
    items = []
    _security = SecurityList()

    if not all((connection, transport)):
        log_msg = "Redirecting to / because at least one of ('connection', 'transport') GET parameters was missing"
        logger.debug(log_msg)
        return HttpResponseRedirect('/')

    create_form = None
    edit_form = None
    meta = None

    colspan = 17

    if transport == 'soap':
        colspan += 2

    if req.zato.cluster_id:
        for def_item in req.zato.client.invoke(
                'zato.security.get-list', {'cluster_id': req.zato.cluster.id}):
            if connection == 'outgoing':
                if transport == URL_TYPE.PLAIN_HTTP and def_item.sec_type not in (
                        SEC_DEF_TYPE.BASIC_AUTH, SEC_DEF_TYPE.TLS_KEY_CERT):
                    continue
                elif transport == URL_TYPE.SOAP and def_item.sec_type not in (
                        SEC_DEF_TYPE.BASIC_AUTH, SEC_DEF_TYPE.NTLM,
                        SEC_DEF_TYPE.WSS):
                    continue

            _security.append(def_item)

        _soap_versions = SOAP_CHANNEL_VERSIONS if connection == 'channel' else SOAP_VERSIONS

        create_form = CreateForm(_security,
                                 get_tls_ca_cert_list(req.zato.client,
                                                      req.zato.cluster),
                                 _soap_versions,
                                 req=req)
        edit_form = EditForm(_security,
                             get_tls_ca_cert_list(req.zato.client,
                                                  req.zato.cluster),
                             _soap_versions,
                             prefix='edit',
                             req=req)

        input_dict = {
            'cluster_id': req.zato.cluster_id,
            'connection': connection,
            'transport': transport,
            'paginate': True,
            'cur_page': req.GET.get('cur_page', 1)
        }

        data, meta = parse_response_data(
            req.zato.client.invoke('zato.http-soap.get-list', input_dict))

        for item in data:

            _security_name = item.security_name
            if _security_name:
                security_name = '{0}<br/>{1}'.format(
                    SEC_DEF_TYPE_NAME[item.sec_type], _security_name)
            else:
                if item.sec_use_rbac:
                    security_name = DELEGATED_TO_RBAC
                else:
                    security_name = 'No security definition'

            _security_id = item.security_id
            if _security_id:
                security_id = '{0}/{1}'.format(item.sec_type, _security_id)
            else:
                if item.sec_use_rbac:
                    security_id = ZATO_SEC_USE_RBAC
                else:
                    security_id = ZATO_NONE

            item = HTTPSOAP(item.id,
                            item.name,
                            item.is_active,
                            item.is_internal,
                            connection,
                            transport,
                            item.host,
                            item.url_path,
                            item.method,
                            item.soap_action,
                            item.soap_version,
                            item.data_format,
                            item.ping_method,
                            item.pool_size,
                            item.merge_url_params_req,
                            item.url_params_pri,
                            item.params_pri,
                            item.serialization_type,
                            item.timeout,
                            item.sec_tls_ca_cert_id,
                            service_id=item.service_id,
                            service_name=item.service_name,
                            security_id=security_id,
                            has_rbac=item.has_rbac,
                            security_name=security_name,
                            content_type=item.content_type)
            items.append(item)

    return_data = {
        'zato_clusters': req.zato.clusters,
        'cluster_id': req.zato.cluster_id,
        'search_form': SearchForm(req.zato.clusters, req.GET),
        'items': items,
        'create_form': create_form,
        'edit_form': edit_form,
        'connection': connection,
        'transport': transport,
        'connection_label': CONNECTION[connection],
        'connection_label_plural': CONNECTION_PLURAL[connection],
        'transport_label': TRANSPORT[transport],
        'colspan': colspan,
        'default_http_ping_method': DEFAULT_HTTP_PING_METHOD,
        'default_http_pool_size': DEFAULT_HTTP_POOL_SIZE,
        'default_http_timeout': MISC.DEFAULT_HTTP_TIMEOUT,
        'paginate': True,
        'meta': meta,
        'req': req
    }

    return TemplateResponse(req, 'zato/http_soap/index.html', return_data)