Skip to content
This repository has been archived by the owner on Mar 13, 2022. It is now read-only.

Fixing get Google default credentials method #21

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions config/kube_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down