Class: Legion::Identity::Lease
- Inherits:
-
Object
- Object
- Legion::Identity::Lease
- Defined in:
- lib/legion/identity/lease.rb
Instance Attribute Summary collapse
-
#credential ⇒ Object
readonly
Returns the value of attribute credential.
-
#expires_at ⇒ Object
readonly
Returns the value of attribute expires_at.
-
#issued_at ⇒ Object
readonly
Returns the value of attribute issued_at.
-
#lease_id ⇒ Object
readonly
Returns the value of attribute lease_id.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#provider ⇒ Object
readonly
Returns the value of attribute provider.
-
#renewable ⇒ Object
readonly
Returns the value of attribute renewable.
Instance Method Summary collapse
- #expired? ⇒ Boolean
-
#initialize(provider:, credential:, lease_id: nil, expires_at: nil, renewable: false, issued_at: nil, metadata: {}) ⇒ Lease
constructor
rubocop:disable Metrics/ParameterLists.
- #stale? ⇒ Boolean
- #to_h ⇒ Object
- #token ⇒ Object
- #ttl_seconds ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(provider:, credential:, lease_id: nil, expires_at: nil, renewable: false, issued_at: nil, metadata: {}) ⇒ Lease
rubocop:disable Metrics/ParameterLists
8 9 10 11 12 13 14 15 16 |
# File 'lib/legion/identity/lease.rb', line 8 def initialize(provider:, credential:, lease_id: nil, expires_at: nil, renewable: false, issued_at: nil, metadata: {}) # rubocop:disable Metrics/ParameterLists @provider = provider @credential = credential @lease_id = lease_id @expires_at = expires_at @renewable = renewable @issued_at = issued_at || Time.now @metadata = .freeze end |
Instance Attribute Details
#credential ⇒ Object (readonly)
Returns the value of attribute credential.
6 7 8 |
# File 'lib/legion/identity/lease.rb', line 6 def credential @credential end |
#expires_at ⇒ Object (readonly)
Returns the value of attribute expires_at.
6 7 8 |
# File 'lib/legion/identity/lease.rb', line 6 def expires_at @expires_at end |
#issued_at ⇒ Object (readonly)
Returns the value of attribute issued_at.
6 7 8 |
# File 'lib/legion/identity/lease.rb', line 6 def issued_at @issued_at end |
#lease_id ⇒ Object (readonly)
Returns the value of attribute lease_id.
6 7 8 |
# File 'lib/legion/identity/lease.rb', line 6 def lease_id @lease_id end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
6 7 8 |
# File 'lib/legion/identity/lease.rb', line 6 def @metadata end |
#provider ⇒ Object (readonly)
Returns the value of attribute provider.
6 7 8 |
# File 'lib/legion/identity/lease.rb', line 6 def provider @provider end |
#renewable ⇒ Object (readonly)
Returns the value of attribute renewable.
6 7 8 |
# File 'lib/legion/identity/lease.rb', line 6 def renewable @renewable end |
Instance Method Details
#expired? ⇒ Boolean
22 23 24 25 26 |
# File 'lib/legion/identity/lease.rb', line 22 def expired? return false if expires_at.nil? Time.now >= expires_at end |
#stale? ⇒ Boolean
28 29 30 31 32 33 34 35 36 |
# File 'lib/legion/identity/lease.rb', line 28 def stale? return false if expires_at.nil? || issued_at.nil? elapsed = Time.now - issued_at total = expires_at - issued_at return false if total <= 0 elapsed >= (total * 0.5) end |
#to_h ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/legion/identity/lease.rb', line 49 def to_h { provider: provider, lease_id: lease_id, expires_at: expires_at&.iso8601, renewable: renewable, issued_at: issued_at&.iso8601, ttl: ttl_seconds, valid: valid?, metadata: } end |
#token ⇒ Object
18 19 20 |
# File 'lib/legion/identity/lease.rb', line 18 def token credential end |
#ttl_seconds ⇒ Object
38 39 40 41 42 43 |
# File 'lib/legion/identity/lease.rb', line 38 def ttl_seconds return nil if expires_at.nil? remaining = expires_at - Time.now remaining.negative? ? 0 : remaining.to_i end |
#valid? ⇒ Boolean
45 46 47 |
# File 'lib/legion/identity/lease.rb', line 45 def valid? !credential.nil? && !expired? end |