Created
July 25, 2018 09:33
-
-
Save sideshowbandana/fb810d5392cb5e4aef9814a28486aab0 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 python | |
import base64 | |
import os | |
import json | |
import sys | |
import re | |
environment = sys.argv[1] | |
environment = environment.upper() | |
# Only grab the variables that are pertinent to the environment. | |
data = { | |
"{}_VERSION".format(environment): os.environ.get('CIRCLE_SHA1') | |
} | |
for env, val in os.environ.items(): | |
prefix = environment | |
if env.startswith(prefix): | |
env_without_prefix = env[len(prefix)+1:] | |
data[env_without_prefix] = base64.b64encode(bytes(val, 'utf-8')).decode() | |
secret_name = re.sub('_', '-', os.environ.get('CIRCLE_PROJECT_REPONAME')) | |
json_output = { | |
"apiVersion": "v1", | |
"kind": "Secret", | |
"metadata": { | |
"name": secret_name | |
}, | |
"type": "Opaque", | |
"data": data, | |
} | |
print(json.dumps(json_output)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment