Module: Legion::Extensions::Llm::Bedrock::InstanceIdentity

Defined in:
lib/legion/extensions/llm/bedrock/instance_identity.rb

Overview

Deterministic SSOT v3 physical-identity derivation for Bedrock provider instances.

Instance IDENTIFICATION is the operator's CONFIG NAME (InstanceKey.instance_id). The value derived here is the SECONDARY physical id (InstanceKey.physical_id) — region + credential fingerprint — kept for dedup and diagnostics only. It never participates in identity, tuning lookups, or routing.

Single source of truth shared by the discovery actor and the conformance harness. A config is only claimable when it carries a resolvable credential; a credential-less config derives NO physical id (nil) instead of a provider-family fallback.

Class Method Summary collapse

Class Method Details

.derive_credential_fingerprint(instance_cfg:) ⇒ Object

"bearer:" | "ak:" | "profile:", or nil when the config has no resolvable credential.



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/legion/extensions/llm/bedrock/instance_identity.rb', line 37

def derive_credential_fingerprint(instance_cfg:)
  bearer  = instance_cfg[:bearer_token]
  akid    = instance_cfg[:bedrock_access_key_id]
  profile = instance_cfg[:bedrock_profile]

  if bearer.is_a?(::String) && !bearer.strip.empty?
    "bearer:#{::Digest::SHA256.hexdigest(bearer)[0, 8]}"
  elsif akid.is_a?(::String) && !akid.strip.empty?
    "ak:#{::Digest::SHA256.hexdigest(akid)[0, 8]}"
  elsif profile.is_a?(::String) && !profile.strip.empty?
    "profile:#{profile}"
  end
end

.derive_physical_id(instance_cfg:) ⇒ Object

Returns "region/" or nil when the config carries no resolvable credential. The credential segment is never a provider-family fallback identity.



28
29
30
31
32
33
# File 'lib/legion/extensions/llm/bedrock/instance_identity.rb', line 28

def derive_physical_id(instance_cfg:)
  credential = derive_credential_fingerprint(instance_cfg: instance_cfg)
  return nil unless credential

  "#{resolve_region(instance_cfg: instance_cfg)}/#{credential}"
end

.resolve_region(instance_cfg:) ⇒ Object



51
52
53
# File 'lib/legion/extensions/llm/bedrock/instance_identity.rb', line 51

def resolve_region(instance_cfg:)
  instance_cfg[:bedrock_region] || instance_cfg[:region] || 'us-east-1'
end