Class: Textus::Manifest::Data

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/manifest/data.rb

Overview

Immutable, parsed view of a manifest YAML document.

Holds raw structural data (zones, entries, audit_config, role_caps) but no behaviour beyond accessors. Behaviour (zone authority, key resolution, rules) lives on Manifest::Policy / Resolver / Rules.

Constant Summary collapse

AUDIT_DEFAULTS =
{ max_size: 10_485_760, keep: 5 }.freeze
WORKER_DEFAULTS =
{ pool: 4, poll: 5, lease_ttl: 60, max_attempts: 3 }.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw:, root:) ⇒ Data

Returns a new instance of Data.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/textus/manifest/data.rb', line 36

def initialize(raw:, root:)
  @raw = raw
  @root = root
  # Write authority is derived from capabilities × zone-kind (ADR 0030),
  # not a per-zone writer list. "Which zones are declared" lives in the
  # one kind-keyed map below (declared_zone_kinds); membership checks by
  # read-side callers (boot, maintenance/zone_mv) use its keyset (ADR 0034).
  @declared_zone_kinds = Array(raw["zones"]).to_h do |z|
    [z["name"], z["kind"]&.to_sym]
  end
  @zone_descs  = Array(raw["zones"]).to_h { |z| [z["name"], z["desc"]] }
  # Only zones that actually declare an owner — keep nil-tombstones out so a
  # future `zone_owners.key?(name)` means "owner declared", not "zone exists".
  @zone_owners = Array(raw["zones"]).to_h { |z| [z["name"], z["owner"]] }.compact
  @audit_config = build_audit_config(raw)
  @worker_config = build_worker_config(raw)
  @role_caps = Capabilities.resolve(raw["roles"])
  # Policy is constructed before entries because Entry validators
  # use the entry's own `derived?` and similar helpers that call into
  # Policy; Policy must exist before entries are built.
  @policy = Policy.new(self)
  @entries = build_entries(raw)
  validate_declared_keys!
  freeze
end

Instance Attribute Details

#audit_configObject (readonly)

Returns the value of attribute audit_config.



15
16
17
# File 'lib/textus/manifest/data.rb', line 15

def audit_config
  @audit_config
end

#declared_zone_kindsObject (readonly)

Returns the value of attribute declared_zone_kinds.



15
16
17
# File 'lib/textus/manifest/data.rb', line 15

def declared_zone_kinds
  @declared_zone_kinds
end

#entriesObject (readonly)

Returns the value of attribute entries.



15
16
17
# File 'lib/textus/manifest/data.rb', line 15

def entries
  @entries
end

#policyObject (readonly)

Returns the value of attribute policy.



15
16
17
# File 'lib/textus/manifest/data.rb', line 15

def policy
  @policy
end

#rawObject (readonly)

Returns the value of attribute raw.



15
16
17
# File 'lib/textus/manifest/data.rb', line 15

def raw
  @raw
end

#role_capsObject (readonly)

Returns the value of attribute role_caps.



15
16
17
# File 'lib/textus/manifest/data.rb', line 15

def role_caps
  @role_caps
end

#rootObject (readonly)

Returns the value of attribute root.



15
16
17
# File 'lib/textus/manifest/data.rb', line 15

def root
  @root
end

#worker_configObject (readonly)

Returns the value of attribute worker_config.



15
16
17
# File 'lib/textus/manifest/data.rb', line 15

def worker_config
  @worker_config
end

#zone_descsObject (readonly)

Returns the value of attribute zone_descs.



15
16
17
# File 'lib/textus/manifest/data.rb', line 15

def zone_descs
  @zone_descs
end

#zone_ownersObject (readonly)

Returns the value of attribute zone_owners.



15
16
17
# File 'lib/textus/manifest/data.rb', line 15

def zone_owners
  @zone_owners
end

Class Method Details

.parse(raw, root:) ⇒ Object

Raises:



29
30
31
32
33
34
# File 'lib/textus/manifest/data.rb', line 29

def self.parse(raw, root:)
  raise BadFrontmatter.new(File.join(root.to_s, "manifest.yaml"), "manifest must declare zones:") if Array(raw["zones"]).empty?

  Schema.validate!(raw)
  new(raw: raw, root: root)
end

.validate_key!(key) ⇒ Object

Raises:



19
20
21
22
23
# File 'lib/textus/manifest/data.rb', line 19

def self.validate_key!(key)
  raise UsageError.new("empty key") if key.nil? || key.empty?

  Key::Grammar.validate!(key)
end

Instance Method Details

#validate_key!(key) ⇒ Object

Forwarder used by Resolver and Entry classes that received a Data but were written against the historical Manifest API.



27
# File 'lib/textus/manifest/data.rb', line 27

def validate_key!(key) = self.class.validate_key!(key)