module Fog::Proxmox
Proxmox module
Constants
- VERSION
Attributes
credentials[R]
now[RW]
version[R]
Public Class Methods
authenticate(options, connection_options = {})
click to toggle source
# File lib/fog/proxmox.rb, line 55 def self.authenticate(options, connection_options = {}) get_tokens(options, connection_options) self end
authenticated?()
click to toggle source
# File lib/fog/proxmox.rb, line 60 def self.authenticated? !@credentials.empty? end
clear_credentials()
click to toggle source
# File lib/fog/proxmox.rb, line 51 def self.clear_credentials @credentials = {} end
credentials_has_expired?()
click to toggle source
# File lib/fog/proxmox.rb, line 64 def self.credentials_has_expired? authenticated? && @credentials[:deadline] > @now end
extract_password(options)
click to toggle source
# File lib/fog/proxmox.rb, line 68 def self.extract_password(options) ticket = options[:pve_ticket] options[:pve_password] = ticket unless ticket end
get_tokens(options, connection_options = {})
click to toggle source
# File lib/fog/proxmox.rb, line 73 def self.get_tokens(options, connection_options = {}) username = options[:pve_username].to_s password = options[:pve_password].to_s url = options[:pve_url] extract_password(options) uri = URI.parse(url) @api_path = uri.path connection_options = connection_options.merge(path_prefix: @api_path) password = @credentials[:csrftoken] if credentials_has_expired? retrieve_tokens(uri, connection_options, username, password) unless authenticated? && !credentials_has_expired? end
retrieve_tokens(uri, connection_options, username, password)
click to toggle source
# File lib/fog/proxmox.rb, line 85 def self.retrieve_tokens(uri, connection_options, username, password) request = { expects: [200, 204], headers: { 'Accept' => 'application/json' }, body: "username=#{username}&password=#{password}", method: 'POST', path: 'access/ticket' } connection = Fog::Core::Connection.new( uri.to_s, false, connection_options ) response = connection.request(request) data = Json.get_data(response) ticket = data['ticket'] username = data['username'] csrftoken = data['CSRFPreventionToken'] deadline = Time.at(@now.to_i + @ticket_lifetime) save_token(username, ticket, csrftoken, deadline) end
save_token(username, ticket, csrftoken, deadline)
click to toggle source
# File lib/fog/proxmox.rb, line 109 def self.save_token(username, ticket, csrftoken, deadline) @credentials = { username: username, ticket: ticket, csrftoken: csrftoken, deadline: deadline } end