Class: SupplyChain::Slsa::ProvenanceStatement

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Serializers::JSON, CamelCaseJson
Defined in:
app/models/supply_chain/slsa/provenance_statement.rb

Defined Under Namespace

Classes: BuildDefinition, BuildMetadata, Builder, ExternalParameters, Predicate, RunDetails

Constant Summary collapse

PREDICATE_TYPE_V1 =
"https://slsa.dev/provenance/v1"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CamelCaseJson

#deep_change_case

Constructor Details

#initializeProvenanceStatement

Returns a new instance of ProvenanceStatement.



43
44
45
46
# File 'app/models/supply_chain/slsa/provenance_statement.rb', line 43

def initialize
  @_type = "https://in-toto.io/Statement/v1"
  @predicate_type = PREDICATE_TYPE_V1
end

Instance Attribute Details

#_typeObject

Returns the value of attribute _type.



25
26
27
# File 'app/models/supply_chain/slsa/provenance_statement.rb', line 25

def _type
  @_type
end

#predicateObject

Returns the value of attribute predicate.



25
26
27
# File 'app/models/supply_chain/slsa/provenance_statement.rb', line 25

def predicate
  @predicate
end

#predicate_typeObject

Returns the value of attribute predicate_type.



25
26
27
# File 'app/models/supply_chain/slsa/provenance_statement.rb', line 25

def predicate_type
  @predicate_type
end

#subjectObject

Returns the value of attribute subject.



25
26
27
# File 'app/models/supply_chain/slsa/provenance_statement.rb', line 25

def subject
  @subject
end

Class Method Details

.from_build(build) ⇒ Object

Raises:

  • (ArgumentError)


29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/models/supply_chain/slsa/provenance_statement.rb', line 29

def self.from_build(build)
  archives = build.job_artifacts.filter { |artifact| artifact.file_type == "archive" }
  raise ArgumentError, 'artifacts associated with build do not contain a single archive' if archives.length != 1

  archive = archives[0]
  archive_resource = ResourceDescriptor.new(name: archive.file.filename, digest: { sha256: archive.file_sha256 })

  provenance_statement = ProvenanceStatement.new
  provenance_statement.subject = [archive_resource]
  provenance_statement.predicate = Predicate.from_build(build)

  provenance_statement
end

Instance Method Details

#as_json(options = nil) ⇒ Object



48
49
50
# File 'app/models/supply_chain/slsa/provenance_statement.rb', line 48

def as_json(options = nil)
  deep_change_case(super)
end

#attributesObject



52
53
54
# File 'app/models/supply_chain/slsa/provenance_statement.rb', line 52

def attributes
  { '_type' => nil, 'subject' => nil, 'predicate_type' => nil, 'predicate' => nil }
end