mirror of
https://github.com/puppetlabs/vmfloaty.git
synced 2026-01-26 05:28:40 -05:00
Fix token auth for methods
Properly set the header to be X-AUTH-TOKEN for requests to the pooler.
This commit is contained in:
parent
de7a9ac433
commit
98741e5e4a
4 changed files with 23 additions and 36 deletions
|
|
@ -37,24 +37,4 @@ class Http
|
|||
return conn
|
||||
end
|
||||
|
||||
def self.get_conn_with_token(verbose, url, token)
|
||||
if url.nil?
|
||||
STDERR.puts "The url you provided was empty"
|
||||
exit 1
|
||||
end
|
||||
|
||||
if token.nil?
|
||||
STDERR.puts "The token you provided was empty"
|
||||
exit 1
|
||||
end
|
||||
|
||||
conn = Faraday.new(:url => url, :ssl => {:verify => false}) do |faraday|
|
||||
faraday.request :url_encoded
|
||||
faraday.request :token_auth, token
|
||||
faraday.response :logger if verbose
|
||||
faraday.adapter Faraday.default_adapter
|
||||
end
|
||||
|
||||
return conn
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -20,11 +20,9 @@ class Pooler
|
|||
|
||||
def self.retrieve(verbose, os_type, token, url)
|
||||
os = os_type.gsub(',','+')
|
||||
if token.nil?
|
||||
conn = Http.get_conn(verbose, url)
|
||||
else
|
||||
conn = Http.get_conn_with_token(verbose, url, token)
|
||||
conn.headers['X-AUTH-TOKEN']
|
||||
conn = Http.get_conn(verbose, url)
|
||||
if token
|
||||
conn.headers['X-AUTH-TOKEN'] = token
|
||||
end
|
||||
|
||||
response = conn.post "/vm/#{os}"
|
||||
|
|
@ -42,15 +40,18 @@ class Pooler
|
|||
modify_body['tags'] = tags
|
||||
end
|
||||
|
||||
conn = Http.get_conn_with_token(verbose, url, token)
|
||||
conn.headers['X-AUTH-TOKEN']
|
||||
conn = Http.get_conn(verbose, url)
|
||||
conn.headers['X-AUTH-TOKEN'] = token
|
||||
|
||||
response = conn.put "/vm/#{hostname}"
|
||||
response = conn.put do |req|
|
||||
req.url "/vm/#{hostname}"
|
||||
req.body = modify_body
|
||||
end
|
||||
res_body = JSON.parse(response.body)
|
||||
res_body
|
||||
end
|
||||
|
||||
def self.delete(verbose, url, hostnames)
|
||||
def self.delete(verbose, url, hostnames, token)
|
||||
if hostnames.nil?
|
||||
STDERR.puts "You did not provide any hosts to delete"
|
||||
exit 1
|
||||
|
|
@ -59,6 +60,10 @@ class Pooler
|
|||
hosts = hostnames.split(',')
|
||||
conn = Http.get_conn(verbose, url)
|
||||
|
||||
if token
|
||||
conn.headers['X-AUTH-TOKEN'] = token
|
||||
end
|
||||
|
||||
hosts.each do |host|
|
||||
puts "Scheduling host #{host} for deletion"
|
||||
response = conn.delete "/vm/#{host}"
|
||||
|
|
@ -97,8 +102,8 @@ class Pooler
|
|||
end
|
||||
|
||||
def self.snapshot(verbose, url, hostname, token)
|
||||
conn = Http.get_conn_with_token(verbose, url, token)
|
||||
conn.headers['X-AUTH-TOKEN']
|
||||
conn = Http.get_conn(verbose, url)
|
||||
conn.headers['X-AUTH-TOKEN'] = token
|
||||
|
||||
response = conn.post "/vm/#{hostname}/snapshot"
|
||||
res_body = JSON.parse(response.body)
|
||||
|
|
@ -106,8 +111,8 @@ class Pooler
|
|||
end
|
||||
|
||||
def self.revert(verbose, url, hostname, token, snapshot_sha)
|
||||
conn = Http.get_conn_with_token(verbose, url, token)
|
||||
conn.headers['X-AUTH-TOKEN']
|
||||
conn = Http.get_conn(verbose, url)
|
||||
conn.headers['X-AUTH-TOKEN'] = token
|
||||
|
||||
response = conn.post "/vm/#{hostname}/snapshot/#{snapshot}"
|
||||
res_body = JSON.parse(response.body)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue