Class: VagrantCloud::Auth::HCPToken

Inherits:
Struct
  • Object
show all
Defined in:
lib/vagrant_cloud/auth.rb

Overview

HCP token

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#expires_atObject

Returns the value of attribute expires_at

Returns:

  • (Object)

    the current value of expires_at



36
37
38
# File 'lib/vagrant_cloud/auth.rb', line 36

def expires_at
  @expires_at
end

#tokenObject

Returns the value of attribute token

Returns:

  • (Object)

    the current value of token



36
37
38
# File 'lib/vagrant_cloud/auth.rb', line 36

def token
  @token
end

Instance Method Details

#expired?Boolean

Note:

Will show token as expired TOKEN_EXPIRY_PADDING

seconds prior to actual expiry

Returns:

  • (Boolean)

    token is expired



48
49
50
51
52
# File 'lib/vagrant_cloud/auth.rb', line 48

def expired?
  validate!

  Time.now.to_i > (expires_at - TOKEN_EXPIRY_PADDING)
end

#valid?Boolean

Returns token is not expired.

Returns:

  • (Boolean)

    token is not expired



55
56
57
# File 'lib/vagrant_cloud/auth.rb', line 55

def valid?
  !expired?
end

#validate!Object

Raise exception if any values are missing



38
39
40
41
42
43
# File 'lib/vagrant_cloud/auth.rb', line 38

def validate!
  [:token, :expires_at].each do |name|
    raise ArgumentError,
      "Missing required token value - #{name.inspect}" if self.send(name).nil?
  end
end