Class: Homebrew::Cmd::Vulns Private

Inherits:
AbstractCommand show all
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

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

#argsHomebrew::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.

Parameters:

Returns:



87
88
89
# File 'cmd/vulns.rb', line 87

def brewfile_path(value)
  value.presence if value.is_a?(String)
end

#formulaeArray<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.

Returns:



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'cmd/vulns.rb', line 66

def formulae
  list = if (brewfile = args.brewfile)
    require "bundle/brewfile"
    Homebrew::Bundle::Brewfile.read(file: brewfile_path(brewfile)).entries
                              .select { |e| e.type == :brew }
                              .map { |e| Formulary.resolve(e.name) }
  elsif args.named.any?
    args.named.to_resolved_formulae
  elsif Homebrew::EnvConfig.tap_trust_configured?
    Formula.all
  else
    Formula.installed
  end
  list += list.flat_map { |f| f.recursive_dependencies.map(&:to_formula) } if args.deps?
  list.uniq(&:full_name)
end

#max_summaryInteger

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.

Returns:

Raises:



103
104
105
106
107
108
109
110
# File 'cmd/vulns.rb', line 103

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_severitySymbol?

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.

Returns:

Raises:



92
93
94
95
96
97
98
99
100
# File 'cmd/vulns.rb', line 92

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

#runvoid

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.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'cmd/vulns.rb', line 37

def run
  require "vulns"

  summary_width = max_summary

  results = Homebrew::Vulns::Scanner.new(
    formulae,
    ignore_patches: !args.no_ignore_patches?,
    min_severity:,
  ).scan

  if args.json?
    Homebrew::Vulns::Output.json(results)
  else
    Homebrew::Vulns::Output.text(results, max_summary: summary_width)
  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