Mercurial > hg > config
view python/k8sdecode.py @ 832:b9be1237fffa
revert to python2 for time being
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sun, 19 Feb 2017 20:27:07 -0800 |
parents | 46674fb64686 |
children |
line wrap: on
line source
#!/usr/bin/env python # -*- coding: utf-8 -*- """ get a kubernetes secret and decode it """ # imports import argparse import base64 import json import os import subprocess import sys def main(args=sys.argv[1:]): """CLI""" # parse command line parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('secret', help="k8s secret name") options = parser.parse_args(args) # get JSON from `kubectl` command = ['kubectl', 'get', 'secret', options.secret, '-o', 'json'] try: output = subprocess.check_output(command) except subprocess.CalledProcessError as e: print (e) sys.exit(e.returncode) data = json.loads(output)['data'] # decode them output = {key: base64.b64decode(value) for key, value in data.items()} # output them print (json.dumps(output, indent=2, sort_keys=True)) if __name__ == '__main__': main()