Module: Fog::Proxmox::Auth::Token
- Included in:
- AccessTicket, UserToken
- Defined in:
- lib/fog/proxmox/auth/token.rb,
lib/fog/proxmox/auth/token/user_token.rb,
lib/fog/proxmox/auth/token/access_ticket.rb
Defined Under Namespace
Classes: AccessTicket, ExpiryError, URLError, UserToken
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#expires ⇒ Object
readonly
Returns the value of attribute expires.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#userid ⇒ Object
readonly
Returns the value of attribute userid.
Class Method Summary collapse
Instance Method Summary collapse
- #authenticate(proxmox_options, connection_options = {}) ⇒ Object
- #expired? ⇒ Boolean
- #initialize(proxmox_options, options = {}) ⇒ Object
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
33 34 35 |
# File 'lib/fog/proxmox/auth/token.rb', line 33 def data @data end |
#expires ⇒ Object (readonly)
Returns the value of attribute expires.
33 34 35 |
# File 'lib/fog/proxmox/auth/token.rb', line 33 def expires @expires end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
33 34 35 |
# File 'lib/fog/proxmox/auth/token.rb', line 33 def token @token end |
#userid ⇒ Object (readonly)
Returns the value of attribute userid.
33 34 35 |
# File 'lib/fog/proxmox/auth/token.rb', line 33 def userid @userid end |
Class Method Details
.build(proxmox_options, options) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/fog/proxmox/auth/token.rb', line 51 def self.build(, ) unless .key? :proxmox_auth_method raise ArgumentError, 'Missing required proxmox_auth_method in options.' end auth_method = [:proxmox_auth_method] if auth_method == Fog::Proxmox::Auth::Token::AccessTicket::NAME Fog::Proxmox::Auth::Token::AccessTicket.new(, ) elsif auth_method == Fog::Proxmox::Auth::Token::UserToken::NAME Fog::Proxmox::Auth::Token::UserToken.new(, ) 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 |
Instance Method Details
#authenticate(proxmox_options, connection_options = {}) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/fog/proxmox/auth/token.rb', line 68 def authenticate(, = {}) uri = URI.parse([:proxmox_url]) request = { expects: [200, 201], headers: headers(auth_method, , { Accept: 'application/json' }), body: auth_body(), method: auth_method, path: uri.path + auth_path() } connection = Fog::Core::Connection.new( uri.to_s, false, ) response = connection.request(request) Json.get_data(response) end |
#expired? ⇒ Boolean
86 87 88 89 90 |
# 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 |
#initialize(proxmox_options, options = {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/fog/proxmox/auth/token.rb', line 38 def initialize(, = {}) if [:proxmox_url].nil? || [:proxmox_url].empty? raise URLError, 'No proxmox_url provided' end @token ||= '' @token_id ||= '' @userid ||= '' @data = authenticate(, ) build_credentials(, data) end |