Class: Ace::Hitl::Providers::Lab::DaemonBinding

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/hitl/providers/lab/daemon_binding.rb

Overview

The provider=lab binding policy (spec 8wm.t.y21 §1): the minimal client of the lab daemon's read-only hitl_binding socket op. The W647 authority and its record semantics stay lab-side; this client consumes the daemon's narrow projection and fails closed on every doubt. Confined here by the A1 §8 guard — the generic lifecycle never sees this class.

Constant Summary collapse

LIVE_ATTEMPT_STATES =
%w[reserved starting working].freeze
DAEMON_ATTEMPT_OWNER =
"labd"
MAX_REPLY_BYTES =
64 * 1024
TIMEOUT_SECONDS =
10.0
WORK_ID =
/\AW[0-9]+\z/
ATTEMPT_ID =
/\AA-[0-9a-f]{24}\z/

Instance Method Summary collapse

Constructor Details

#initialize(socket_path: nil, identity: Lifecycle::Identity) ⇒ DaemonBinding

Returns a new instance of DaemonBinding.



27
28
29
30
# File 'lib/ace/hitl/providers/lab/daemon_binding.rb', line 27

def initialize(socket_path: nil, identity: Lifecycle::Identity)
  @socket_path = socket_path || ENV["ACE_HITL_LABD_SOCKET"] || "/run/lab/labd.sock"
  @identity = identity
end

Instance Method Details

#require_active(work:, attempt:) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/ace/hitl/providers/lab/daemon_binding.rb', line 41

def require_active(work:, attempt:)
  _work_value, record = query(work, attempt)
  unless record["work"] == work && record["id"] == attempt
    raise Lifecycle::BindingError, "HITL Attempt cannot be verified against its Work"
  end
  unless LIVE_ATTEMPT_STATES.include?(record["state"].to_s)
    raise Lifecycle::BindingError, "HITL Attempt is no longer active"
  end
  nil
end

#validate_request(work:, attempt:, project:, requester:) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/ace/hitl/providers/lab/daemon_binding.rb', line 32

def validate_request(work:, attempt:, project:, requester:)
  work_value, record = query(work, attempt)
  unless work_value["id"] == work && work_value["project"] == project &&
      work_value["active_attempt"] == attempt
    raise Lifecycle::BindingError, "HITL request is not bound to the exact active Work Attempt"
  end
  validate_record(work, attempt, project, requester, record, work_value)
end