Class: NebulaToken::TokenRecord

Inherits:
Object
  • Object
show all
Defined in:
lib/nebula_token.rb

Overview

One row per issued token ([N-10]).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_atObject (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_hashObject (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_atObject (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_idObject (readonly)

Returns the value of attribute family_id.



282
283
284
# File 'lib/nebula_token.rb', line 282

def family_id
  @family_id
end

#generationObject (readonly)

Returns the value of attribute generation.



282
283
284
# File 'lib/nebula_token.rb', line 282

def generation
  @generation
end

#idle_expires_atObject (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

#kidObject (readonly)

Returns the value of attribute kid.



282
283
284
# File 'lib/nebula_token.rb', line 282

def kid
  @kid
end

#replaced_by_selectorObject

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_atObject

Returns the value of attribute rotated_at.



282
283
284
# File 'lib/nebula_token.rb', line 282

def rotated_at
  @rotated_at
end

#selectorObject (readonly)

Returns the value of attribute selector.



282
283
284
# File 'lib/nebula_token.rb', line 282

def selector
  @selector
end

#statusObject

Returns the value of attribute status.



282
283
284
# File 'lib/nebula_token.rb', line 282

def status
  @status
end

#user_idObject (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_hashObject (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

Returns:

  • (Boolean)


323
# File 'lib/nebula_token.rb', line 323

def active? = @status == STATUS_ACTIVE

#dup_recordObject



337
338
339
# File 'lib/nebula_token.rb', line 337

def dup_record
  TokenRecord.new(**to_h)
end

#inspectObject 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

Returns:

  • (Boolean)


325
# File 'lib/nebula_token.rb', line 325

def revoked? = @status == STATUS_REVOKED

#rotated?Boolean

Returns:

  • (Boolean)


324
# File 'lib/nebula_token.rb', line 324

def rotated? = @status == STATUS_ROTATED

#to_hObject



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