def Connect(self):
     _CheckTLSSupport()
     with gke.ClusterConnectionInfo(self.cluster_ref) as (ip, ca_certs):
         self.ca_certs = ca_certs
         with gke.MonkeypatchAddressChecking('kubernetes.default',
                                             ip) as endpoint:
             self.endpoint = 'https://{}/'.format(endpoint)
             with _OverrideEndpointOverrides(self._api_name, self.endpoint):
                 yield self
 def Connect(self):
     _CheckTLSSupport()
     with self._LoadClusterDetails():
         if self.ca_data:
             with gke.MonkeypatchAddressChecking(
                     'kubernetes.default', self.raw_hostname) as endpoint:
                 self.endpoint = 'https://{}/'.format(endpoint)
                 with _OverrideEndpointOverrides(self.endpoint):
                     yield self
         else:
             self.endpoint = 'https://{}/'.format(self.raw_hostname)
             with _OverrideEndpointOverrides(self.endpoint):
                 yield self
示例#3
0
 def testMonkeypatchGetaddrinfoRedirect(self):
     cert = mock.Mock()
     with gke.MonkeypatchAddressChecking('foo.bar', '1.1.1.1') as endpoint:
         if six.PY3:
             self.assertEquals(endpoint, '1.1.1.1')
             ssl.match_hostname(cert, '1.1.1.1')
             self.stock_match_hostname.assert_called_once_with(
                 cert, 'foo.bar')
         else:
             self.assertEquals(endpoint, 'foo.bar')
             socket.getaddrinfo('foo.bar')
             self.stock_getaddrinfo.assert_called_once_with('1.1.1.1')
     self.assertIs(ssl.match_hostname, self.stock_match_hostname)
     self.assertIs(socket.getaddrinfo, self.stock_getaddrinfo)
示例#4
0
 def Connect(self):
   _CheckTLSSupport()
   with self._LoadClusterDetails():
     try:
       if self.ca_data:
         with gke.MonkeypatchAddressChecking(
             'kubernetes.default', self.raw_hostname) as endpoint:
           self.endpoint = 'https://{}/'.format(endpoint)
           with _OverrideEndpointOverrides(self._api_name, self.endpoint):
             yield self
       else:
         self.endpoint = 'https://{}/'.format(self.raw_hostname)
         with _OverrideEndpointOverrides(self._api_name, self.endpoint):
           yield self
     except httplib2.HttpLib2Error as e:
       if 'CERTIFICATE_VERIFY_FAILED' in six.text_type(e):
         raise gke.NoCaCertError(
             'Missing or invalid [certificate-authority] or '
             '[certificate-authority-data] field in kubeconfig file.')
       else:
         raise