-
-
Save shakahl/7c5278d33542fd94401f8eafb2c241bb to your computer and use it in GitHub Desktop.
Create k8s Secret YAML
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 python3 | |
import base64 | |
from getpass import getpass | |
def create_secret_yaml(secret_name, **kwargs): | |
""" | |
Create k8s Secret Yaml with key: value | |
Value must already be base64 encoded and in utf-8 encoded bytes | |
:param secret_name: Secret name for metadata | |
:param kwargs: Keywords are keys, values are values. | |
:return: UTF-8 Bytes containing Secret YAML | |
""" | |
data = bytes( | |
'apiVersion: v1\n' | |
'kind: Secret\n' | |
'metadata:\n' | |
' name: ' + secret_name + '\n' | |
'data:\n', 'utf-8') | |
for k, v in kwargs.items(): | |
data += b' ' + k.encode('utf-8') + b': ' + v + b'\n' | |
return data | |
if __name__ == '__main__': | |
fn = input('YAML filename: ') | |
sn = input('Secret Name: ') | |
kvs = dict() | |
while True: | |
key = input('Key: ') | |
if key == '': | |
break | |
value = base64.b64encode(getpass('Value (Input is Hidden): ').encode('utf-8')) | |
kvs[key] = value | |
yaml = create_secret_yaml(sn, **kvs) | |
with open(fn, 'wb') as f: | |
f.write(yaml) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment