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_mapping) 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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw:, root:) ⇒ Data

Returns a new instance of Data.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/textus/manifest/data.rb', line 33

def initialize(raw:, root:)
  @raw = raw
  @root = root
  @zones = Array(raw["zones"]).to_h { |z| [z["name"], Array(z["write_policy"])] }
  @zone_readers = Array(raw["zones"]).to_h do |z|
    rp = z["read_policy"]
    [z["name"], rp.nil? ? :all : Array(rp)]
  end
  @audit_config = build_audit_config(raw)
  @role_mapping = RoleKinds.resolve(raw["roles"])
  # Policy is constructed before entries because Entry validators
  # call `entry.in_generator_zone?` which routes through Policy.
  @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.



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

def audit_config
  @audit_config
end

#entriesObject (readonly)

Returns the value of attribute entries.



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

def entries
  @entries
end

#policyObject (readonly)

Returns the value of attribute policy.



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

def policy
  @policy
end

#rawObject (readonly)

Returns the value of attribute raw.



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

def raw
  @raw
end

#role_mappingObject (readonly)

Returns the value of attribute role_mapping.



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

def role_mapping
  @role_mapping
end

#rootObject (readonly)

Returns the value of attribute root.



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

def root
  @root
end

#zone_readersObject (readonly)

Returns the value of attribute zone_readers.



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

def zone_readers
  @zone_readers
end

#zonesObject (readonly)

Returns the value of attribute zones.



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

def zones
  @zones
end

Class Method Details

.parse(raw, root:) ⇒ Object

Raises:



26
27
28
29
30
31
# File 'lib/textus/manifest/data.rb', line 26

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:



16
17
18
19
20
# File 'lib/textus/manifest/data.rb', line 16

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.



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

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