Skip to content

Commit

Permalink
Refactoring auth to simplify methods
Browse files Browse the repository at this point in the history
  • Loading branch information
nledez committed Aug 28, 2013
1 parent eb0a9d0 commit d60da96
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions lib/proxmox.rb
Expand Up @@ -18,28 +18,30 @@ def initialize(pve_cluster, node, username, password, realm)
end

def create_ticket
ticket = nil
csrf_prevention_token = nil
post_param = { :username=>@username, :realm=>@realm, :password=>@password }
@site['access/ticket'].post post_param do |response, request, result, &block|
if response.code == 200
data = JSON.parse(response.body)
ticket = data['data']['ticket']
csrf_prevention_token = data['data']['CSRFPreventionToken']
if !ticket.nil?
token = 'PVEAuthCookie=' + ticket.gsub!(/:/,'%3A').gsub!(/=/,'%3D')
end
@status = "connected"
{
:CSRFPreventionToken => csrf_prevention_token,
:cookie => token
}
extract_ticket response
else
@status = "error"
end
end
end

def extract_ticket(response)
data = JSON.parse(response.body)
ticket = data['data']['ticket']
csrf_prevention_token = data['data']['CSRFPreventionToken']
unless ticket.nil?
token = 'PVEAuthCookie=' + ticket.gsub!(/:/,'%3A').gsub!(/=/,'%3D')
end
@status = "connected"
{
:CSRFPreventionToken => csrf_prevention_token,
:cookie => token
}
end

def task_status(upid)
data = http_action_get "nodes/#{@node}/tasks/#{URI::encode upid}/status"
status = data['status']
Expand Down

0 comments on commit d60da96

Please sign in to comment.