Created
October 30, 2018 08:36
-
-
Save jordiclariana/b1b977c0c27a8461e85b23c6def2b2ed to your computer and use it in GitHub Desktop.
Gets a secrets file from K8s (JSON format) and outputs it in yaml (without the base64 encoding).
This file contains hidden or 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 python2 | |
| from ruamel.yaml import YAML | |
| import json | |
| import sys | |
| import base64 | |
| with open(sys.argv[1], 'r') as srcfile: | |
| myjson = json.loads(srcfile.read()) | |
| secrets = {"secrets": []} | |
| for i in range(0, len(myjson["items"])): | |
| data = {} | |
| for k, v in myjson["items"][i]["data"].items(): | |
| data[k] = base64.b64decode(myjson["items"][i]["data"][k]) | |
| secrets["secrets"].append( | |
| { | |
| "name": myjson["items"][i]["metadata"]["name"], | |
| "type": myjson["items"][i]["type"], | |
| "data": data | |
| } | |
| ) | |
| yaml = YAML() | |
| yaml.indent(mapping=4, sequence=6, offset=2) | |
| yaml.dump(secrets, sys.stdout) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment