Skip to content

Commit

Permalink
Improve error message on protocol mismatch
Browse files Browse the repository at this point in the history
Catch attempts to talk HTTP to HTTPS services
  • Loading branch information
willthames authored and fabianvf committed Mar 11, 2019
1 parent a6aaf5b commit b826e47
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion openshift/dynamic/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from kubernetes.client.rest import ApiException

from openshift.dynamic.exceptions import ResourceNotFoundError, ResourceNotUniqueError, api_exception, KubernetesValidateMissing
from urllib3.exceptions import ProtocolError, MaxRetryError

try:
import kubernetes_validate
Expand Down Expand Up @@ -671,7 +672,16 @@ def parse_api_groups(self, request_resources=False, update=False):

def _load_server_info(self):
if not self._cache.get('version'):
self._cache['version'] = {'kubernetes': load_json(self.client.request('get', '/version'))}
try:
self._cache['version'] = {'kubernetes': load_json(self.client.request('get', '/version'))}
except (ValueError, MaxRetryError) as e:
if isinstance(e, MaxRetryError) and not isinstance(e.reason, ProtocolError):
raise
if not self.client.configuration.host.startswith("https://"):
raise ValueError("Host value %s should start with https:// when talking to HTTPS endpoint" %
self.client.configuration.host)
else:
raise
try:
self._cache['version']['openshift'] = load_json(self.client.request('get', '/version/openshift'))
except ApiException:
Expand Down

0 comments on commit b826e47

Please sign in to comment.