Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI refactor #135

Merged
merged 1 commit into from
Jun 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 35 additions & 10 deletions spec/support/vault_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def self.method_missing(m, *args, &block)
end

attr_reader :token
attr_reader :unseal_token

def initialize
# If there is already a vault-token, we need to move it so we do not
Expand All @@ -30,7 +31,10 @@ def initialize
end

io = Tempfile.new("vault-server")
pid = Process.spawn({}, "vault server -dev", out: io.to_i, err: io.to_i)
pid = Process.spawn(
"vault server -dev -dev-root-token-id=root",
out: io.to_i, err: io.to_i
)

at_exit do
Process.kill("INT", pid)
Expand All @@ -39,26 +43,47 @@ def initialize
io.close
io.unlink
end
wait_for_ready
puts "vault server is ready"
# sleep to get unseal token
sleep 5

wait_for_ready do
@token = File.read(TOKEN_PATH)
@token = "root"

output = ""
while io.rewind
output = io.read
break unless output.empty?
end

if output.match(/Unseal Key.*: (.+)/)
@unseal_token = $1.strip
else
raise "Vault did not return an unseal token!"
end
end

def address
"http://127.0.0.1:8200"
end

def wait_for_ready(&block)
Timeout.timeout(5) do
while !File.exist?(TOKEN_PATH)
sleep(0.25)
def wait_for_ready
uri = URI(address + "/v1/sys/health")
Timeout.timeout(15) do
loop do
begin
response = Net::HTTP.get_response(uri)
if response.code != 200
return true
end
rescue Errno::ECONNREFUSED
puts "waiting for vault to start"
end
sleep 2
end
end

yield
rescue Timeout::Error
raise "Vault did not start in 5 seconds!"
raise TimeoutError, "Timed out waiting for vault health check"
end
end
end