Last active
March 25, 2016 17:06
-
-
Save afterwords/010713e3616f3f4d53d8 to your computer and use it in GitHub Desktop.
Test Vault failover
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/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