Class: Reeve::Audit::Entry

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
Query::Scopes
Defined in:
lib/reeve/audit/entry.rb

Overview

One ledger row: which agent, acting for which principal, called which tool with which arguments, what came back, and which rule decided (FR-009).

Append-only (FR-010). The model enforces that as far as a library can: a persisted row is readonly, so update and save raise, and destroy aborts. It cannot enforce it against raw SQL and does not pretend to — the generated migration documents the INSERT+SELECT grant that closes the rest of the gap.

Constant Summary collapse

ALLOW =
"allow"
DENY =
"deny"
OUTCOMES =
[ALLOW, DENY].freeze
REQUIRED =
%i[
  invocation_id occurred_at agent_id tool_name outcome rule guard contract_version
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Query::Scopes

allowed, between, denied, for_agent, for_principal, for_tool

Class Method Details

.contract_versionObject

The contract version this build of the gem writes (FR-015).

Class-level, and deliberately not the same question as entry.contract_version: this is what the gem implements now, while the column on each row is the shape that row was actually written under. They differ for every row written before an upgrade, which is the whole reason the column exists.



35
36
37
# File 'lib/reeve/audit/entry.rb', line 35

def self.contract_version
  CONTRACT_VERSION
end

Instance Method Details

#allowed?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/reeve/audit/entry.rb', line 45

def allowed?
  outcome == ALLOW
end

#denied?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/reeve/audit/entry.rb', line 49

def denied?
  outcome == DENY
end

#readonly?Boolean

False while the row is being inserted, true forever after: the insert is the only write the ledger ever performs.

Returns:

  • (Boolean)


41
42
43
# File 'lib/reeve/audit/entry.rb', line 41

def readonly?
  persisted?
end