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
|
|
@ -33,7 +33,7 @@ class Vmfloaty
|
||||||
pass = password "Enter your password please:", '*'
|
pass = password "Enter your password please:", '*'
|
||||||
|
|
||||||
unless options.token
|
unless options.token
|
||||||
token = Auth.get_token(user, url, pass)
|
token = Auth.get_token(url, user, pass)
|
||||||
end
|
end
|
||||||
|
|
||||||
unless os_types.nil?
|
unless os_types.nil?
|
||||||
|
|
@ -172,6 +172,34 @@ class Vmfloaty
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
command :token do |c|
|
||||||
|
c.syntax = 'floaty token [get | delete | status]'
|
||||||
|
c.summary = 'Retrieves or deletes a token'
|
||||||
|
c.description = ''
|
||||||
|
c.example '', ''
|
||||||
|
c.option '--url STRING', String, 'URL of vmpooler'
|
||||||
|
c.option '--user STRING', String, 'User to authenticate with'
|
||||||
|
c.option '--token STRING', String, 'Token for vmpooler'
|
||||||
|
c.action do |args, options|
|
||||||
|
action = args.first
|
||||||
|
url = options.url ||= config['url']
|
||||||
|
token = options.token
|
||||||
|
user = options.user ||= config['user']
|
||||||
|
pass = password "Enter your password please:", '*'
|
||||||
|
|
||||||
|
case action
|
||||||
|
when "get"
|
||||||
|
puts Auth.get_token(url, user, pass)
|
||||||
|
when "delete"
|
||||||
|
Auth.delete_token(url, user, pass, token)
|
||||||
|
when "status"
|
||||||
|
Auth.token_status(url, user, pass, token)
|
||||||
|
else
|
||||||
|
puts "Unknown action: #{action}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
run!
|
run!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,20 +3,41 @@ require 'json'
|
||||||
require 'vmfloaty/http'
|
require 'vmfloaty/http'
|
||||||
|
|
||||||
class Auth
|
class Auth
|
||||||
def self.get_token(user, url, password)
|
def self.get_token(url, user, password)
|
||||||
conn = Http.get_conn(url)
|
conn = Http.get_conn(url)
|
||||||
|
|
||||||
resp = conn.post do |req|
|
resp = conn.post do |req|
|
||||||
req.url '/v1/token'
|
req.url '/v1/token'
|
||||||
req.headers['Content-Type'] = 'application/json'
|
req.headers['Content-Type'] = 'application/json'
|
||||||
req.user = user
|
|
||||||
end
|
end
|
||||||
# if ok: true, return token
|
|
||||||
resp_body = JSON.parse(resp.body)
|
resp_body = JSON.parse(resp.body)
|
||||||
resp_body
|
resp_body
|
||||||
end
|
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)
|
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
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue