Module: CommandTower::Impersonation::EstablishIdentity

Defined in:
lib/command_tower/impersonation/establish_identity.rb

Class Method Summary collapse

Class Method Details

.call(actor:, impersonation_session_id:, mode: :enforce) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/command_tower/impersonation/establish_identity.rb', line 18

def call(actor:, impersonation_session_id:, mode: :enforce)
  overlay = ApplyOverlay.call(actor:, session_id: impersonation_session_id, mode:)
  if overlay.status == :expired && mode.to_sym == :enforce
    CommandTower::Execution::IdentityEnrichment.from_user(actor)
    return EstablishedIdentity.new(user: actor, actor:, session: overlay.session, status: :expired)
  end

  if overlay.status == :active
    CommandTower::Execution::IdentityEnrichment.from_impersonation_session(
      overlay.session,
      actor: overlay.actor,
      target: overlay.target
    )
    return EstablishedIdentity.new(
      user: overlay.target,
      actor: overlay.actor,
      session: overlay.session,
      status: :active
    )
  end

  CommandTower::Execution::IdentityEnrichment.from_user(actor)
  EstablishedIdentity.new(user: actor, actor:, session: overlay.session, status: overlay.status)
end