From d1b1ea9fb11a173d0fbd5fc918b1589373d3b032 Mon Sep 17 00:00:00 2001 From: Gabriel Garcia Bim Date: Thu, 20 Jul 2017 12:43:51 -0700 Subject: [PATCH 1/3] Fixing get Google default credentials method --- config/kube_config.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/config/kube_config.py b/config/kube_config.py index 04057fb1..dcf4a68e 100644 --- a/config/kube_config.py +++ b/config/kube_config.py @@ -21,6 +21,10 @@ import yaml from google.oauth2.credentials import Credentials +import google.auth +import google.auth.transport.requests +import requests + from kubernetes.client import ApiClient, ConfigurationObject, configuration from .config_exception import ConfigException @@ -117,12 +121,17 @@ def __init__(self, config_dict, active_context=None, self._cluster = None self.set_active_context(active_context) self._config_base_path = config_base_path + + def _refresh_credentials(): + credentials, project_id = google.auth.default() + request = google.auth.transport.requests.Request() + credentials.refresh(request) + return credentials.token + if get_google_credentials: self._get_google_credentials = get_google_credentials else: - self._get_google_credentials = lambda: ( - GoogleCredentials.get_application_default() - .get_access_token().access_token) + self._get_google_credentials = _refresh_credentials self._client_configuration = client_configuration def set_active_context(self, context_name=None): From 5f5ab3a57ab082ed77a4eda93bc4f2a734fd6adc Mon Sep 17 00:00:00 2001 From: Gabriel Garcia Bim Date: Fri, 21 Jul 2017 13:54:04 -0700 Subject: [PATCH 2/3] Another solution, trying to fix Google default credentials without breaking tests --- config/kube_config.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/config/kube_config.py b/config/kube_config.py index dcf4a68e..ca86e7ff 100644 --- a/config/kube_config.py +++ b/config/kube_config.py @@ -122,16 +122,13 @@ def __init__(self, config_dict, active_context=None, self.set_active_context(active_context) self._config_base_path = config_base_path - def _refresh_credentials(): - credentials, project_id = google.auth.default() - request = google.auth.transport.requests.Request() - credentials.refresh(request) - return credentials.token - if get_google_credentials: self._get_google_credentials = get_google_credentials else: - self._get_google_credentials = _refresh_credentials + credentials, project_id = google.auth.default() + request = google.auth.transport.requests.Request() + credentials.refresh(request) + self._get_google_credentials = lambda: (credentials.token) self._client_configuration = client_configuration def set_active_context(self, context_name=None): From 425811b78385655f821fbf31a67e427a09edda8c Mon Sep 17 00:00:00 2001 From: Gabriel Garcia Bim Date: Fri, 21 Jul 2017 13:58:27 -0700 Subject: [PATCH 3/3] Reverting changes to the original solution --- config/kube_config.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/config/kube_config.py b/config/kube_config.py index ca86e7ff..dcf4a68e 100644 --- a/config/kube_config.py +++ b/config/kube_config.py @@ -122,13 +122,16 @@ def __init__(self, config_dict, active_context=None, self.set_active_context(active_context) self._config_base_path = config_base_path - if get_google_credentials: - self._get_google_credentials = get_google_credentials - else: + def _refresh_credentials(): credentials, project_id = google.auth.default() request = google.auth.transport.requests.Request() credentials.refresh(request) - self._get_google_credentials = lambda: (credentials.token) + return credentials.token + + if get_google_credentials: + self._get_google_credentials = get_google_credentials + else: + self._get_google_credentials = _refresh_credentials self._client_configuration = client_configuration def set_active_context(self, context_name=None):