module Fog::Proxmox::Auth::Token
Attributes
data[R]
expires[R]
token[R]
userid[R]
Public Class Methods
build(proxmox_options, options)
click to toggle source
# File lib/fog/proxmox/auth/token.rb, line 48 def self.build(proxmox_options, options) raise ArgumentError, "Missing required proxmox_auth_method in options." unless proxmox_options.key? :proxmox_auth_method auth_method = proxmox_options[:proxmox_auth_method] if auth_method == Fog::Proxmox::Auth::Token::AccessTicket::NAME Fog::Proxmox::Auth::Token::AccessTicket.new(proxmox_options, options) elsif auth_method == Fog::Proxmox::Auth::Token::UserToken::NAME Fog::Proxmox::Auth::Token::UserToken.new(proxmox_options, options) else raise ArgumentError, "Unkown authentication method: #{auth_method}. Only #{Fog::Proxmox::Auth::Token::AccessTicket::NAME} or #{Fog::Proxmox::Auth::Token::UserToken::NAME} are accepted." end end
new(proxmox_options, options = {})
click to toggle source
# File lib/fog/proxmox/auth/token.rb, line 39 def initialize(proxmox_options, options = {}) raise URLError, 'No proxmox_url provided' if proxmox_options[:proxmox_url].nil? || proxmox_options[:proxmox_url].empty? @token ||= '' @token_id ||= '' @userid ||= '' @data = authenticate(proxmox_options, options) build_credentials(proxmox_options, data) end
Public Instance Methods
authenticate(proxmox_options, connection_options = {})
click to toggle source
# File lib/fog/proxmox/auth/token.rb, line 60 def authenticate(proxmox_options, connection_options = {}) uri = URI.parse(proxmox_options[:proxmox_url]) request = { expects: [200, 201], headers: headers(auth_method, proxmox_options, { Accept: 'application/json' }), body: auth_body(proxmox_options), method: auth_method, path: uri.path + auth_path(proxmox_options) } connection = Fog::Core::Connection.new( uri.to_s, false, connection_options ) response = connection.request(request) Json.get_data(response) end
expired?()
click to toggle source
# File lib/fog/proxmox/auth/token.rb, line 78 def expired? if @expires.nil? || @expires.empty? raise ExpiryError, 'Missing token expiration data' end Time.at(@expires) < Time.now.utc end