Exemplo n.º 1
0
 def test_with_suffix(self):
     http_helpers.set_user_agent_suffix("foobar")
     mock_http = MockHttp()
     http = http_helpers.build_http(mock_http)
     response, content = http.request(DUMMY_URL)
     self.assertIn(UA_KEY, mock_http.headers)
     self.assertRegex(mock_http.headers[UA_KEY], r'foobar\s+gce$')
Exemplo n.º 2
0
 def test_without_suffix(self):
     http_helpers.set_user_agent_suffix("")
     mock_http = MockHttp()
     http = http_helpers.build_http(mock_http)
     response, content = http.request(DUMMY_URL)
     self.assertIn(UA_KEY, mock_http.headers)
     self.assertRegex(
         mock_http.headers[UA_KEY], r'forseti-security/[0-9.]+$')
Exemplo n.º 3
0
 def test_with_suffix_set_platform(self):
     with mock.patch.dict('os.environ', {'FORSETI_PLATFORM': 'gke'}):
         http_helpers.set_user_agent_suffix("foobar")
         mock_http = MockHttp()
         http = http_helpers.build_http(mock_http)
         response, content = http.request(DUMMY_URL)
         self.assertIn(UA_KEY, mock_http.headers)
         self.assertRegex(mock_http.headers[UA_KEY], r'foobar\s+gke$')
Exemplo n.º 4
0
    def http(self):
        """A thread local instance of httplib2.Http.

        Returns:
            google_auth_httplib2.AuthorizedHttp: An Http instance authorized by
                the credentials.
        """
        if self._use_cached_http and hasattr(self._local, 'http'):
            return self._local.http

        authorized_http = google_auth_httplib2.AuthorizedHttp(
            self._credentials, http=http_helpers.build_http())

        if self._use_cached_http:
            self._local.http = authorized_http
        return authorized_http