Class: Sbom::Cyclonedx::Generator
- Inherits:
-
Object
- Object
- Sbom::Cyclonedx::Generator
- Defined in:
- lib/sbom/cyclonedx/generator.rb
Constant Summary collapse
- DEFAULT_VERSION =
"1.6"- SUPPORTED_VERSIONS =
%w[1.4 1.5 1.6 1.7].freeze
- LIFECYCLE_PHASES =
%w[ design pre-build build post-build operations discovery decommission ].freeze
Instance Method Summary collapse
- #generate(project_name, sbom_data) ⇒ Object
-
#initialize(format: :json, application: "sbom", version: Sbom::VERSION) ⇒ Generator
constructor
A new instance of Generator.
- #output ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(format: :json, application: "sbom", version: Sbom::VERSION) ⇒ Generator
Returns a new instance of Generator.
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/sbom/cyclonedx/generator.rb', line 17 def initialize(format: :json, application: "sbom", version: Sbom::VERSION) @format = format @application = application @app_version = version @spec_version = ENV.fetch("SBOM_CYCLONEDX_VERSION", DEFAULT_VERSION) @organization = ENV["SBOM_ORGANIZATION"] @output = {} @components = [] @dependencies = [] @element_refs = {} end |
Instance Method Details
#generate(project_name, sbom_data) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/sbom/cyclonedx/generator.rb', line 30 def generate(project_name, sbom_data) return if sbom_data.nil? || (sbom_data.respond_to?(:empty?) && sbom_data.empty?) data = sbom_data.is_a?(Hash) ? sbom_data : sbom_data.to_h @spec_version = normalize_version(data[:version]) if data[:version] uuid = data[:uuid] || "urn:uuid:#{SecureRandom.uuid}" bom_version = data[:bom_version] || "1" component_data = extract_component_data(data) generate_document_header(project_name, component_data, uuid, bom_version) generate_components(data[:packages]) generate_dependencies(data[:relationships]) finalize_output end |
#output ⇒ Object
48 49 50 |
# File 'lib/sbom/cyclonedx/generator.rb', line 48 def output JSON.pretty_generate(@output) end |
#to_h ⇒ Object
52 53 54 |
# File 'lib/sbom/cyclonedx/generator.rb', line 52 def to_h @output end |