Ejemplo n.º 1
0
 def __init__(self, client=None):
     """
     Our client wraps the  asyncio aiohttp client. This is so we can provide different implementations such as providing
     a mocked implementation to make testing easier.
     :param client: instance of AioHTTPClient or mock instance
     """
     self.client = client if client else AioHttpClient()
 def __init__(self):
     """
     :param uri: string representing uri to make request to
     """
     super(AsyncTelemetryClient, self).__init__(client=AioHttpClient(verify_ssl=False))
     self.telemetry_instance_id = None
     self.splunk_version = None
     self.installation_environment = None
class AsyncSpacebridgeClient(AioHttpClient):
    def __init__(self, config, key_bundle: KeyBundle = None):
        self.https_proxy = config.get_https_proxy_settings()
        self.config = config
        self.client = AioHttpClient(proxy=self.https_proxy,
                                    key_bundle=key_bundle)

    def async_send_request(self, api, auth_header, data='', headers={}):
        """
        Generic Async send request
        :param api:
        :param auth_header:
        :param data:
        :param headers:
        :return:
        """
        if self.https_proxy and self.https_proxy['auth']:
            headers[
                'Proxy-Authorization'] = 'Basic ' + self.https_proxy['auth']

        rest_uri = "https://{}".format(self.config.get_spacebridge_server() +
                                       api)
        return self.client.post(uri=rest_uri,
                                auth_header=auth_header,
                                data=data,
                                headers=headers)

    def async_send_notification_request(self,
                                        auth_header,
                                        data='',
                                        headers={}):
        """
        API to send notifications
        :param auth_header:
        :param data:
        :param headers:
        :return:
        """
        return self.async_send_request('/api/notifications', auth_header, data,
                                       headers)

    def async_send_message_request(self, auth_header, data='', headers={}):
        """
        API to send messages
        :param auth_header:
        :param data:
        :param headers:
        :return:
        """
        return self.async_send_request('/api/deployments/messages',
                                       auth_header, data, headers)
    async def run(self):
        proxy = config.get_https_proxy_settings()
        uri = "{}/health_check".format(config.get_spacebridge_domain())

        if not self.useProxy:
            proxy = None

        client = AsyncClient(AioHttpClient(proxy=proxy))

        try:
            result = await client.async_get_request(uri, None)
            if result.code == 200:
                self.echo_state.ok = True
            else:
                self.echo_state.message = 'Got http {}'.format(result.code)
        except Exception as e:
            self.echo_state.message = str(e)

        return {
            'https_async': self.echo_state.ok,
            'message': self.echo_state.message
        }
 def __init__(self):
     super(AsyncNonSslClient,
           self).__init__(client=AioHttpClient(verify_ssl=False))
Ejemplo n.º 6
0
 def __init__(self, username):
     self.username = username
     self.token = None
     self.async_client = AioHttpClient()
 def __init__(self, config, key_bundle: KeyBundle = None):
     self.https_proxy = config.get_https_proxy_settings()
     self.config = config
     self.client = AioHttpClient(proxy=self.https_proxy,
                                 key_bundle=key_bundle)