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 51
def self.build(proxmox_options, options)
  unless proxmox_options.key? :proxmox_auth_method
    raise ArgumentError,
          'Missing required proxmox_auth_method in options.'
  end

  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 38
def initialize(proxmox_options, options = {})
  if proxmox_options[:proxmox_url].nil? || proxmox_options[:proxmox_url].empty?
    raise URLError,
          'No proxmox_url provided'
  end

  @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 68
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 86
def expired?
  raise ExpiryError, 'Missing token expiration data' if @expires.nil? || @expires.empty?

  Time.at(@expires) < Time.now.utc
end