def do_service()

in src/ab/plugins/spring/eureka.py [0:0]


    def do_service(self, app_name, service, return_type="json",
                   method="get", headers: dict=None,
                   data=None, json=None, files: dict=None,
                   prefer_ip=True, prefer_https=False,
                   timeout=None,
                   ):
        """
        integrate eureka_client and requests

        :param app_name:
        :param service:
        :param return_type:
        :param method: method for the new :class:`Request` object.
        :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`.
        :param data: (optional) Dictionary, list of tuples, bytes, or file-like
            object to send in the body of the :class:`Request`.
        :param json: (optional) A JSON serializable Python object to send in the body of the :class:`Request`.
        :param files: (optional) Dictionary of ``'name': file-like-objects`` (or ``{'name': file-tuple}``) for multipart encoding upload.
            ``file-tuple`` can be a 2-tuple ``('filename', fileobj)``, 3-tuple ``('filename', fileobj, 'content_type')``
            or a 4-tuple ``('filename', fileobj, 'content_type', custom_headers)``, where ``'content-type'`` is a string
            defining the content type of the given file and ``custom_headers`` a dict-like object containing additional headers
            to add for the file.
        :param prefer_ip:
        :param prefer_https:
        :param timeout: (optional) How many seconds to wait for the server to send data
            before giving up, as a float, or a :ref:`(connect timeout, read
            timeout) <timeouts>` tuple.
        """
        # check method
        method = method.lower()
        if files:
            assert method == 'post'

        # fill headers
        headers = headers or {}
        if 'Authorization' not in headers:
            auth_header = self.get_auth_token()
            if auth_header:
                headers['Authorization'] = auth_header
        if not headers:
            logger.debug('empty eureka request headers')

        # copy from eureka_client and patch walker func
        def walk_using_requests(url):
            """
            data or files, if present, will overwrite json
            data and files could co-exist
            See :func:`requests.models.PreparedRequest#prepare_body`
            """
            logger.info('requesting url: {url}'.format(url=url))
            resp = requests.request(method, url, headers=headers, files=files, json=json, data=data, timeout=timeout)
            if return_type == 'json':
                return resp.json(encoding='utf8')
            elif return_type == 'raw':
                return resp
            else:
                return resp.text

        return self.discovery_client.walk_nodes(app_name, service, prefer_ip, prefer_https, walk_using_requests)