Created
June 19, 2020 14:10
-
-
Save wolph/a6da7b96499bdf2bc33435e7db4079e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
''' | |
A very simple kubernetes secrets dump tool. You can use it like this: | |
# kubectl get secret -o yaml -A | python decode_secrets.py | |
''' | |
import sys | |
import yaml | |
import base64 | |
MAX_LENGTH = 120 | |
if sys.argv[1:]: | |
with open(sys.argv[1]) as fh: | |
data = yaml.load(fh) | |
else: | |
data = yaml.load(sys.stdin) | |
for item in data['items']: | |
data = item.pop('data') | |
metadata = item.pop('metadata') | |
for key, value in data.items(): | |
key = '{namespace}.{name}.{key}'.format(key=key, **metadata) | |
value = base64.b64decode(value).decode('utf-8') | |
if value[MAX_LENGTH:]: | |
value = value[:MAX_LENGTH - 3] + '...' | |
print(f'{key}={value}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment