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