Skip to content

Instantly share code, notes, and snippets.

@afterwords
Last active March 25, 2016 17:06
Show Gist options
  • Save afterwords/010713e3616f3f4d53d8 to your computer and use it in GitHub Desktop.
Save afterwords/010713e3616f3f4d53d8 to your computer and use it in GitHub Desktop.
Test Vault failover
#!/usr/bin/ruby
require 'vault'
require 'base64'
# set these variables
@address = "https://:8200"
@token = ""
@transit_key = ""
def vaultmaster
Vault::Client.new(
:address => @address,
:timeout => 30,
:token => @token,
:ssl_verify => false,
)
end
my_message = Base64.encode64("test text")
begin
@ciphertext = vaultmaster.logical.write("transit/encrypt/#{@transit_key}", plaintext: my_message).data[:ciphertext]
puts @ciphertext
rescue => e
puts e
end
i = 0
loop do
begin
text = vaultmaster.logical.write("transit/decrypt/#{@transit_key}", ciphertext: @ciphertext).data[:plaintext]
rescue => e
puts e
end
if Base64.decode64(text) != Base64.decode64(my_message)
puts "vault message decryption failed"
break
end
i += 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment