Merge pull request #15940 from MikeMcQuaid/utils_curl_explicit
utils/curl: include or use explicitly.
This commit is contained in:
commit
4db9aa013e
@ -4,6 +4,7 @@
|
|||||||
require "cask/cache"
|
require "cask/cache"
|
||||||
require "cask/cask"
|
require "cask/cask"
|
||||||
require "uri"
|
require "uri"
|
||||||
|
require "utils/curl"
|
||||||
|
|
||||||
module Cask
|
module Cask
|
||||||
# Loads a cask from various sources.
|
# Loads a cask from various sources.
|
||||||
@ -160,7 +161,7 @@ module Cask
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
ohai "Downloading #{url}"
|
ohai "Downloading #{url}"
|
||||||
curl_download url, to: path
|
::Utils::Curl.curl_download url, to: path
|
||||||
rescue ErrorDuringExecution
|
rescue ErrorDuringExecution
|
||||||
raise CaskUnavailableError.new(token, "Failed to download #{Formatter.url(url)}.")
|
raise CaskUnavailableError.new(token, "Failed to download #{Formatter.url(url)}.")
|
||||||
end
|
end
|
||||||
|
@ -11,6 +11,7 @@ module Homebrew
|
|||||||
# @api private
|
# @api private
|
||||||
class FormulaAuditor
|
class FormulaAuditor
|
||||||
include FormulaCellarChecks
|
include FormulaCellarChecks
|
||||||
|
include Utils::Curl
|
||||||
|
|
||||||
attr_reader :formula, :text, :problems, :new_formula_problems
|
attr_reader :formula, :text, :problems, :new_formula_problems
|
||||||
|
|
||||||
@ -537,12 +538,14 @@ module Homebrew
|
|||||||
spec.using == :homebrew_curl
|
spec.using == :homebrew_curl
|
||||||
end
|
end
|
||||||
|
|
||||||
if (http_content_problem = curl_check_http_content(homepage,
|
if (http_content_problem = curl_check_http_content(
|
||||||
SharedAudits::URL_TYPE_HOMEPAGE,
|
homepage,
|
||||||
user_agents: [:browser, :default],
|
SharedAudits::URL_TYPE_HOMEPAGE,
|
||||||
check_content: true,
|
user_agents: [:browser, :default],
|
||||||
strict: @strict,
|
check_content: true,
|
||||||
use_homebrew_curl: use_homebrew_curl))
|
strict: @strict,
|
||||||
|
use_homebrew_curl: use_homebrew_curl,
|
||||||
|
))
|
||||||
problem http_content_problem
|
problem http_content_problem
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -6,6 +6,7 @@ require "extend/cachable"
|
|||||||
require "tab"
|
require "tab"
|
||||||
require "utils/bottles"
|
require "utils/bottles"
|
||||||
require "service"
|
require "service"
|
||||||
|
require "utils/curl"
|
||||||
|
|
||||||
require "active_support/core_ext/hash/deep_transform_values"
|
require "active_support/core_ext/hash/deep_transform_values"
|
||||||
|
|
||||||
@ -591,7 +592,7 @@ module Formulary
|
|||||||
end
|
end
|
||||||
HOMEBREW_CACHE_FORMULA.mkpath
|
HOMEBREW_CACHE_FORMULA.mkpath
|
||||||
FileUtils.rm_f(path)
|
FileUtils.rm_f(path)
|
||||||
curl_download url, to: path
|
Utils::Curl.curl_download url, to: path
|
||||||
super
|
super
|
||||||
rescue MethodDeprecatedError => e
|
rescue MethodDeprecatedError => e
|
||||||
if (match_data = url.match(%r{github.com/(?<user>[\w-]+)/(?<repo>[\w-]+)/}).presence)
|
if (match_data = url.match(%r{github.com/(?<user>[\w-]+)/(?<repo>[\w-]+)/}).presence)
|
||||||
|
@ -9,7 +9,6 @@ require "json"
|
|||||||
# @api private
|
# @api private
|
||||||
class GitHubReleases
|
class GitHubReleases
|
||||||
include Context
|
include Context
|
||||||
include Utils::Curl
|
|
||||||
|
|
||||||
URL_REGEX = %r{https://github\.com/([\w-]+)/([\w-]+)?/releases/download/(.+)}.freeze
|
URL_REGEX = %r{https://github\.com/([\w-]+)/([\w-]+)?/releases/download/(.+)}.freeze
|
||||||
|
|
||||||
|
@ -123,10 +123,12 @@ module Homebrew
|
|||||||
raise HomebrewCurlDownloadStrategyError, url if
|
raise HomebrewCurlDownloadStrategyError, url if
|
||||||
strategy <= HomebrewCurlDownloadStrategy && !Formula["curl"].any_version_installed?
|
strategy <= HomebrewCurlDownloadStrategy && !Formula["curl"].any_version_installed?
|
||||||
|
|
||||||
if (http_content_problem = curl_check_http_content(url,
|
if (http_content_problem = Utils::Curl.curl_check_http_content(
|
||||||
"source URL",
|
url,
|
||||||
specs: specs,
|
"source URL",
|
||||||
use_homebrew_curl: @use_homebrew_curl))
|
specs: specs,
|
||||||
|
use_homebrew_curl: @use_homebrew_curl,
|
||||||
|
))
|
||||||
problem http_content_problem
|
problem http_content_problem
|
||||||
end
|
end
|
||||||
elsif strategy <= GitDownloadStrategy
|
elsif strategy <= GitDownloadStrategy
|
||||||
|
@ -128,11 +128,11 @@ module SystemConfig
|
|||||||
|
|
||||||
sig { returns(String) }
|
sig { returns(String) }
|
||||||
def describe_curl
|
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 (?<curl_version>[\d.]+)/.match(out)
|
match_data = /^curl (?<curl_version>[\d.]+)/.match(out)
|
||||||
if match_data
|
if match_data
|
||||||
"#{match_data[:curl_version]} => #{curl_path}"
|
"#{match_data[:curl_version]} => #{Utils::Curl.curl_path}"
|
||||||
else
|
else
|
||||||
"N/A"
|
"N/A"
|
||||||
end
|
end
|
||||||
|
@ -167,7 +167,7 @@ RSpec.configure do |config|
|
|||||||
|
|
||||||
config.before(:each, :needs_homebrew_curl) do
|
config.before(:each, :needs_homebrew_curl) do
|
||||||
ENV["HOMEBREW_CURL"] = HOMEBREW_BREWED_CURL_PATH
|
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
|
rescue FormulaUnavailableError
|
||||||
skip "No `curl` formula is available."
|
skip "No `curl` formula is available."
|
||||||
end
|
end
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
require "utils/curl"
|
require "utils/curl"
|
||||||
|
|
||||||
describe "Utils::Curl" do
|
describe "Utils::Curl" do
|
||||||
|
include Utils::Curl
|
||||||
|
|
||||||
let(:details) do
|
let(:details) do
|
||||||
details = {
|
details = {
|
||||||
normal: {},
|
normal: {},
|
||||||
|
@ -609,6 +609,3 @@ module Utils
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# FIXME: Include `Utils::Curl` explicitly everywhere it is used.
|
|
||||||
include Utils::Curl # rubocop:disable Style/MixinUsage
|
|
||||||
|
@ -251,7 +251,7 @@ module GitHub
|
|||||||
|
|
||||||
args += ["--dump-header", T.must(headers_tmpfile.path)]
|
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")
|
||||||
output, _, http_code = output.rpartition("\n") if http_code == "000"
|
output, _, http_code = output.rpartition("\n") if http_code == "000"
|
||||||
headers = headers_tmpfile.read
|
headers = headers_tmpfile.read
|
||||||
|
@ -65,7 +65,7 @@ module PyPI
|
|||||||
else
|
else
|
||||||
"https://pypi.org/pypi/#{name}/json"
|
"https://pypi.org/pypi/#{name}/json"
|
||||||
end
|
end
|
||||||
out, _, status = curl_output metadata_url, "--location", "--fail"
|
out, _, status = Utils::Curl.curl_output metadata_url, "--location", "--fail"
|
||||||
|
|
||||||
return unless status.success?
|
return unless status.success?
|
||||||
|
|
||||||
|
@ -16,7 +16,8 @@ module Repology
|
|||||||
last_package_in_response += "/" if last_package_in_response.present?
|
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"
|
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)
|
JSON.parse(output)
|
||||||
rescue
|
rescue
|
||||||
if Homebrew::EnvConfig.developer?
|
if Homebrew::EnvConfig.developer?
|
||||||
@ -31,7 +32,8 @@ module Repology
|
|||||||
def self.single_package_query(name, repository:)
|
def self.single_package_query(name, repository:)
|
||||||
url = "https://repology.org/api/v1/project/#{name}"
|
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)
|
data = JSON.parse(output)
|
||||||
{ name => data }
|
{ name => data }
|
||||||
|
@ -2,14 +2,12 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "utils/curl"
|
require "utils/curl"
|
||||||
|
require "utils/github/api"
|
||||||
|
|
||||||
# Auditing functions for rules common to both casks and formulae.
|
# Auditing functions for rules common to both casks and formulae.
|
||||||
#
|
#
|
||||||
# @api private
|
# @api private
|
||||||
module SharedAudits
|
module SharedAudits
|
||||||
include Utils::Curl
|
|
||||||
extend Utils::Curl
|
|
||||||
|
|
||||||
URL_TYPE_HOMEPAGE = "homepage URL"
|
URL_TYPE_HOMEPAGE = "homepage URL"
|
||||||
|
|
||||||
module_function
|
module_function
|
||||||
@ -60,7 +58,7 @@ module SharedAudits
|
|||||||
def gitlab_repo_data(user, repo)
|
def gitlab_repo_data(user, repo)
|
||||||
@gitlab_repo_data ||= {}
|
@gitlab_repo_data ||= {}
|
||||||
@gitlab_repo_data["#{user}/#{repo}"] ||= begin
|
@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?
|
JSON.parse(out) if status.success?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -69,7 +67,7 @@ module SharedAudits
|
|||||||
id = "#{user}/#{repo}/#{tag}"
|
id = "#{user}/#{repo}/#{tag}"
|
||||||
@gitlab_release_data ||= {}
|
@gitlab_release_data ||= {}
|
||||||
@gitlab_release_data[id] ||= begin
|
@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"
|
"https://gitlab.com/api/v4/projects/#{user}%2F#{repo}/releases/#{tag}", "--fail"
|
||||||
)
|
)
|
||||||
JSON.parse(out) if status.success?
|
JSON.parse(out) if status.success?
|
||||||
@ -126,7 +124,7 @@ module SharedAudits
|
|||||||
|
|
||||||
def bitbucket(user, repo)
|
def bitbucket(user, repo)
|
||||||
api_url = "https://api.bitbucket.org/2.0/repositories/#{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?
|
return unless status.success?
|
||||||
|
|
||||||
metadata = JSON.parse(out)
|
metadata = JSON.parse(out)
|
||||||
@ -138,10 +136,10 @@ module SharedAudits
|
|||||||
|
|
||||||
return "Bitbucket repository too new (<30 days old)" if Date.parse(metadata["created_on"]) >= (Date.today - 30)
|
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?
|
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?
|
return unless watcher_status.success?
|
||||||
|
|
||||||
forks_metadata = JSON.parse(forks_out)
|
forks_metadata = JSON.parse(forks_out)
|
||||||
|
5
Library/Homebrew/utils/shared_audits.rbi
Normal file
5
Library/Homebrew/utils/shared_audits.rbi
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# typed: strict
|
||||||
|
|
||||||
|
module SharedAudits
|
||||||
|
include ::Kernel
|
||||||
|
end
|
@ -8,9 +8,6 @@ require "utils/github"
|
|||||||
#
|
#
|
||||||
# @api private
|
# @api private
|
||||||
module SPDX
|
module SPDX
|
||||||
include Utils::Curl
|
|
||||||
extend Utils::Curl
|
|
||||||
|
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
DATA_PATH = (HOMEBREW_DATA_PATH/"spdx").freeze
|
DATA_PATH = (HOMEBREW_DATA_PATH/"spdx").freeze
|
||||||
@ -34,8 +31,8 @@ module SPDX
|
|||||||
|
|
||||||
def download_latest_license_data!(to: DATA_PATH)
|
def download_latest_license_data!(to: DATA_PATH)
|
||||||
data_url = "https://raw.githubusercontent.com/spdx/license-list-data/#{latest_tag}/json/"
|
data_url = "https://raw.githubusercontent.com/spdx/license-list-data/#{latest_tag}/json/"
|
||||||
curl_download("#{data_url}licenses.json", to: to/"spdx_licenses.json")
|
Utils::Curl.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}exceptions.json", to: to/"spdx_exceptions.json")
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_license_expression(license_expression)
|
def parse_license_expression(license_expression)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user