Skip to content

Instantly share code, notes, and snippets.

@joemiller
Last active June 23, 2022 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joemiller/dbf79451517c6aefde239431c537b624 to your computer and use it in GitHub Desktop.
Save joemiller/dbf79451517c6aefde239431c537b624 to your computer and use it in GitHub Desktop.
quick script to parse vault pki issue responses into tls.pem file
#!/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