mirror of
https://github.com/puppetlabs/vmfloaty.git
synced 2026-01-27 05:48:41 -05:00
(#33) Handle Auth class errors
This commit updates the Auth class to properly raise an error when something goes wrong. It also updates the vmpooler command class to handle when those errors get raised.
This commit is contained in:
parent
05e9d5a0cc
commit
8da1deaf6b
4 changed files with 85 additions and 45 deletions
|
|
@ -1,6 +1,7 @@
|
|||
require 'faraday'
|
||||
require 'json'
|
||||
require 'vmfloaty/http'
|
||||
require 'vmfloaty/errors'
|
||||
|
||||
class Auth
|
||||
def self.get_token(verbose, url, user, password)
|
||||
|
|
@ -12,15 +13,13 @@ class Auth
|
|||
if res_body["ok"]
|
||||
return res_body["token"]
|
||||
else
|
||||
STDERR.puts "There was a problem with your request:\n#{res_body}"
|
||||
return nil
|
||||
raise TokenError, "HTTP #{resp.status}: There was a problem requesting a token:\n#{res_body}"
|
||||
end
|
||||
end
|
||||
|
||||
def self.delete_token(verbose, url, user, password, token)
|
||||
if token.nil?
|
||||
STDERR.puts 'You did not provide a token'
|
||||
return nil
|
||||
end
|
||||
|
||||
conn = Http.get_conn_with_auth(verbose, url, user, password)
|
||||
|
|
@ -30,15 +29,13 @@ class Auth
|
|||
if res_body["ok"]
|
||||
return res_body
|
||||
else
|
||||
STDERR.puts "There was a problem with your request:\n#{res_body}"
|
||||
return nil
|
||||
raise TokenError, "HTTP #{response.status}: There was a problem deleting a token:\n#{res_body}"
|
||||
end
|
||||
end
|
||||
|
||||
def self.token_status(verbose, url, token)
|
||||
if token.nil?
|
||||
STDERR.puts 'You did not provide a token'
|
||||
return nil
|
||||
end
|
||||
|
||||
conn = Http.get_conn(verbose, url)
|
||||
|
|
@ -49,8 +46,7 @@ class Auth
|
|||
if res_body["ok"]
|
||||
return res_body
|
||||
else
|
||||
STDERR.puts "There was a problem with your request:\n#{res_body}"
|
||||
return nil
|
||||
raise TokenError, "HTTP #{response.status}: There was a problem getting the status of a token:\n#{res_body}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue