From c2d641a18d96f864e1b2e5de1f16c9e5594ee15f Mon Sep 17 00:00:00 2001 From: David Alexander Date: Thu, 7 Nov 2019 10:59:51 -0500 Subject: [PATCH] Adds some love for Windows users --- CHANGELOG.md | 1 + oc_auth/kube_config.py | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 177176e..053064d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ means we will never make a backwards-incompatible change within a major version ## [UNRELEASED] - Uses the TLS verification settings already present in the kube config +- Adds Windows support for path separation ## [0.2.0] - 2019-10-25 diff --git a/oc_auth/kube_config.py b/oc_auth/kube_config.py index 8b0439d..364f866 100644 --- a/oc_auth/kube_config.py +++ b/oc_auth/kube_config.py @@ -1,4 +1,5 @@ import logging +import platform import os from typing import Any, Dict, List, Iterator, Union @@ -6,6 +7,12 @@ _missing = object() +_default_kube_config = os.path.expanduser('~/.kube/config') + +if platform.system() == 'Windows': + _path_separator = ';' +else: + _path_separator = ':' class KubeConfigData(object): @@ -55,7 +62,7 @@ def persist(self): class KubeConfig(object): - def __init__(self, config_files: List[str] = [os.path.expanduser('~/.kube/config')]): + def __init__(self, config_files: List[str] = [_default_kube_config]): self.configs: List[KubeConfigData] = [] for filename in config_files: if not filename: @@ -66,8 +73,8 @@ def __init__(self, config_files: List[str] = [os.path.expanduser('~/.kube/config @classmethod def find_from_env(cls): - path = os.environ.get('KUBECONFIG', os.path.expanduser('~/.kube/config')) - files = path.split(':') + path = os.environ.get('KUBECONFIG', _default_kube_config) + files = path.split(_path_separator) return cls(config_files=files) @property