Module: Homebrew::Trust Private

Extended by:
Utils::Output::Mixin
Defined in:
trust.rb

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

Class Method Summary collapse

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_outdated, pretty_uninstalled, pretty_upgradable

Class Method Details

.clear!(type) ⇒ 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.

Parameters:



63
64
65
66
67
# File 'trust.rb', line 63

def self.clear!(type)
  store = trust_store
  store.delete(setting_key(type))
  write_trust_store(store)
end

.enabled?Boolean

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:

  • (Boolean)


28
29
30
# File 'trust.rb', line 28

def self.enabled?
  Homebrew::EnvConfig.require_tap_trust? && !Homebrew::EnvConfig.no_require_tap_trust?
end

.normalise_name(name) ⇒ 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.

Parameters:

Returns:



139
140
141
# File 'trust.rb', line 139

def self.normalise_name(name)
  name.downcase
end

.require_trusted_cask!(token, path) ⇒ 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.

Parameters:



93
94
95
96
97
98
99
100
101
102
103
# File 'trust.rb', line 93

def self.require_trusted_cask!(token, path)
  return if Homebrew::EnvConfig.no_require_tap_trust?
  return unless (tap = tap_from_path(path))
  return if trusted_tap?(tap)

  full_name = "#{tap.name}/#{::Utils.name_from_full_name(token)}"
  return if trusted?(:cask, full_name)
  return trust_by_default!(tap) unless enabled?

  raise_untrusted!(:cask, full_name, tap)
end

.require_trusted_command!(path, command = nil) ⇒ 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.

Parameters:



106
107
108
109
110
111
112
113
114
115
116
# File 'trust.rb', line 106

def self.require_trusted_command!(path, command = nil)
  return if Homebrew::EnvConfig.no_require_tap_trust?
  return unless (tap = tap_from_path(path))
  return if trusted_tap?(tap)

  full_name = "#{tap.name}/#{command || path.basename(path.extname).to_s.delete_prefix("brew-")}"
  return if trusted?(:command, full_name)
  return trust_by_default!(tap) unless enabled?

  raise_untrusted!(:command, full_name, tap)
end

.require_trusted_formula!(name, path) ⇒ 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.

Parameters:



80
81
82
83
84
85
86
87
88
89
90
# File 'trust.rb', line 80

def self.require_trusted_formula!(name, path)
  return if Homebrew::EnvConfig.no_require_tap_trust?
  return unless (tap = tap_from_path(path))
  return if trusted_tap?(tap)

  full_name = "#{tap.name}/#{::Utils.name_from_full_name(name)}"
  return if trusted?(:formula, full_name)
  return trust_by_default!(tap) unless enabled?

  raise_untrusted!(:formula, full_name, tap)
end

.setting_key(type) ⇒ 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.

Parameters:

Returns:



129
130
131
# File 'trust.rb', line 129

def self.setting_key(type)
  SETTING_KEYS.fetch(type).to_s
end

.target(name, type: nil, include_existing: false) ⇒ Array<(Symbol, 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.

Parameters:

  • name (String)
  • type (Symbol, nil) (defaults to: nil)
  • include_existing (Boolean) (defaults to: false)

Returns:



144
145
146
147
148
# File 'trust.rb', line 144

def self.target(name, type: nil, include_existing: false)
  return [type, trust_name(type, name)] if type

  infer_target(name, include_existing:)
end

.trust!(type, name) ⇒ Boolean

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.

Parameters:

Returns:

  • (Boolean)


33
34
35
36
37
38
39
40
41
42
43
# File 'trust.rb', line 33

def self.trust!(type, name)
  key = setting_key(type)
  entries = trusted_entries(type)
  name = normalise_name(name)
  return false if entries.include?(name)

  store = trust_store
  store[key] = (entries + [name]).sort
  write_trust_store(store)
  true
end

.trusted?(type, name) ⇒ Boolean

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.

Parameters:

Returns:

  • (Boolean)


70
71
72
# File 'trust.rb', line 70

def self.trusted?(type, name)
  trusted_entries(type).include?(normalise_name(name))
end

.trusted_cask_file?(path) ⇒ Boolean

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.

Parameters:

Returns:

  • (Boolean)


124
125
126
# File 'trust.rb', line 124

def self.trusted_cask_file?(path)
  trusted_file?(:cask, path)
end

.trusted_entries(type) ⇒ 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.

Parameters:

Returns:



134
135
136
# File 'trust.rb', line 134

def self.trusted_entries(type)
  trust_store.fetch(setting_key(type), [])
end

.trusted_formula_file?(path) ⇒ Boolean

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.

Parameters:

Returns:

  • (Boolean)


119
120
121
# File 'trust.rb', line 119

def self.trusted_formula_file?(path)
  trusted_file?(:formula, path)
end

.trusted_tap?(tap) ⇒ Boolean

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.

Parameters:

  • tap (T.untyped)

Returns:

  • (Boolean)


75
76
77
# File 'trust.rb', line 75

def self.trusted_tap?(tap)
  tap.official? || trusted?(:tap, tap.name)
end

.untrust!(type, name) ⇒ Boolean

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.

Parameters:

Returns:

  • (Boolean)


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'trust.rb', line 46

def self.untrust!(type, name)
  key = setting_key(type)
  entries = trusted_entries(type)
  name = normalise_name(name)
  return false unless entries.delete(name)

  store = trust_store
  if entries.empty?
    store.delete(key)
  else
    store[key] = entries.sort
  end
  write_trust_store(store)
  true
end