Skip to content

Commit

Permalink
Use highline for crt questions
Browse files Browse the repository at this point in the history
  • Loading branch information
benichu committed Aug 7, 2016
1 parent 757a42b commit 1e2dbd6
Showing 1 changed file with 17 additions and 35 deletions.
52 changes: 17 additions & 35 deletions bin/checklister
Original file line number Diff line number Diff line change
Expand Up @@ -102,61 +102,43 @@ command :setup do |c|

if service_selected == "gitlab"
# Get the service url
choice = bot.ask("<%= color('What is your gitlab endpoint? (Ex: https://gitlab.com/api/v3)', :question) %>") do |q|
data["endpoint"] = bot.ask("<%= color('What is your gitlab endpoint? (Ex: https://gitlab.com/api/v3)', :question) %>") do |q|
q.validate = /https?:\/\/[\S]+/
end
data["endpoint"] = choice

# Configure tls client certificate, if any
if bot.agree("<%= color('Does your Gitlab server require a client certificate? [y/n]', :question) %>")
# Set the endpoint certificate path
puts "** Please enter the path to your SSL certificate (the extension should be .crt)"
choice = STDIN.gets.chomp
while choice.to_s.empty?
puts "** Please enter a valid path"
choice = STDIN.gets.chomp
data["endpoint_certificate_path"] = bot.ask("<%= color('Please enter the path to your SSL certificate (the extension should be .crt)', :question) %>") do |q|
q.validate = /.*\S.*/
end
data["endpoint_certificate_path"] = choice

# Set the private certificate path
puts "** Please enter the path to your private certificate (the extension should be .p12)"
choice = STDIN.gets.chomp
while choice.to_s.empty?
puts "** Please enter a valid path"
choice = STDIN.gets.chomp
data["client_certificate_path"] = bot.ask("<%= color('Please enter the path to your private certificate (the extension should be .p12)', :question) %>") do |q|
q.validate = /.*\S.*/
end
data["client_certificate_path"] = choice

# Set the private certificate password
puts "** Please enter your private certificate password"
choice = STDIN.gets.chomp
while choice.empty?
puts "** The password cannot be blank"
choice = STDIN.gets.chomp

# Set the private certificate password (not compulsory)
data["client_certificate_password"] = bot.ask("<%= color('Please enter your private certificate password', :question) %>") do |q|
q.echo = "*"
end
data["client_certificate_password"] = choice
end
elsif service_selected == "github"
data["endpoint"] = "https://api.github.com"
end

puts ""
puts "** What is your private token with the #{service_selected} service?"
choice = STDIN.gets.chomp
raise("You need to type a private token.") if choice == ""
data["private_token"] = choice

puts ""
puts "** You can give a label to #{data["endpoint"]} (you can leave it blank too)"
choice = STDIN.gets.chomp
if choice != ""
data["label"] = choice
# Private token
data["private_token"] = bot.ask("<%= color('What is your private token with the #{service_selected} service?', :question) %>") do |q|
q.validate = /^$|\s+/
end

# Label
data["label"] = bot.ask("<%= color('You can give a label to #{data["endpoint"]} (you can leave it blank too)', :question) %>")

# Persist the configuration to file
config_file.add_service data
config_file.persist
puts ""
puts "* Your configuration data has been saved at #{global_options[:config]}"
bot.say "<%= color('Your configuration data has been saved at #{global_options[:config]}', :info) %>"
end
end

Expand Down

0 comments on commit 1e2dbd6

Please sign in to comment.