module Fog::Proxmox::Core
Core module
Attributes
auth_method[R]
current_user[R]
expires[R]
token[RW]
Public Class Methods
new(options = {})
click to toggle source
# File lib/fog/proxmox/core.rb, line 41 def initialize(options = {}) setup(options) authenticate @auth_token.missing_credentials(options) @connection = Fog::Core::Connection.new(@proxmox_url, @persistent, @connection_options) end
not_found_class()
click to toggle source
fallback
# File lib/fog/proxmox/core.rb, line 37 def self.not_found_class Fog::Proxmox::Core::NotFound end
Public Instance Methods
credentials()
click to toggle source
# File lib/fog/proxmox/core.rb, line 68 def credentials options = { provider: 'proxmox', proxmox_auth_method: @auth_method, proxmox_url: @proxmox_uri.to_s, current_user: @current_user } proxmox_options.merge options end
reload()
click to toggle source
# File lib/fog/proxmox/core.rb, line 78 def reload @connection.reset end
setup(options)
click to toggle source
# File lib/fog/proxmox/core.rb, line 48 def setup(options) if options.respond_to?(:config_service?) && options.config_service? configure(options) return end Fog::Proxmox::Variables.to_variables(self, options, 'proxmox') @connection_options = options[:connection_options] || {} @connection_options[:disable_proxy] = true if ENV['DISABLE_PROXY'] == 'true' @connection_options[:ssl_verify_peer] = false if ENV['SSL_VERIFY_PEER'] == 'false' @proxmox_must_reauthenticate = true @persistent = options[:persistent] || false @token ||= options[:proxmox_token] @auth_method ||= options[:proxmox_auth_method] if @token @proxmox_can_reauthenticate = false else @proxmox_can_reauthenticate = true end end
user_token?()
click to toggle source
# File lib/fog/proxmox/core.rb, line 32 def user_token? @auth_token == 'user_token' end
Private Instance Methods
authenticate()
click to toggle source
# File lib/fog/proxmox/core.rb, line 121 def authenticate if @proxmox_must_reauthenticate @token = nil if @proxmox_must_reauthenticate @auth_token = Fog::Proxmox::Auth::Token.build(proxmox_options, @connection_options) @current_user = proxmox_options[:proxmox_userid] ? proxmox_options[:proxmox_userid] : proxmox_options[:proxmox_username] @token = @auth_token.token @expires = @auth_token.expires @proxmox_must_reauthenticate = false else @token = @proxmox_token end uri = URI.parse(@proxmox_url) @path = uri.path true end
authenticate!()
click to toggle source
# File lib/fog/proxmox/core.rb, line 137 def authenticate! @proxmox_must_reauthenticate = true authenticate end
expired?()
click to toggle source
# File lib/fog/proxmox/core.rb, line 84 def expired? return false if @expires.nil? return false if @expires == 0 return @expires - Time.now.utc.to_i < 60 end
proxmox_options()
click to toggle source
# File lib/fog/proxmox/core.rb, line 117 def proxmox_options Fog::Proxmox::Variables.to_hash(self, 'proxmox') end
request(params)
click to toggle source
# File lib/fog/proxmox/core.rb, line 90 def request(params) retried = false begin authenticate! if expired? request_options = params.merge(path: "#{@path}/#{params[:path]}", headers: @auth_token.headers(params[:method], params.respond_to?(:headers) ? params[:headers] : {}, {})) response = @connection.request(request_options) rescue Excon::Errors::Unauthorized => error # token expiration and token renewal possible if !%w[Bad username or password, invalid token value!].include?(error.response.body) && @proxmox_can_reauthenticate && !retried authenticate! retried = true retry # bad credentials or token renewal not possible else raise error end rescue Excon::Errors::HTTPStatusError => error raise case error when Excon::Errors::NotFound self.class.not_found_class.slurp(error) else error end end Fog::Proxmox::Json.get_data(response) end