def setUp(self):
     self.build_client()
     self.doppler = DopplerClient(re.sub("^http", "ws",
                                         self.TARGET_ENDPOINT),
                                  proxy="",
                                  verify_ssl=False,
                                  credentials_manager=self.client)
Пример #2
0
 def setUp(self):
     self.build_client()
     self.doppler = DopplerClient(re.sub('^http', 'ws',
                                         self.TARGET_ENDPOINT),
                                  proxy='',
                                  verify_ssl=False,
                                  credentials_manager=self.client)
class TestLoggregator(unittest.TestCase, AbstractTestCase):
    @classmethod
    def setUpClass(cls):
        cls.mock_client_class()

    def setUp(self):
        self.build_client()
        self.doppler = DopplerClient(re.sub("^http", "ws",
                                            self.TARGET_ENDPOINT),
                                     proxy="",
                                     verify_ssl=False,
                                     credentials_manager=self.client)

    def test_recents(self):
        boundary = "d661b2c1426a3abcf1c0524d7fdbc774c42a767bdd6702141702d16047bc"
        app_guid = "app_id"
        self.client.get.return_value = self.mock_response(
            "/apps/%s/recentlogs" % app_guid,
            HTTPStatus.OK,
            {"content-type": "multipart/x-protobuf; boundary=%s" % boundary},
            "recents",
            "GET_response.bin",
        )
        cpt = reduce(lambda increment, _: increment + 1,
                     self.doppler.recent_logs(app_guid), 0)
        self.client.get.assert_called_with(self.client.get.return_value.url,
                                           stream=True)
        self.assertEqual(cpt, 200)
Пример #4
0
 def __init__(self,
              target_endpoint,
              client_id='cf',
              client_secret='',
              proxy=None,
              verify=True):
     self.info = self._get_info(target_endpoint, proxy, verify=verify)
     if not self.info.api_version.startswith('2.'):
         raise AssertionError(
             'Only version 2 is supported for now. Found %s' %
             self.info.api_version)
     service_informations = ServiceInformation(
         None, '%s/oauth/token' % self.info.authorization_endpoint,
         client_id, client_secret, [], verify)
     super(CloudFoundryClient, self).__init__(service_informations, proxy)
     CredentialManager.__init__(self, service_informations, proxy)
     self.v2 = V2(target_endpoint, self)
     self.v3 = V3(target_endpoint, self)
     if self.info.doppler_endpoint is not None:
         self._doppler = DopplerClient(
             self.info.doppler_endpoint,
             self.proxies['http' if self.info.doppler_endpoint.
                          startswith('ws://') else 'https'],
             self.service_information.verify,
             self) if self.info.doppler_endpoint is not None else None
Пример #5
0
 def __init__(self,
              target_endpoint: str,
              client_id: str = "cf",
              client_secret: str = "",
              **kwargs):
     """ "
     :param target_endpoint :the target endpoint
     :param client_id: the client_id
     :param client_secret: the client secret
     :param proxy: a dict object with entries http and https
     :param verify: parameter directly passed to underlying requests library.
         (optional) Either a boolean, in which case it controls whether we verify
         the server's TLS certificate, or a string, in which case it must be a path
         to a CA bundle to use. Defaults to ``True``.
     :param token_format: string Can be set to opaque to retrieve an opaque and revocable token.
         See UAA API specifications
     :param login_hint: string. Indicates the identity provider to be used.
         The passed string has to be a URL-Encoded JSON Object, containing the field origin with value as origin_key
         of an identity provider. Note that this identity provider must support the grant type password.
         See UAA API specifications
     """
     proxy = kwargs.get("proxy", dict(http="", https=""))
     verify = kwargs.get("verify", True)
     self.token_format = kwargs.get("token_format")
     self.login_hint = kwargs.get("login_hint")
     target_endpoint_trimmed = target_endpoint.rstrip("/")
     info = self._get_info(target_endpoint_trimmed, proxy, verify=verify)
     if not info.api_v2_version.startswith("2."):
         raise AssertionError(
             "Only version 2 is supported for now. Found %s" %
             info.api_v2_version)
     service_information = ServiceInformation(
         None, "%s/oauth/token" % info.authorization_endpoint, client_id,
         client_secret, [], verify)
     super(CloudFoundryClient, self).__init__(service_information,
                                              proxies=proxy)
     self.v2 = V2(target_endpoint_trimmed, self)
     self.v3 = V3(target_endpoint_trimmed, self)
     self._doppler = (DopplerClient(
         info.doppler_endpoint,
         self.proxies["http" if info.doppler_endpoint.
                      startswith("ws://") else "https"],
         self.service_information.verify,
         self,
     ) if info.doppler_endpoint is not None else None)
     self._rlpgateway = (RLPGatewayClient(
         info.log_stream_endpoint,
         self.proxies["https"],
         self.service_information.verify,
         self,
     ) if info.log_stream_endpoint is not None else None)
     self.networking_v1_external = NetworkingV1External(
         target_endpoint_trimmed, self)
     self.info = info
Пример #6
0
 def __init__(self,
              target_endpoint,
              client_id='cf',
              client_secret='',
              **kwargs):
     """"
     :param target_endpoint :the target endpoint
     :param client_id: the client_id
     :param client_secret: the client secret
     :param proxy: a dict object with entries http and https
     :param verify: parameter directly passed to underlying requests library.
         (optional) Either a boolean, in which case it controls whether we verify
         the server's TLS certificate, or a string, in which case it must be a path
         to a CA bundle to use. Defaults to ``True``.
     :param token_format: string Can be set to opaque to retrieve an opaque and revocable token.
         See UAA API specifications
     :param login_hint: string. Indicates the identity provider to be used.
         The passed string has to be a URL-Encoded JSON Object, containing the field origin with value as origin_key
         of an identity provider. Note that this identity provider must support the grant type password.
         See UAA API specifications
     """
     proxy = kwargs.get('proxy', dict(http='', https=''))
     verify = kwargs.get('verify', True)
     self.token_format = kwargs.get('token_format')
     self.login_hint = kwargs.get('login_hint')
     info = self._get_info(target_endpoint, proxy, verify=verify)
     if not info.api_version.startswith('2.'):
         raise AssertionError(
             'Only version 2 is supported for now. Found %s' %
             info.api_version)
     service_information = ServiceInformation(
         None, '%s/oauth/token' % info.authorization_endpoint, client_id,
         client_secret, [], verify)
     super(CloudFoundryClient, self).__init__(service_information,
                                              proxies=proxy)
     self.v2 = V2(target_endpoint, self)
     self.v3 = V3(target_endpoint, self)
     self._doppler = DopplerClient(
         info.doppler_endpoint,
         self.proxies['http' if info.doppler_endpoint.
                      startswith('ws://') else 'https'],
         self.service_information.verify,
         self) if info.doppler_endpoint is not None else None
     self.info = info
Пример #7
0
class TestLoggregator(unittest.TestCase, AbstractTestCase):
    @classmethod
    def setUpClass(cls):
        cls.mock_client_class()

    def setUp(self):
        self.build_client()
        self.doppler = DopplerClient(re.sub('^http', 'ws', TARGET_ENDPOINT),
                                     proxy='',
                                     verify_ssl=False,
                                     credentials_manager=self.client)

    def test_recents(self):
        boundary = 'd661b2c1426a3abcf1c0524d7fdbc774c42a767bdd6702141702d16047bc'
        app_guid = 'app_id'
        self.client.get.return_value = mock_response(
            '/apps/%s/recentlogs' % app_guid, OK,
            {'content-type': 'multipart/x-protobuf; boundary=%s' % boundary},
            'recents', 'GET_response.bin')
        cpt = reduce(lambda increment, _: increment + 1,
                     self.doppler.recent_logs(app_guid), 0)
        self.client.get.assert_called_with(self.client.get.return_value.url,
                                           stream=True)
        self.assertEqual(cpt, 200)