Class: Homebrew::Cmd::Vulns Private
- Inherits:
-
AbstractCommand
- Object
- AbstractCommand
- Homebrew::Cmd::Vulns
- Defined in:
- cmd/vulns.rb,
sorbet/rbi/dsl/homebrew/cmd/vulns.rbi
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
Defined Under Namespace
Classes: Args
Constant Summary collapse
- SEVERITIES =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
%w[low medium high critical].freeze
Instance Method Summary collapse
- #args ⇒ Homebrew::Cmd::Vulns::Args private
-
#brewfile_path(value) ⇒ String?
private
A bare
--brewfile(no=path) yieldstruefrom OptionParser at runtime; the generated RBI types it asT.nilable(String), so accept the wider type here and normalisetrue/""to thenildefault. - #formulae ⇒ Array<Formula> private
- #installed_formulae ⇒ Array<Formula> private
- #max_summary ⇒ Integer private
- #min_severity ⇒ Symbol? private
- #run ⇒ void private
- #untrusted_skipped ⇒ Array<String> private
Methods inherited from AbstractCommand
command, command_name, dev_cmd?, #initialize, parser, ruby_cmd?
Methods included from Utils::Output::Mixin
#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning
Constructor Details
This class inherits a constructor from Homebrew::AbstractCommand
Instance Method Details
#args ⇒ Homebrew::Cmd::Vulns::Args
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
10 |
# File 'sorbet/rbi/dsl/homebrew/cmd/vulns.rbi', line 10 def args; end |
#brewfile_path(value) ⇒ String?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
A bare --brewfile (no =path) yields true from OptionParser at
runtime; the generated RBI types it as T.nilable(String), so accept
the wider type here and normalise true/"" to the nil default.
124 125 126 |
# File 'cmd/vulns.rb', line 124 def brewfile_path(value) value.presence if value.is_a?(String) end |
#formulae ⇒ Array<Formula>
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'cmd/vulns.rb', line 89 def formulae list = T.let([], T::Array[Formula]) if (brewfile = args.brewfile) require "bundle/brewfile" list += Homebrew::Bundle::Brewfile.read(file: brewfile_path(brewfile)).entries .select { |e| e.type == :brew } .map { |e| Formulary.resolve(e.name) } end list += args.named.to_resolved_formulae if args.named.any? list = installed_formulae if !args.brewfile && args.no_named? list += list.flat_map { |f| f.recursive_dependencies.map(&:to_formula) } if args.deps? list.uniq(&:full_name) end |
#installed_formulae ⇒ Array<Formula>
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
104 105 106 107 108 109 110 111 112 113 |
# File 'cmd/vulns.rb', line 104 def installed_formulae Formula.racks.filter_map do |rack| Formulary.from_rack(rack) rescue Homebrew::UntrustedTapError => e untrusted_skipped << e..lines.first.to_s.strip nil rescue nil end.uniq(&:name) end |
#max_summary ⇒ Integer
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
140 141 142 143 144 145 146 147 |
# File 'cmd/vulns.rb', line 140 def max_summary raw = args.max_summary return Homebrew::Vulns::Output::DEFAULT_MAX_SUMMARY if raw.nil? raise UsageError, "`--max-summary` must be a non-negative integer" unless raw.match?(/\A\d+\z/) raw.to_i end |
#min_severity ⇒ Symbol?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
129 130 131 132 133 134 135 136 137 |
# File 'cmd/vulns.rb', line 129 def min_severity raw = args.severity return if raw.nil? raw = raw.downcase raise UsageError, "`--severity` must be one of: #{SEVERITIES.join(", ")}" unless SEVERITIES.include?(raw) raw.to_sym end |
#run ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'cmd/vulns.rb', line 48 def run require "vulns" summary_width = max_summary severity = min_severity results = Homebrew::Vulns::Scanner.new( formulae, ignore_patches: !args.no_ignore_patches?, min_severity: severity, only_fixed: args.fix_available?, except_fixed: args.no_fix_available?, ).scan if args.json? Homebrew::Vulns::Output.json(results) else Homebrew::Vulns::Output.text(results, max_summary: summary_width) end if untrusted_skipped.any? kegs = Utils.pluralize("installed keg", untrusted_skipped.size, include_count: true) opoo <<~EOS #{kegs} from an untrusted tap not scanned: #{untrusted_skipped.join("\n ")} Run `brew trust` on the formula or tap to include it in future scans. EOS Homebrew.failed = true end if results.outdated_without_sbom.any? opoo <<~EOS The installed source of #{results.outdated_without_sbom.sort.join(", ")} could not be determined (older than the current formula and no SBOM was written at install time). Results above reflect the current formula version, not what is installed. Run `brew upgrade` for accurate results. EOS Homebrew.failed = true end Homebrew.failed = true if results.any_open? end |
#untrusted_skipped ⇒ Array<String>
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
116 117 118 |
# File 'cmd/vulns.rb', line 116 def untrusted_skipped @untrusted_skipped ||= T.let([], T.nilable(T::Array[String])) end |