Class: Fog::Proxmox::Auth::Token::AccessTicket

Inherits:
Object
  • Object
show all
Includes:
Fog::Proxmox::Auth::Token
Defined in:
lib/fog/proxmox/auth/token/access_ticket.rb

Defined Under Namespace

Classes: URIError

Constant Summary collapse

NAME =
'access_ticket'
EXPIRATION_DELAY =
2 * 60 * 60

Instance Attribute Summary collapse

Attributes included from Fog::Proxmox::Auth::Token

#data, #expires, #token, #userid

Instance Method Summary collapse

Methods included from Fog::Proxmox::Auth::Token

#authenticate, build, #expired?, #initialize

Instance Attribute Details

#csrf_tokenObject (readonly)

Returns the value of attribute csrf_token.



34
35
36
# File 'lib/fog/proxmox/auth/token/access_ticket.rb', line 34

def csrf_token
  @csrf_token
end

Instance Method Details

#auth_body(params = {}) ⇒ Object

Raises:



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/fog/proxmox/auth/token/access_ticket.rb', line 48

def auth_body(params = {})
  raise URIError, 'URI params is required' if params.nil? || params.empty?

  if params[:proxmox_username].nil? || params[:proxmox_username].empty?
    raise URIError,
          'proxmox_username is required'
  end
  if params[:proxmox_password].nil? || params[:proxmox_password].empty?
    raise URIError,
          'proxmox_password is required'
  end

  URI.encode_www_form(username: params[:proxmox_username], password: params[:proxmox_password])
end

#auth_methodObject



40
41
42
# File 'lib/fog/proxmox/auth/token/access_ticket.rb', line 40

def auth_method
  'POST'
end

#auth_path(_params = {}) ⇒ Object



44
45
46
# File 'lib/fog/proxmox/auth/token/access_ticket.rb', line 44

def auth_path(_params = {})
  '/access/ticket'
end

#build_credentials(_proxmox_options, data) ⇒ Object



76
77
78
79
80
81
# File 'lib/fog/proxmox/auth/token/access_ticket.rb', line 76

def build_credentials(_proxmox_options, data)
  @token = data['ticket']
  @expires = Time.now.utc.to_i + EXPIRATION_DELAY
  @userid = data['username']
  @csrf_token = data['CSRFPreventionToken']
end

#headers(method = 'GET', _params = {}, additional_headers = {}) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/fog/proxmox/auth/token/access_ticket.rb', line 63

def headers(method = 'GET', _params = {}, additional_headers = {})
  headers_hash = {}
  @data ||= {}
  unless @data.empty?
    headers_hash.store('Cookie', "PVEAuthCookie=#{@data['ticket']}")
    if %w[PUT POST DELETE].include? method
      headers_hash.store('CSRFPreventionToken', @data['CSRFPreventionToken'])
    end
  end
  headers_hash.merge! additional_headers
  headers_hash
end

#missing_credentials(options) ⇒ Object

Raises:

  • (ArgumentError)


83
84
85
86
87
88
89
90
91
# File 'lib/fog/proxmox/auth/token/access_ticket.rb', line 83

def missing_credentials(options)
  missing_credentials = []
  missing_credentials << :proxmox_username unless options[:proxmox_username]
  missing_credentials << :proxmox_password unless options[:proxmox_password]
  return if missing_credentials.empty?

  raise ArgumentError,
        "Missing required arguments: #{missing_credentials.join(', ')}"
end