Created
March 18, 2015 15:54
-
-
Save mrsipan/eef39839103c148cb0a4 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
# Use: python files_from_ssl_bag.py <path-to-data-bag-ssl-in-chef> | |
import os | |
import json | |
import argparse | |
import tempfile | |
def main(args=None): | |
parser = argparse.ArgumentParser() | |
parser.add_argument('data_bag_path', help='data bag path') | |
options = parser.parse_args() | |
with open(options.data_bag_path) as fp: | |
ssl_data = json.load(fp) | |
tmpdir = tempfile.mkdtemp(prefix=ssl_data['id']) | |
print 'go to this directory for keys: %s' % tmpdir | |
currdir = os.getcwd() | |
try: | |
os.chdir(tmpdir) | |
open("%s.crt" % ssl_data['id'], 'w').write(ssl_data['cert']) | |
open("%s.key" % ssl_data['id'], 'w').write(ssl_data['key']) | |
open("chain.crt", 'w').write(ssl_data['intermediate']) | |
finally: | |
os.chdir(currdir) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment