Skip to content
Open
Show file tree
Hide file tree
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
20 changes: 17 additions & 3 deletions kubeconfig/kubeconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# Check to see our changes.
print(conf.view())
"""
import json
import yaml


Expand Down Expand Up @@ -85,7 +86,7 @@ def delete_context(self, name):
Deletes a context entry from your config.

:param str name: The name of the context to delete from your config.
:raise: :py:exc:`KubectlCommandError <kubeconfig.exceptions.KubectlCommandError>`
:raise: :py:exc:`KubectlCommandError <kubeconfig.exceptions.KubectlCommandError>`
when an invalid context name is specified.
"""
self._run_kubectl_config('delete-context', name)
Expand Down Expand Up @@ -229,11 +230,24 @@ def use_context(self, name):
"""
self._run_kubectl_config('use-context', name)

def view(self):
def view(self, raw=False):
"""
:param bool raw: Set to true to return raw certificate data. Defaults
to false, where sensitive tokens are returned as REDACTED. Valid
only for kubectl versions >= 1.19, where the --raw flag was
introduced; output for previous kubectl versions is already raw.
:rtype: dict
:return: A dict representing your full kubeconfig file, after all
merging has been done.
"""
conf_doc_str = self._run_kubectl_config('view')

args = ['view']
version = json.loads(
self._run(subcmd_args="version -o json --client".split())
)["clientVersion"]
should_be_raw = raw and version["major"] >= 1 and version["minor"] >= 19

if should_be_raw:
args.append("--raw")
conf_doc_str = self._run_kubectl_config(*args)
return yaml.safe_load(conf_doc_str)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
author_email='greg@gctaylor.com',
license='BSD',
url='http://kubeconfig-python.readthedocs.io',
version='1.1.1',
version='1.2.0',
packages=find_packages(),
install_requires=[
'PyYAML>=5.2',
Expand Down