diff --git a/Library/Homebrew/cask/cask_loader.rb b/Library/Homebrew/cask/cask_loader.rb index 738533781260a..379b8b6e8ca76 100644 --- a/Library/Homebrew/cask/cask_loader.rb +++ b/Library/Homebrew/cask/cask_loader.rb @@ -4,6 +4,7 @@ require "cask/cache" require "cask/cask" require "uri" +require "utils/curl" module Cask # Loads a cask from various sources. @@ -160,7 +161,7 @@ def load(config:) begin ohai "Downloading #{url}" - curl_download url, to: path + ::Utils::Curl.curl_download url, to: path rescue ErrorDuringExecution raise CaskUnavailableError.new(token, "Failed to download #{Formatter.url(url)}.") end diff --git a/Library/Homebrew/formula_auditor.rb b/Library/Homebrew/formula_auditor.rb index 28464e512c95b..aa579f2ebb909 100644 --- a/Library/Homebrew/formula_auditor.rb +++ b/Library/Homebrew/formula_auditor.rb @@ -11,6 +11,7 @@ module Homebrew # @api private class FormulaAuditor include FormulaCellarChecks + include Utils::Curl attr_reader :formula, :text, :problems, :new_formula_problems @@ -537,12 +538,14 @@ def audit_homepage spec.using == :homebrew_curl end - if (http_content_problem = curl_check_http_content(homepage, - SharedAudits::URL_TYPE_HOMEPAGE, - user_agents: [:browser, :default], - check_content: true, - strict: @strict, - use_homebrew_curl: use_homebrew_curl)) + if (http_content_problem = curl_check_http_content( + homepage, + SharedAudits::URL_TYPE_HOMEPAGE, + user_agents: [:browser, :default], + check_content: true, + strict: @strict, + use_homebrew_curl: use_homebrew_curl, + )) problem http_content_problem end end diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 0123a79b3e8ba..f2e0d5137b2c6 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -6,6 +6,7 @@ require "tab" require "utils/bottles" require "service" +require "utils/curl" require "active_support/core_ext/hash/deep_transform_values" @@ -591,7 +592,7 @@ def load_file(flags:, ignore_errors:) end HOMEBREW_CACHE_FORMULA.mkpath FileUtils.rm_f(path) - curl_download url, to: path + Utils::Curl.curl_download url, to: path super rescue MethodDeprecatedError => e if (match_data = url.match(%r{github.com/(?[\w-]+)/(?[\w-]+)/}).presence) diff --git a/Library/Homebrew/github_releases.rb b/Library/Homebrew/github_releases.rb index 53dccb0dc8a1f..e58b1fffbdef8 100644 --- a/Library/Homebrew/github_releases.rb +++ b/Library/Homebrew/github_releases.rb @@ -9,7 +9,6 @@ # @api private class GitHubReleases include Context - include Utils::Curl URL_REGEX = %r{https://github\.com/([\w-]+)/([\w-]+)?/releases/download/(.+)}.freeze diff --git a/Library/Homebrew/resource_auditor.rb b/Library/Homebrew/resource_auditor.rb index f149e19f48713..9dc663b7e3a02 100644 --- a/Library/Homebrew/resource_auditor.rb +++ b/Library/Homebrew/resource_auditor.rb @@ -123,10 +123,12 @@ def audit_urls raise HomebrewCurlDownloadStrategyError, url if strategy <= HomebrewCurlDownloadStrategy && !Formula["curl"].any_version_installed? - if (http_content_problem = curl_check_http_content(url, - "source URL", - specs: specs, - use_homebrew_curl: @use_homebrew_curl)) + if (http_content_problem = Utils::Curl.curl_check_http_content( + url, + "source URL", + specs: specs, + use_homebrew_curl: @use_homebrew_curl, + )) problem http_content_problem end elsif strategy <= GitDownloadStrategy diff --git a/Library/Homebrew/system_config.rb b/Library/Homebrew/system_config.rb index 36ce8c2ee54bf..c2bb8ae46f3c2 100644 --- a/Library/Homebrew/system_config.rb +++ b/Library/Homebrew/system_config.rb @@ -128,11 +128,11 @@ def describe_git sig { returns(String) } def describe_curl - out, = system_command(curl_executable, args: ["--version"], verbose: false) + out, = system_command(Utils::Curl.curl_executable, args: ["--version"], verbose: false) match_data = /^curl (?[\d.]+)/.match(out) if match_data - "#{match_data[:curl_version]} => #{curl_path}" + "#{match_data[:curl_version]} => #{Utils::Curl.curl_path}" else "N/A" end diff --git a/Library/Homebrew/test/spec_helper.rb b/Library/Homebrew/test/spec_helper.rb index f6ca54bf38be5..990ca69b84451 100644 --- a/Library/Homebrew/test/spec_helper.rb +++ b/Library/Homebrew/test/spec_helper.rb @@ -167,7 +167,7 @@ config.before(:each, :needs_homebrew_curl) do ENV["HOMEBREW_CURL"] = HOMEBREW_BREWED_CURL_PATH - skip "A `curl` with TLS 1.3 support is required." unless curl_supports_tls13? + skip "A `curl` with TLS 1.3 support is required." unless Utils::Curl.curl_supports_tls13? rescue FormulaUnavailableError skip "No `curl` formula is available." end diff --git a/Library/Homebrew/test/utils/curl_spec.rb b/Library/Homebrew/test/utils/curl_spec.rb index cbbe43b806d6d..25c473fd9ab41 100644 --- a/Library/Homebrew/test/utils/curl_spec.rb +++ b/Library/Homebrew/test/utils/curl_spec.rb @@ -3,6 +3,8 @@ require "utils/curl" describe "Utils::Curl" do + include Utils::Curl + let(:details) do details = { normal: {}, diff --git a/Library/Homebrew/utils/curl.rb b/Library/Homebrew/utils/curl.rb index 1379829b6c425..caf88ba6641e0 100644 --- a/Library/Homebrew/utils/curl.rb +++ b/Library/Homebrew/utils/curl.rb @@ -609,6 +609,3 @@ def parse_curl_response(response_text) end end end - -# FIXME: Include `Utils::Curl` explicitly everywhere it is used. -include Utils::Curl # rubocop:disable Style/MixinUsage diff --git a/Library/Homebrew/utils/github/api.rb b/Library/Homebrew/utils/github/api.rb index 3d167c42322a1..fd2f884c46702 100644 --- a/Library/Homebrew/utils/github/api.rb +++ b/Library/Homebrew/utils/github/api.rb @@ -251,7 +251,7 @@ def self.open_rest( args += ["--dump-header", T.must(headers_tmpfile.path)] - output, errors, status = curl_output("--location", url.to_s, *args, secrets: [token]) + output, errors, status = Utils::Curl.curl_output("--location", url.to_s, *args, secrets: [token]) output, _, http_code = output.rpartition("\n") output, _, http_code = output.rpartition("\n") if http_code == "000" headers = headers_tmpfile.read diff --git a/Library/Homebrew/utils/pypi.rb b/Library/Homebrew/utils/pypi.rb index 38d7e75ea0a06..73d3abe93796b 100644 --- a/Library/Homebrew/utils/pypi.rb +++ b/Library/Homebrew/utils/pypi.rb @@ -65,7 +65,7 @@ def pypi_info(new_version: nil) else "https://pypi.org/pypi/#{name}/json" end - out, _, status = curl_output metadata_url, "--location", "--fail" + out, _, status = Utils::Curl.curl_output metadata_url, "--location", "--fail" return unless status.success? diff --git a/Library/Homebrew/utils/repology.rb b/Library/Homebrew/utils/repology.rb index 4244b08f96bc4..15d11a93fd547 100644 --- a/Library/Homebrew/utils/repology.rb +++ b/Library/Homebrew/utils/repology.rb @@ -16,7 +16,8 @@ def self.query_api(last_package_in_response = "", repository:) last_package_in_response += "/" if last_package_in_response.present? url = "https://repology.org/api/v1/projects/#{last_package_in_response}?inrepo=#{repository}&outdated=1" - output, errors, = curl_output(url.to_s, "--silent", use_homebrew_curl: !curl_supports_tls13?) + output, errors, = Utils::Curl.curl_output(url.to_s, "--silent", + use_homebrew_curl: !Utils::Curl.curl_supports_tls13?) JSON.parse(output) rescue if Homebrew::EnvConfig.developer? @@ -31,7 +32,8 @@ def self.query_api(last_package_in_response = "", repository:) def self.single_package_query(name, repository:) url = "https://repology.org/api/v1/project/#{name}" - output, errors, = curl_output("--location", "--silent", url.to_s, use_homebrew_curl: !curl_supports_tls13?) + output, errors, = Utils::Curl.curl_output("--location", "--silent", url.to_s, + use_homebrew_curl: !Utils::Curl.curl_supports_tls13?) data = JSON.parse(output) { name => data } diff --git a/Library/Homebrew/utils/shared_audits.rb b/Library/Homebrew/utils/shared_audits.rb index c192d59ec7862..af3ff7913bf18 100644 --- a/Library/Homebrew/utils/shared_audits.rb +++ b/Library/Homebrew/utils/shared_audits.rb @@ -2,14 +2,12 @@ # frozen_string_literal: true require "utils/curl" +require "utils/github/api" # Auditing functions for rules common to both casks and formulae. # # @api private module SharedAudits - include Utils::Curl - extend Utils::Curl - URL_TYPE_HOMEPAGE = "homepage URL" module_function @@ -60,7 +58,7 @@ def github_release(user, repo, tag, formula: nil, cask: nil) def gitlab_repo_data(user, repo) @gitlab_repo_data ||= {} @gitlab_repo_data["#{user}/#{repo}"] ||= begin - out, _, status = curl_output("https://gitlab.com/api/v4/projects/#{user}%2F#{repo}") + out, _, status = Utils::Curl.curl_output("https://gitlab.com/api/v4/projects/#{user}%2F#{repo}") JSON.parse(out) if status.success? end end @@ -69,7 +67,7 @@ def gitlab_release_data(user, repo, tag) id = "#{user}/#{repo}/#{tag}" @gitlab_release_data ||= {} @gitlab_release_data[id] ||= begin - out, _, status = curl_output( + out, _, status = Utils::Curl.curl_output( "https://gitlab.com/api/v4/projects/#{user}%2F#{repo}/releases/#{tag}", "--fail" ) JSON.parse(out) if status.success? @@ -126,7 +124,7 @@ def gitlab(user, repo) def bitbucket(user, repo) api_url = "https://api.bitbucket.org/2.0/repositories/#{user}/#{repo}" - out, _, status= curl_output("--request", "GET", api_url) + out, _, status = Utils::Curl.curl_output("--request", "GET", api_url) return unless status.success? metadata = JSON.parse(out) @@ -138,10 +136,10 @@ def bitbucket(user, repo) return "Bitbucket repository too new (<30 days old)" if Date.parse(metadata["created_on"]) >= (Date.today - 30) - forks_out, _, forks_status= curl_output("--request", "GET", "#{api_url}/forks") + forks_out, _, forks_status = Utils::Curl.curl_output("--request", "GET", "#{api_url}/forks") return unless forks_status.success? - watcher_out, _, watcher_status= curl_output("--request", "GET", "#{api_url}/watchers") + watcher_out, _, watcher_status = Utils::Curl.curl_output("--request", "GET", "#{api_url}/watchers") return unless watcher_status.success? forks_metadata = JSON.parse(forks_out) diff --git a/Library/Homebrew/utils/shared_audits.rbi b/Library/Homebrew/utils/shared_audits.rbi new file mode 100644 index 0000000000000..0a6a448e47cea --- /dev/null +++ b/Library/Homebrew/utils/shared_audits.rbi @@ -0,0 +1,5 @@ +# typed: strict + +module SharedAudits + include ::Kernel +end diff --git a/Library/Homebrew/utils/spdx.rb b/Library/Homebrew/utils/spdx.rb index dc4025e4db4fc..b1d90d6edbcfc 100644 --- a/Library/Homebrew/utils/spdx.rb +++ b/Library/Homebrew/utils/spdx.rb @@ -8,9 +8,6 @@ # # @api private module SPDX - include Utils::Curl - extend Utils::Curl - module_function DATA_PATH = (HOMEBREW_DATA_PATH/"spdx").freeze @@ -34,8 +31,8 @@ def latest_tag def download_latest_license_data!(to: DATA_PATH) data_url = "https://raw.githubusercontent.com/spdx/license-list-data/#{latest_tag}/json/" - curl_download("#{data_url}licenses.json", to: to/"spdx_licenses.json") - curl_download("#{data_url}exceptions.json", to: to/"spdx_exceptions.json") + Utils::Curl.curl_download("#{data_url}licenses.json", to: to/"spdx_licenses.json") + Utils::Curl.curl_download("#{data_url}exceptions.json", to: to/"spdx_exceptions.json") end def parse_license_expression(license_expression)