Class: NebulaToken::TokenRecord
- Inherits:
-
Object
- Object
- NebulaToken::TokenRecord
- Defined in:
- lib/nebula_token.rb
Overview
One row per issued token ([N-10]).
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#device_id_hash ⇒ Object
readonly
Returns the value of attribute device_id_hash.
-
#family_expires_at ⇒ Object
readonly
Returns the value of attribute family_expires_at.
-
#family_id ⇒ Object
readonly
Returns the value of attribute family_id.
-
#generation ⇒ Object
readonly
Returns the value of attribute generation.
-
#idle_expires_at ⇒ Object
readonly
Returns the value of attribute idle_expires_at.
-
#kid ⇒ Object
readonly
Returns the value of attribute kid.
-
#replaced_by_selector ⇒ Object
Returns the value of attribute replaced_by_selector.
-
#rotated_at ⇒ Object
Returns the value of attribute rotated_at.
-
#selector ⇒ Object
readonly
Returns the value of attribute selector.
-
#status ⇒ Object
Returns the value of attribute status.
-
#user_id ⇒ Object
readonly
Returns the value of attribute user_id.
-
#verifier_hash ⇒ Object
readonly
Returns the value of attribute verifier_hash.
Class Method Summary collapse
-
.integer(value) ⇒ Object
Kernel#Integer alone reads "010" as octal and "0x10" as hex; a database column is always base 10.
Instance Method Summary collapse
- #active? ⇒ Boolean
- #dup_record ⇒ Object
-
#initialize(selector:, verifier_hash:, kid:, family_id:, generation:, user_id:, created_at:, family_expires_at:, idle_expires_at:, device_id_hash: nil, status: STATUS_ACTIVE, rotated_at: nil, replaced_by_selector: nil) ⇒ TokenRecord
constructor
rubocop:disable Metrics/ParameterLists.
-
#inspect ⇒ Object
(also: #to_s)
[N-14]/[N-46]: no secret-derived material in a debug representation.
- #revoked? ⇒ Boolean
- #rotated? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(selector:, verifier_hash:, kid:, family_id:, generation:, user_id:, created_at:, family_expires_at:, idle_expires_at:, device_id_hash: nil, status: STATUS_ACTIVE, rotated_at: nil, replaced_by_selector: nil) ⇒ TokenRecord
rubocop:disable Metrics/ParameterLists
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 |
# File 'lib/nebula_token.rb', line 287 def initialize(selector:, verifier_hash:, kid:, family_id:, generation:, user_id:, created_at:, family_expires_at:, idle_expires_at:, device_id_hash: nil, status: STATUS_ACTIVE, rotated_at: nil, replaced_by_selector: nil) @selector = selector @verifier_hash = verifier_hash @kid = kid @family_id = family_id @user_id = user_id @device_id_hash = device_id_hash @replaced_by_selector = replaced_by_selector # [N-2]: timestamps and the generation counter are integers. A store that # returns them as strings (the pg gem does, by default) must not silently # produce `Integer < String` comparisons deep inside the engine. @generation = TokenRecord.integer(generation) @created_at = TokenRecord.integer(created_at) @family_expires_at = TokenRecord.integer(family_expires_at) @idle_expires_at = TokenRecord.integer(idle_expires_at) @rotated_at = rotated_at.nil? ? nil : TokenRecord.integer(rotated_at) self.status = status end |
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
282 283 284 |
# File 'lib/nebula_token.rb', line 282 def created_at @created_at end |
#device_id_hash ⇒ Object (readonly)
Returns the value of attribute device_id_hash.
282 283 284 |
# File 'lib/nebula_token.rb', line 282 def device_id_hash @device_id_hash end |
#family_expires_at ⇒ Object (readonly)
Returns the value of attribute family_expires_at.
282 283 284 |
# File 'lib/nebula_token.rb', line 282 def family_expires_at @family_expires_at end |
#family_id ⇒ Object (readonly)
Returns the value of attribute family_id.
282 283 284 |
# File 'lib/nebula_token.rb', line 282 def family_id @family_id end |
#generation ⇒ Object (readonly)
Returns the value of attribute generation.
282 283 284 |
# File 'lib/nebula_token.rb', line 282 def generation @generation end |
#idle_expires_at ⇒ Object (readonly)
Returns the value of attribute idle_expires_at.
282 283 284 |
# File 'lib/nebula_token.rb', line 282 def idle_expires_at @idle_expires_at end |
#kid ⇒ Object (readonly)
Returns the value of attribute kid.
282 283 284 |
# File 'lib/nebula_token.rb', line 282 def kid @kid end |
#replaced_by_selector ⇒ Object
Returns the value of attribute replaced_by_selector.
282 283 284 |
# File 'lib/nebula_token.rb', line 282 def replaced_by_selector @replaced_by_selector end |
#rotated_at ⇒ Object
Returns the value of attribute rotated_at.
282 283 284 |
# File 'lib/nebula_token.rb', line 282 def rotated_at @rotated_at end |
#selector ⇒ Object (readonly)
Returns the value of attribute selector.
282 283 284 |
# File 'lib/nebula_token.rb', line 282 def selector @selector end |
#status ⇒ Object
Returns the value of attribute status.
282 283 284 |
# File 'lib/nebula_token.rb', line 282 def status @status end |
#user_id ⇒ Object (readonly)
Returns the value of attribute user_id.
282 283 284 |
# File 'lib/nebula_token.rb', line 282 def user_id @user_id end |
#verifier_hash ⇒ Object (readonly)
Returns the value of attribute verifier_hash.
282 283 284 |
# File 'lib/nebula_token.rb', line 282 def verifier_hash @verifier_hash end |
Class Method Details
.integer(value) ⇒ Object
Kernel#Integer alone reads "010" as octal and "0x10" as hex; a database column is always base 10.
312 313 314 |
# File 'lib/nebula_token.rb', line 312 def self.integer(value) value.is_a?(String) ? Integer(value, 10) : Integer(value) end |
Instance Method Details
#active? ⇒ Boolean
323 |
# File 'lib/nebula_token.rb', line 323 def active? = @status == STATUS_ACTIVE |
#dup_record ⇒ Object
337 338 339 |
# File 'lib/nebula_token.rb', line 337 def dup_record TokenRecord.new(**to_h) end |
#inspect ⇒ Object Also known as: to_s
[N-14]/[N-46]: no secret-derived material in a debug representation.
342 343 344 345 346 |
# File 'lib/nebula_token.rb', line 342 def inspect "#<NebulaToken::TokenRecord selector=#{@selector.inspect} kid=#{@kid.inspect} " \ "family_id=#{@family_id.inspect} user_id=#{@user_id.inspect} generation=#{@generation} " \ "status=#{@status.inspect} verifier_hash=[REDACTED] device_id_hash=[REDACTED]>" end |
#revoked? ⇒ Boolean
325 |
# File 'lib/nebula_token.rb', line 325 def revoked? = @status == STATUS_REVOKED |
#rotated? ⇒ Boolean
324 |
# File 'lib/nebula_token.rb', line 324 def rotated? = @status == STATUS_ROTATED |
#to_h ⇒ Object
327 328 329 330 331 332 333 334 335 |
# File 'lib/nebula_token.rb', line 327 def to_h { selector: @selector, verifier_hash: @verifier_hash, kid: @kid, family_id: @family_id, generation: @generation, user_id: @user_id, device_id_hash: @device_id_hash, created_at: @created_at, family_expires_at: @family_expires_at, idle_expires_at: @idle_expires_at, status: @status, rotated_at: @rotated_at, replaced_by_selector: @replaced_by_selector } end |