mirror of
https://github.com/puppetlabs/vmfloaty.git
synced 2026-01-26 05:28:40 -05:00
59 lines
1.3 KiB
Ruby
59 lines
1.3 KiB
Ruby
require 'faraday'
|
|
require 'json'
|
|
require 'vmfloaty/http'
|
|
|
|
class Auth
|
|
def self.get_token(verbose, url, user, password)
|
|
conn = Http.get_conn_with_auth(verbose, url, user, password)
|
|
|
|
resp = conn.post "/token"
|
|
|
|
res_body = JSON.parse(resp.body)
|
|
if res_body["ok"]
|
|
return res_body["token"]
|
|
else
|
|
STDERR.puts "There was a problem with your request:"
|
|
puts res_body
|
|
exit 1
|
|
end
|
|
end
|
|
|
|
def self.delete_token(verbose, url, user, password, token)
|
|
if token.nil?
|
|
STDERR.puts 'You did not provide a token'
|
|
exit 1
|
|
end
|
|
|
|
conn = Http.get_conn_with_auth(verbose, url, user, password)
|
|
|
|
response = conn.delete "/token/#{token}"
|
|
res_body = JSON.parse(response.body)
|
|
if res_body["ok"]
|
|
puts res_body
|
|
else
|
|
STDERR.puts "There was a problem with your request:"
|
|
puts res_body
|
|
exit 1
|
|
end
|
|
end
|
|
|
|
def self.token_status(verbose, url, user, password, token)
|
|
if token.nil?
|
|
STDERR.puts 'You did not provide a token'
|
|
exit 1
|
|
end
|
|
|
|
conn = Http.get_conn_with_auth(verbose, url, user, password)
|
|
|
|
response = conn.get "/token/#{token}"
|
|
res_body = JSON.parse(response.body)
|
|
|
|
if res_body["ok"]
|
|
puts res_body
|
|
else
|
|
STDERR.puts "There was a problem with your request:"
|
|
puts res_body
|
|
exit 1
|
|
end
|
|
end
|
|
end
|