Improve error message for allowed and forbidden taps
This commit is contained in:
parent
7c9e8927e9
commit
5222c9e32d
@ -574,7 +574,7 @@ on_request: true)
|
||||
|
||||
sig { void }
|
||||
def forbidden_tap_check
|
||||
return if Homebrew::EnvConfig.forbidden_taps.blank? && Homebrew::EnvConfig.allowed_taps.blank?
|
||||
return if Tap.allowed_taps.blank? && Tap.forbidden_taps.blank?
|
||||
|
||||
owner = Homebrew::EnvConfig.forbidden_owner
|
||||
owner_contact = if (contact = Homebrew::EnvConfig.forbidden_owner_contact.presence)
|
||||
@ -587,24 +587,28 @@ on_request: true)
|
||||
next if dep_tap.blank? || dep_tap.allowed_by_env?
|
||||
|
||||
dep_full_name = cask_or_formula.full_name
|
||||
raise CaskCannotBeInstalledError.new(@cask, <<~EOS
|
||||
The installation of #{@cask} has a dependency #{dep_full_name}
|
||||
but #{owner} has either not allowed the #{dep_tap} in `HOMEBREW_ALLOWED_TAPS` or
|
||||
has forbidden the #{dep_tap} in `HOMEBREW_FORBIDDEN_TAPS`.#{owner_contact}
|
||||
EOS
|
||||
)
|
||||
error_message = +"The installation of #{@cask} has a dependency #{dep_full_name}\n" \
|
||||
"from the #{dep_tap} tap but #{owner} "
|
||||
error_message << "has not allowed this tap in `HOMEBREW_ALLOWED_TAPS`" unless dep_tap.allowed_by_env?
|
||||
error_message << " and\n" if !dep_tap.allowed_by_env? && dep_tap.forbidden_by_env?
|
||||
error_message << "has forbidden this tap in `HOMEBREW_FORBIDDEN_TAPS`" if dep_tap.forbidden_by_env?
|
||||
error_message << ".#{owner_contact}"
|
||||
|
||||
raise CaskCannotBeInstalledError.new(@cask, error_message)
|
||||
end
|
||||
end
|
||||
|
||||
cask_tap = @cask.tap
|
||||
return if cask_tap.blank? || cask_tap.allowed_by_env?
|
||||
|
||||
raise CaskCannotBeInstalledError.new(@cask, <<~EOS
|
||||
The installation of #{@cask.full_name} has the tap #{cask_tap}
|
||||
which is either not allowed by #{owner} in `HOMEBREW_ALLOWED_TAPS` or
|
||||
is forbidden by #{owner} in `HOMEBREW_FORBIDDEN_TAPS`.#{owner_contact}
|
||||
EOS
|
||||
)
|
||||
error_message = +"The installation of #{@cask.full_name} has the tap #{cask_tap}\n" \
|
||||
"but #{owner} "
|
||||
error_message << "has not allowed this tap in `HOMEBREW_ALLOWED_TAPS`" unless cask_tap.allowed_by_env?
|
||||
error_message << " and\n" if !cask_tap.allowed_by_env? && cask_tap.forbidden_by_env?
|
||||
error_message << "has forbidden this tap in `HOMEBREW_FORBIDDEN_TAPS`" if cask_tap.forbidden_by_env?
|
||||
error_message << ".#{owner_contact}"
|
||||
|
||||
raise CaskCannotBeInstalledError.new(@cask, error_message)
|
||||
end
|
||||
|
||||
sig { void }
|
||||
|
||||
@ -1381,7 +1381,7 @@ on_request: installed_on_request?, options:)
|
||||
|
||||
sig { void }
|
||||
def forbidden_tap_check
|
||||
return if Homebrew::EnvConfig.forbidden_taps.blank? && Homebrew::EnvConfig.allowed_taps.blank?
|
||||
return if Tap.allowed_taps.blank? && Tap.forbidden_taps.blank?
|
||||
|
||||
owner = Homebrew::EnvConfig.forbidden_owner
|
||||
owner_contact = if (contact = Homebrew::EnvConfig.forbidden_owner_contact.presence)
|
||||
@ -1391,26 +1391,32 @@ on_request: installed_on_request?, options:)
|
||||
unless ignore_deps?
|
||||
compute_dependencies.each do |(dep, _options)|
|
||||
dep_tap = dep.tap
|
||||
next if dep_tap.blank? || dep_tap.allowed_by_env?
|
||||
next if dep_tap.blank? || (dep_tap.allowed_by_env? && !dep_tap.forbidden_by_env?)
|
||||
|
||||
raise CannotInstallFormulaError, <<~EOS
|
||||
The installation of #{formula.name} has a dependency #{dep.name}
|
||||
but #{owner} has either not allowed the #{dep_tap} tap in `HOMEBREW_ALLOWED_TAPS` or
|
||||
has forbidden the #{dep_tap} tap in `HOMEBREW_FORBIDDEN_TAPS`.#{owner_contact}
|
||||
EOS
|
||||
error_message = +"The installation of #{formula.name} has a dependency #{dep.name}\n" \
|
||||
"from the #{dep_tap} tap but #{owner} "
|
||||
error_message << "has not allowed this tap in `HOMEBREW_ALLOWED_TAPS`" unless dep_tap.allowed_by_env?
|
||||
error_message << " and\n" if !dep_tap.allowed_by_env? && dep_tap.forbidden_by_env?
|
||||
error_message << "has forbidden this tap in `HOMEBREW_FORBIDDEN_TAPS`" if dep_tap.forbidden_by_env?
|
||||
error_message << ".#{owner_contact}"
|
||||
|
||||
raise CannotInstallFormulaError, error_message
|
||||
end
|
||||
end
|
||||
|
||||
return if only_deps?
|
||||
|
||||
formula_tap = formula.tap
|
||||
return if formula_tap.blank? || formula_tap.allowed_by_env?
|
||||
return if formula_tap.blank? || (formula_tap.allowed_by_env? && !formula_tap.forbidden_by_env?)
|
||||
|
||||
raise CannotInstallFormulaError, <<~EOS
|
||||
The installation of #{formula.full_name} has the tap #{formula_tap}
|
||||
which is either not allowed by #{owner} in `HOMEBREW_ALLOWED_TAPS` or
|
||||
is forbidden by #{owner} in `HOMEBREW_FORBIDDEN_TAPS`.#{owner_contact}
|
||||
EOS
|
||||
error_message = +"The installation of #{formula.full_name} has the tap #{formula_tap}\n" \
|
||||
"but #{owner} "
|
||||
error_message << "has not allowed this tap in `HOMEBREW_ALLOWED_TAPS`" unless formula_tap.allowed_by_env?
|
||||
error_message << " and\n" if !formula_tap.allowed_by_env? && formula_tap.forbidden_by_env?
|
||||
error_message << "has forbidden this tap in `HOMEBREW_FORBIDDEN_TAPS`" if formula_tap.forbidden_by_env?
|
||||
error_message << ".#{owner_contact}"
|
||||
|
||||
raise CannotInstallFormulaError, error_message
|
||||
end
|
||||
|
||||
sig { void }
|
||||
|
||||
@ -1095,12 +1095,16 @@ class Tap
|
||||
def allowed_by_env?
|
||||
@allowed_by_env ||= begin
|
||||
allowed_taps = self.class.allowed_taps
|
||||
forbidden_taps = self.class.forbidden_taps
|
||||
|
||||
(official? || allowed_taps.blank? || allowed_taps.include?(self)) && forbidden_taps.exclude?(self)
|
||||
official? || allowed_taps.blank? || allowed_taps.include?(self)
|
||||
end
|
||||
end
|
||||
|
||||
sig { returns(T::Boolean) }
|
||||
def forbidden_by_env?
|
||||
@forbidden_by_env ||= self.class.forbidden_taps.include?(self)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
sig { params(file: Pathname).returns(T.any(T::Array[String], Hash)) }
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user