class Chelsea::Bom
Class to convert dependencies to SBOM xml
Public Class Methods
new(dependencies)
click to toggle source
# File lib/chelsea/bom.rb, line 25 def initialize(dependencies) @dependencies = dependencies end
Public Instance Methods
collect()
click to toggle source
# File lib/chelsea/bom.rb, line 29 def collect xml to_s end
random_urn_uuid()
click to toggle source
# File lib/chelsea/bom.rb, line 42 def random_urn_uuid "urn:uuid:#{SecureRandom.uuid}" end
to_s()
click to toggle source
# File lib/chelsea/bom.rb, line 38 def to_s Ox.dump(@xml) end
xml()
click to toggle source
# File lib/chelsea/bom.rb, line 34 def xml @xml ||= _get_xml end
Private Instance Methods
_bom_xml()
click to toggle source
# File lib/chelsea/bom.rb, line 61 def _bom_xml bom = Ox::Element.new('bom') bom[:xmlns] = 'http://cyclonedx.org/schema/bom/1.1' bom[:version] = '1' bom[:serialNumber] = random_urn_uuid bom end
_component_xml(name, version)
click to toggle source
# File lib/chelsea/bom.rb, line 77 def _component_xml(name, version) component = Ox::Element.new('component') component[:type] = 'library' n = Ox::Element.new('name') n << name v = Ox::Element.new('version') v << version.version purl = Ox::Element.new('purl') purl << Chelsea.to_purl(name, version.version) component << n << v << purl component end
_get_xml()
click to toggle source
# File lib/chelsea/bom.rb, line 48 def _get_xml doc = Ox::Document.new doc << _root_xml bom = _bom_xml doc << bom components = Ox::Element.new('components') @dependencies.each do |_, (name, version)| components << _component_xml(name, version) end bom << components doc end
_root_xml()
click to toggle source
# File lib/chelsea/bom.rb, line 69 def _root_xml instruct = Ox::Instruct.new(:xml) instruct[:version] = '1.0' instruct[:encoding] = 'UTF-8' instruct[:standalone] = 'yes' instruct end
_show_logo()
click to toggle source
# File lib/chelsea/bom.rb, line 90 def _show_logo # rubocop:disable Metrics/MethodLength logo = %( -o/ -+hNmNN- .:+osyhddddyso/-``ody+- .NN. /mMMdhssooooooosyhdmhs/. /Mm- oMs` `.-:. oMNs. . `N. `. .+hNh+` +N. yo -m` -d` `dm. `:smd+. `yMM. -m`mM/ -mN/`ddMs -sNh/ .dy-M- dmdsd/m--dmo Nh `o: /o` `+md- :m/ N: /y `Nd` do my .dMy. .hMy` `oN+ om- m: + . `No +NN+oNm: .d+ `hd` d: `Mo .dMMy SBOM `d+ms` d: `. -M+ `yMhmNo` BABY `hN/- d/ /: yd /o -M/ /NN/ +Nm: +Nd.-mo m+ dm`/mmo-NMo /M- .dMs` `o/ /mN+ `hh. N+ -MMdN//NNhhMysm /- `+mMs` +mo N+ sN/Ny hd``yMMh :yNNs. `sm+M+ dd.`` `` /d- oy. `/yNNh/` .yM+ `yNy/` oMm` `/sdMdo- .. `/ymmys+///++shN+/Nm. /NMNo. `-/+ooo+/:.` :NN- /MMo` -NNoNM+ :MMM+ :d/ ) puts logo end