Last active
June 23, 2022 14:55
-
-
Save joemiller/dbf79451517c6aefde239431c537b624 to your computer and use it in GitHub Desktop.
quick script to parse vault pki issue responses into tls.pem file
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 ruby | |
# | |
# Usage: | |
# | |
# vault write pki/issue/role common_name=foo ttl=1h | ruby vault-cert-parse.rb | |
# | |
# Creates the file tls.pem containing private-key, cert, and issuing-ca | |
# | |
# Can also be used with curl for living on the edge: | |
# | |
# vault write pki/issue/role common_name=foo ttl=1h | curl -sL https://gist.githubusercontent.com/joemiller/dbf79451517c6aefde239431c537b624/raw/vault-cert-parse.rb | ruby | |
require 'json' | |
payload = JSON.parse(ARGF.read) | |
File.open('tls.pem', 'w') do |f| | |
f.write(payload['data']['private_key']) | |
f.write("\n") | |
f.write(payload['data']['certificate']) | |
f.write("\n") | |
f.write(payload['data']['issuing_ca']) | |
f.write("\n") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment