Class: Fog::Proxmox::Auth::Token::UserToken
Defined Under Namespace
Classes: URIError
Constant Summary
collapse
- NAME =
'user_token'
Instance Attribute Summary collapse
#data, #expires, #token, #userid
Instance Method Summary
collapse
#authenticate, build, #expired?, #initialize
Instance Attribute Details
#token_id ⇒ Object
Returns the value of attribute token_id.
34
35
36
|
# File 'lib/fog/proxmox/auth/token/user_token.rb', line 34
def token_id
@token_id
end
|
Instance Method Details
#auth_body(_params = {}) ⇒ Object
57
58
59
|
# File 'lib/fog/proxmox/auth/token/user_token.rb', line 57
def auth_body(_params = {})
''
end
|
#auth_method ⇒ Object
38
39
40
|
# File 'lib/fog/proxmox/auth/token/user_token.rb', line 38
def auth_method
'GET'
end
|
#auth_path(params = {}) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/fog/proxmox/auth/token/user_token.rb', line 42
def auth_path(params = {})
raise URIError, 'URI params are required' if params.nil? || params.empty?
if params[:proxmox_userid].nil? || params[:proxmox_userid].empty?
raise URIError,
'proxmox_userid is required'
end
if params[:proxmox_tokenid].nil? || params[:proxmox_tokenid].empty?
raise URIError,
'proxmox_tokenid is required'
end
"/access/users/#{URI.encode_www_form_component(params[:proxmox_userid])}/token/#{params[:proxmox_tokenid]}"
end
|
#build_credentials(proxmox_options, data) ⇒ Object
86
87
88
89
90
91
|
# File 'lib/fog/proxmox/auth/token/user_token.rb', line 86
def build_credentials(proxmox_options, data)
@expires = data['expire']
@token = proxmox_options[:proxmox_token]
@token_id = proxmox_options[:proxmox_tokenid]
@userid = proxmox_options[:proxmox_userid]
end
|
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/fog/proxmox/auth/token/user_token.rb', line 75
def (_method = 'GET', params = {}, = {})
raise URIError, 'User token is required' if no_token?(params)
credentials = set_credentials(params)
= {}
.store('Authorization',
"PVEAPIToken=#{credentials[:userid]}!#{credentials[:token_id]}=#{credentials[:token]}")
.merge!
end
|
#missing_credentials(options) ⇒ Object
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/fog/proxmox/auth/token/user_token.rb', line 93
def missing_credentials(options)
missing_credentials = []
missing_credentials << :proxmox_userid unless options[:proxmox_userid]
missing_credentials << :proxmox_tokenid unless options[:proxmox_tokenid]
missing_credentials << :proxmox_token unless options[:proxmox_token]
return if missing_credentials.empty?
raise ArgumentError,
"Missing required arguments: #{missing_credentials.join(', ')}"
end
|
#no_token?(params) ⇒ Boolean
61
62
63
|
# File 'lib/fog/proxmox/auth/token/user_token.rb', line 61
def no_token?(params)
(params.respond_to?(:proxmox_token) || params[:proxmox_token].nil? || params[:proxmox_token].empty?) && (@token.nil? || @token.empty?)
end
|
#set_credentials(params) ⇒ Object
65
66
67
68
69
70
71
72
73
|
# File 'lib/fog/proxmox/auth/token/user_token.rb', line 65
def set_credentials(params)
token = @token
token = params[:proxmox_token] if token.empty?
token_id = @token_id
token_id = params[:proxmox_tokenid] if token_id.empty?
userid = @userid
userid = params[:proxmox_userid] if userid.empty?
{ userid: userid, token_id: token_id, token: token }
end
|