598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
|
# File 'lib/soracom/cli.rb', line 598
def configure
print <<EOS
--- SORACOM CLI setup ---
This will create .soracom directory under #{ENV['HOME']} and place '#{options.profile}.json' in it.
Please select which authentication method to use.
1. Input AuthKeyId and AuthKey *Recommended*
2. Input Operator credentials (Operator Email and Password)
3. Input SAM credentials (OperatorId and UserName and Password)
EOS
mode = STDIN.tap{print "select(1-3)> "}.gets.chomp
begin
Dir.mkdir("#{ENV['HOME']}/.soracom/",0700)
rescue Errno::EEXIST
end
case mode
when '1'
authKeyId = STDIN.tap{print "authKeyId: "}.gets.chomp
authKey = STDIN.tap{print "authKey: "}.noecho(&:gets).tap{print "\n"}.chomp
File.open("#{ENV['HOME']}/.soracom/#{options.profile}.json", "w") do |f|
f.print JSON.pretty_generate ({authKeyId: authKeyId, authKey: authKey})
end
when '2'
email = STDIN.tap{print "Email: "}.gets.chomp
password = STDIN.tap{print "Password: "}.noecho(&:gets).tap{print "\n"}.chomp
File.open("#{ENV['HOME']}/.soracom/#{options.profile}.json", "w") do |f|
f.print JSON.pretty_generate ({email: email, password: password})
end
when '3'
operatorId = STDIN.tap{print "operatorId: "}.gets.chomp
userName = STDIN.tap{print "userName: "}.gets.chomp
password = STDIN.tap{print "password: "}.noecho(&:gets).tap{print "\n"}.chomp
File.open("#{ENV['HOME']}/.soracom/#{options.profile}.json", "w") do |f|
f.print JSON.pretty_generate ({operatorId: operatorId, userName: userName, password: password})
end
else
abort "invalid number."
end
print "wrote to #{ENV['HOME']}/.soracom/#{options.profile}.json\n"
end
|