19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/thor/main.rb', line 19
def auth
error "WARNING! Disabling SSL certificate verification is not recommended. Proceed with caution!" if options[:skip_ssl_verify]
email, password = options[:email], options[:password]
email = ask("Please enter your email:") unless email
raise Thor::Error, "You must enter a value for that field." if email.empty?
print "Please enter your password: "
password = STDIN.noecho(&:gets).chomp unless password
print "\n"
raise Thor::Error, "You must enter a value for that field." if password.empty?
say "Attempting to aquire API token..."
token = StormForge::Client.new(dev_mode: options[:development], skip_ssl_verify: options[:skip_ssl_verify]).aquire_api_token(email, password)
raise Thor::Error, "Authentication error!" unless token
say "Your API authentication is: #{token}", :yellow
unless options[:authfile] == "-"
say "Writing/Updating credentials to #{authfile}"
File.open(authfile, "w+") do |file|
file.puts({ email: email, authentication_token: token, created_at: Time.now }.to_json)
end
File.chmod(0600, authfile)
end
rescue Faraday::Error::ConnectionFailed => e
p e.message
raise Thor::Error, "StormForger API not available :-/ (connection failed)"
rescue Faraday::Error::ClientError => e
if e.response[:status] == 401
handle_authentication_error(e)
else
raise e
end
end
|