Class: Necropsy::Bench::ReleaseAudit::RunProvenance

Inherits:
Object
  • Object
show all
Defined in:
lib/necropsy/bench/release_audit/run_provenance.rb

Constant Summary collapse

SCHEMA_VERSION =
1

Instance Method Summary collapse

Constructor Details

#initialize(root:, manifest_path:, config_path:, output_dir:, command:) ⇒ RunProvenance

Returns a new instance of RunProvenance.



14
15
16
17
18
19
20
# File 'lib/necropsy/bench/release_audit/run_provenance.rb', line 14

def initialize(root:, manifest_path:, config_path:, output_dir:, command:)
  @root = File.expand_path(root)
  @manifest_path = File.expand_path(manifest_path)
  @config_path = File.expand_path(config_path)
  @output_dir = File.expand_path(output_dir)
  @command = command
end

Instance Method Details

#capture_source!Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/necropsy/bench/release_audit/run_provenance.rb', line 22

def capture_source!
  ensure_clean!
  {
    'schema_version' => SCHEMA_VERSION,
    'git_ref' => git_head,
    'clean' => true,
    'manifest_sha256' => digest(manifest_path),
    'audit_config_sha256' => digest(config_path)
  }
end

#complete(source, summary) ⇒ Object



33
34
35
36
37
38
# File 'lib/necropsy/bench/release_audit/run_provenance.rb', line 33

def complete(source, summary)
  source.merge(
    'environment' => environment(summary),
    'artifacts' => artifact_digests
  )
end

#load_and_validate!(path) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/necropsy/bench/release_audit/run_provenance.rb', line 44

def load_and_validate!(path)
  payload = JSON.parse(File.read(path))
  expected = capture_source!
  expected.each do |key, value|
    raise Error, "Benchmark provenance mismatch for #{key}" unless payload[key] == value
  end
  validate_environment!(payload.fetch('environment'))
  raise Error, 'Benchmark provenance mismatch for artifacts' unless payload['artifacts'] == artifact_digests

  payload
rescue Errno::ENOENT, JSON::ParserError => e
  raise Error, "Could not load benchmark provenance: #{e.message}"
end

#write(path, payload) ⇒ Object



40
41
42
# File 'lib/necropsy/bench/release_audit/run_provenance.rb', line 40

def write(path, payload)
  File.write(path, "#{JSON.pretty_generate(payload)}\n")
end