Module: Misty::Auth::Token

Includes:
HTTP::NetHTTP
Included in:
V2, V3
Defined in:
lib/misty.rb,
lib/misty/errors.rb,
lib/misty/auth/token.rb,
lib/misty/auth/token/v2.rb,
lib/misty/auth/token/v3.rb

Defined Under Namespace

Classes: ExpiryError, URLError, V2, V3

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HTTP::NetHTTP

http_request

Instance Attribute Details

#catalogObject (readonly)

Returns the value of attribute catalog.



6
7
8
# File 'lib/misty/auth/token.rb', line 6

def catalog
  @catalog
end

#dataObject (readonly)

Returns the value of attribute data.



6
7
8
# File 'lib/misty/auth/token.rb', line 6

def data
  @data
end

#expiresObject (readonly)

Returns the value of attribute expires.



6
7
8
# File 'lib/misty/auth/token.rb', line 6

def expires
  @expires
end

#tokenObject (readonly)

Returns the value of attribute token.



6
7
8
# File 'lib/misty/auth/token.rb', line 6

def token
  @token
end

#userObject (readonly)

Returns the value of attribute user.



6
7
8
# File 'lib/misty/auth/token.rb', line 6

def user
  @user
end

Class Method Details

.build(auth) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/misty/auth/token.rb', line 8

def self.build(auth)
  if auth[:tenant_id] || auth[:tenant]
    Misty::Auth::Token::V2.new(auth)
  else
    Misty::Auth::Token::V3.new(auth)
  end
end

Instance Method Details

#getObject



35
36
37
38
# File 'lib/misty/auth/token.rb', line 35

def get
  set(authenticate(@creds)) if expired?
  @token
end

#initialize(auth) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/misty/auth/token.rb', line 16

def initialize(auth)
  @log = auth[:log]

  if auth[:context] && auth[:context][:token] && auth[:context][:expires] && auth[:context][:catalog]
    # Bypass authentication
    @catalog = Misty::Auth::Catalog.new(auth[:context][:catalog])
    @expires = auth[:context][:expires]
    @token = auth[:context][:token]
  else
    raise URLError, 'No URL provided' if auth[:url].nil? || auth[:url].empty?
    @creds = {
      :data            => set_credentials(auth),
      :ssl_verify_mode => auth[:ssl_verify_mode].nil? ? Misty::Config::SSL_VERIFY_MODE : auth[:ssl_verify_mode],
      :uri             => URI.parse(auth[:url])
    }
    set(authenticate(@creds))
  end
end