Module: Hecks::Ports::IdentityResolution

Defined in:
lib/hecks/ports/identity_resolution.rb

Overview

AN AUTHENTICATED (issuer, subject) PAIR, RESOLVED TO A STABLE Identity — the other half of the same symmetry Authorization already has for Governance: one adapter registry-wide answers this port, resolved the same zero/one/many way, so an application never has to name Identity directly to ask "who is this."

Answers nil for a pair nothing has linked — the caller decides what that means (refuse, prompt to register, whatever), the same way Authorization#holds_role? answering false decides nothing on its own.

Constant Summary collapse

NAME =
"identity_resolution"

Class Method Summary collapse

Class Method Details

.adapter(registry) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/hecks/ports/identity_resolution.rb', line 24

def adapter(registry)
  implementations = registry.adapters.values.select { |a| a.port == NAME }

  case implementations.size
  when 1 then Adapters.const_get(implementations.first.name)
  when 0
    raise Runtime::WiringError,
          "no adapter implements the #{NAME} port — nothing can resolve an identity"
  else
    raise Runtime::WiringError,
          "#{implementations.size} adapters implement the #{NAME} port " \
          "(#{implementations.map(&:name).sort.join(', ')}) — the runtime will not choose for you"
  end
end

.resolve(registry, issuer:, subject:) ⇒ Object



20
21
22
# File 'lib/hecks/ports/identity_resolution.rb', line 20

def resolve(registry, issuer:, subject:)
  adapter(registry).resolve(registry, issuer: issuer, subject: subject)
end