mirror of
https://github.com/puppetlabs/vmfloaty.git
synced 2026-01-26 05:28:40 -05:00
(#1) Add token status and delete methods
This commit is contained in:
parent
02527b9665
commit
d3b1af4a06
2 changed files with 54 additions and 5 deletions
|
|
@ -3,20 +3,41 @@ require 'json'
|
|||
require 'vmfloaty/http'
|
||||
|
||||
class Auth
|
||||
def self.get_token(user, url, password)
|
||||
def self.get_token(url, user, password)
|
||||
conn = Http.get_conn(url)
|
||||
|
||||
resp = conn.post do |req|
|
||||
req.url '/v1/token'
|
||||
req.headers['Content-Type'] = 'application/json'
|
||||
req.user = user
|
||||
end
|
||||
# if ok: true, return token
|
||||
|
||||
resp_body = JSON.parse(resp.body)
|
||||
resp_body
|
||||
end
|
||||
|
||||
def self.delete_token(user, token)
|
||||
def self.delete_token(url, user, pass, token)
|
||||
if token.nil?
|
||||
puts 'You did not provide a token'
|
||||
return
|
||||
end
|
||||
|
||||
conn = Http.get_conn(url)
|
||||
|
||||
response = conn.delete "/v1/token/#{token}"
|
||||
res_body = JSON.parse(response)
|
||||
puts res_body
|
||||
end
|
||||
|
||||
def self.token_status(url, user, pass, token)
|
||||
if token.nil?
|
||||
puts 'You did not provide a token'
|
||||
return
|
||||
end
|
||||
|
||||
conn = Http.get_conn(url)
|
||||
|
||||
response = conn.get "/v1/token/#{token}"
|
||||
res_body = JSON.parse(response.body)
|
||||
puts res_body
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue