Skip to content

Commit

Permalink
Merge pull request #5408 from dependabot/brrygrdn/cache-timeouts-for-…
Browse files Browse the repository at this point in the history
…remaining-ecosystems

Cache client-side timeouts when a remote host is unreachable for remaining ecosystems
  • Loading branch information
brrygrdn authored Jul 28, 2022
2 parents 7a63659 + 569bfaa commit 644c143
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 48 deletions.
9 changes: 3 additions & 6 deletions elm/lib/dependabot/elm/update_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require "excon"
require "dependabot/update_checkers"
require "dependabot/update_checkers/base"
require "dependabot/shared_helpers"
require "dependabot/registry_client"
require "dependabot/errors"

module Dependabot
Expand Down Expand Up @@ -98,11 +98,8 @@ def all_versions

@version_lookup_attempted = true

response = Excon.get(
"https://package.elm-lang.org/packages/#{dependency.name}/"\
"releases.json",
idempotent: true,
**Dependabot::SharedHelpers.excon_defaults
response = Dependabot::RegistryClient.get(
url: "https://package.elm-lang.org/packages/#{dependency.name}/releases.json"
)

return @all_versions = [] unless response.status == 200
Expand Down
19 changes: 7 additions & 12 deletions gradle/lib/dependabot/gradle/metadata_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require "dependabot/file_fetchers/base"
require "dependabot/gradle/file_parser/repositories_finder"
require "dependabot/maven/utils/auth_headers_finder"
require "dependabot/registry_client"

module Dependabot
module Gradle
Expand Down Expand Up @@ -109,12 +110,9 @@ def dependency_pom_file
dependency.name.split(":").last
end

response = Excon.get(
"#{maven_repo_dependency_url}/"\
"#{dependency.version}/"\
"#{artifact_id}-#{dependency.version}.pom",
idempotent: true,
**SharedHelpers.excon_defaults(headers: auth_headers)
response = Dependabot::RegistryClient.get(
url: "#{maven_repo_dependency_url}/#{dependency.version}/#{artifact_id}-#{dependency.version}.pom",
headers: auth_headers
)

@dependency_pom_file = Nokogiri::XML(response.body)
Expand All @@ -132,12 +130,9 @@ def parent_pom_file(pom)

return unless artifact_id && group_id && version

response = Excon.get(
"#{maven_repo_url}/#{group_id.tr('.', '/')}/#{artifact_id}/"\
"#{version}/"\
"#{artifact_id}-#{version}.pom",
idempotent: true,
**SharedHelpers.excon_defaults(headers: auth_headers)
response = Dependabot::RegistryClient.get(
url: "#{maven_repo_url}/#{group_id.tr('.', '/')}/#{artifact_id}/#{version}/#{artifact_id}-#{version}.pom",
headers: auth_headers
)

Nokogiri::XML(response.body)
Expand Down
13 changes: 4 additions & 9 deletions gradle/lib/dependabot/gradle/update_checker/version_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,7 @@ def google_version_details

@google_version_details ||=
begin
response = Excon.get(
dependency_metadata_url,
idempotent: true,
**SharedHelpers.excon_defaults
)
response = Dependabot::RegistryClient.get(url: dependency_metadata_url)
Nokogiri::XML(response.body)
end

Expand All @@ -168,10 +164,9 @@ def dependency_metadata(repository_details)
@dependency_metadata ||= {}
@dependency_metadata[repository_details.hash] ||=
begin
response = Excon.get(
dependency_metadata_url(repository_details.fetch("url")),
idempotent: true,
**Dependabot::SharedHelpers.excon_defaults(headers: repository_details.fetch("auth_headers"))
response = Dependabot::RegistryClient.get(
url: dependency_metadata_url(repository_details.fetch("url")),
headers: repository_details.fetch("auth_headers")
)
check_response(response, repository_details.fetch("url"))
Nokogiri::XML(response.body)
Expand Down
9 changes: 2 additions & 7 deletions hex/lib/dependabot/hex/metadata_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require "excon"
require "dependabot/metadata_finders"
require "dependabot/metadata_finders/base"
require "dependabot/shared_helpers"
require "dependabot/registry_client"

module Dependabot
module Hex
Expand Down Expand Up @@ -55,12 +55,7 @@ def find_source_from_git_url
def hex_listing
return @hex_listing unless @hex_listing.nil?

response = Excon.get(
"https://hex.pm/api/packages/#{dependency.name}",
idempotent: true,
**SharedHelpers.excon_defaults
)

response = Dependabot::RegistryClient.get(url: "https://hex.pm/api/packages/#{dependency.name}")
@hex_listing = JSON.parse(response.body)
end
end
Expand Down
9 changes: 2 additions & 7 deletions hex/lib/dependabot/hex/update_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require "dependabot/git_commit_checker"
require "dependabot/update_checkers"
require "dependabot/update_checkers/base"
require "dependabot/shared_helpers"
require "dependabot/registry_client"

require "json"

Expand Down Expand Up @@ -243,12 +243,7 @@ def hex_registry_response

@hex_registry_requested = true

response = Excon.get(
dependency_url,
idempotent: true,
**SharedHelpers.excon_defaults
)

response = Dependabot::RegistryClient.get(url: dependency_url)
return unless response.status == 200

@hex_registry_response = JSON.parse(response.body)
Expand Down
9 changes: 2 additions & 7 deletions pub/lib/dependabot/pub/metadata_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require "excon"
require "dependabot/metadata_finders"
require "dependabot/metadata_finders/base"
require "dependabot/shared_helpers"
require "dependabot/registry_client"

module Dependabot
module Pub
Expand Down Expand Up @@ -31,12 +31,7 @@ def look_up_source
end

def repository_listing(repository_url)
response = Excon.get(
"#{repository_url}/api/packages/#{dependency.name}",
idempotent: true,
**SharedHelpers.excon_defaults
)

response = Dependabot::RegistryClient.get(url: "#{repository_url}/api/packages/#{dependency.name}")
JSON.parse(response.body)
end
end
Expand Down

0 comments on commit 644c143

Please sign in to comment.