Skip to content

Commit

Permalink
adding wait method to conjurctl (#504)
Browse files Browse the repository at this point in the history
  • Loading branch information
izgeri authored Jan 10, 2018
1 parent ec556c8 commit 03a47b9
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions bin/conjur-cli.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require 'gli'
require 'net/http'
require 'uri'

include GLI::App

Expand Down Expand Up @@ -209,4 +211,46 @@ def test_select
end
end

desc "Wait for the Conjur server to be ready"
command :wait do |c|
c.desc 'Port'
c.arg_name :port
c.default_value ENV['PORT'] || '80'
c.flag [ :p, :port ], :must_match => /\d+/

c.desc 'Number of retries'
c.arg_name :retries
c.default_value 90
c.flag [ :r, :retries ], :must_match => /\d+/

c.action do |global_options,options,args|
puts "Waiting for Conjur to be ready..."

retries = options[:retries].to_i
port = options[:port]

conjur_ready = lambda do
uri = URI.parse("http://localhost:#{port}")
begin
response = Net::HTTP.get_response(uri)
response.code.to_i < 300
rescue
false
end
end

retries.times do
break if conjur_ready.call
STDOUT.print "."
sleep 1
end

if conjur_ready.call
puts " Conjur is ready!"
else
exit_now! " Conjur is not ready after #{retries} seconds"
end
end
end

exit run(ARGV)

0 comments on commit 03a47b9

Please sign in to comment.