dependabot-cargo 0.405.0 → 0.406.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 176c28bfc2127a41f3cd89509686ce8bcc73533efd4aa472f6f1c072ea812e56
4
- data.tar.gz: 740ae228d735e19d129bb28d5ff530e6d264e85a00d7b3aecdca4066b52c7196
3
+ metadata.gz: f77e4941a1f5d332902b10eba379330fe1b91c6529dcc1d7f8c376b870d16c9d
4
+ data.tar.gz: 3fcdb4bb89136473c898b09f475c77885ef601a098393fb575fd24409b5f5baf
5
5
  SHA512:
6
- metadata.gz: 8828cda2fc84a65a7e19c1add8de0a8a44ac320a6531c31fc805ac10b809fcc609bc1959fb40c354f28ceb0bfd388c58932a573d8d429002f251fefc15728ac8
7
- data.tar.gz: 413377a211037c14487762c5edbba8a146cf38e963f7c4bdb591acf74ac8466662e8ca70dc9d9cece038ca717f50b5ad3c25cc8740743779489b783bcdf7b7db
6
+ metadata.gz: 716d96953f0314c30d22440c8e69fa19410d054e14f501aad60d43de1102caefca6d657be2e2588c992916c2d217a5a6aa8c3c08222e1c17ade02c6f6db34e01
7
+ data.tar.gz: 417a907c7f829f0b9e3e8dafdb10f369fd65b9045e33b0dc6d769369f26e99702219bc64fac79e5889e56db7fa483e84ae9ce97670b71007050843f29bb7ac3d
@@ -11,6 +11,7 @@ require "dependabot/cargo/requirement"
11
11
  require "dependabot/cargo/version"
12
12
  require "dependabot/errors"
13
13
  require "dependabot/cargo/registry_fetcher"
14
+ require "dependabot/cargo/registry_response"
14
15
  require "dependabot/cargo/language"
15
16
  require "dependabot/cargo/package_manager"
16
17
 
@@ -328,7 +329,11 @@ module Dependabot
328
329
  url = index_url.delete_prefix("sparse+")
329
330
  url << "/" unless url.end_with?("/")
330
331
  url << "config.json"
331
- config_json = JSON.parse(RegistryClient.get(url: url, headers: headers).body)
332
+ response = RegistryClient.get(url: url, headers: headers)
333
+ RegistryResponse.raise_for_error_status!(response, index_url.delete_prefix("sparse+"))
334
+ config_json = RegistryResponse.with_parse_error_context(response, url) do
335
+ T.cast(JSON.parse(response.body), T::Hash[String, String])
336
+ end
332
337
 
333
338
  {
334
339
  type: "registry",
@@ -7,6 +7,7 @@ require "sorbet-runtime"
7
7
  require "dependabot/metadata_finders"
8
8
  require "dependabot/metadata_finders/base"
9
9
  require "dependabot/registry_client"
10
+ require "dependabot/cargo/registry_response"
10
11
 
11
12
  module Dependabot
12
13
  module Cargo
@@ -65,9 +66,12 @@ module Dependabot
65
66
  hdrs = build_headers(index, dependency.source_string("name"))
66
67
 
67
68
  url = metadata_fetch_url(dependency, index)
68
- response = fetch_metadata(url, hdrs)
69
+ response = Dependabot::RegistryClient.get(url: url, headers: hdrs)
70
+ return @crates_listing = {} if response.status == 404
69
71
 
70
- @crates_listing = parse_response(response, index)
72
+ RegistryResponse.raise_for_error_status!(response, index.delete_prefix("sparse+")) if index != CRATES_IO_API
73
+
74
+ @crates_listing = RegistryResponse.with_parse_error_context(response, url) { parse_response(response, index) }
71
75
  end
72
76
 
73
77
  sig do
@@ -86,15 +90,6 @@ module Dependabot
86
90
  hdrs
87
91
  end
88
92
 
89
- sig { params(url: String, headers: T::Hash[String, String]).returns(Excon::Response) }
90
- def fetch_metadata(url, headers)
91
- Excon.get(
92
- url,
93
- idempotent: true,
94
- **SharedHelpers.excon_defaults(headers: headers)
95
- )
96
- end
97
-
98
93
  sig { params(response: Excon::Response, index: String).returns(T::Hash[String, T.anything]) }
99
94
  def parse_response(response, index)
100
95
  if index.start_with?("sparse+")
@@ -8,6 +8,7 @@ require "nokogiri"
8
8
  require "sorbet-runtime"
9
9
  require "dependabot/registry_client"
10
10
  require "dependabot/cargo"
11
+ require "dependabot/cargo/registry_response"
11
12
  require "dependabot/package/package_release"
12
13
  require "dependabot/package/package_details"
13
14
 
@@ -84,10 +85,15 @@ module Dependabot
84
85
 
85
86
  Dependabot.logger.info("Calling #{url} to fetch metadata for #{dependency.name} from #{index}")
86
87
 
87
- response = fetch_response(url, hdrs)
88
+ response = RegistryClient.get(url: url, headers: hdrs)
88
89
  return {} if response.status == 404
89
90
 
90
- @crates_listing = T.let(parse_response(response, index), T.nilable(T::Hash[String, T.anything]))
91
+ RegistryResponse.raise_for_error_status!(response, index.delete_prefix("sparse+")) if index != CRATES_IO_API
92
+
93
+ @crates_listing = T.let(
94
+ RegistryResponse.with_parse_error_context(response, url) { parse_response(response, index) },
95
+ T.nilable(T::Hash[String, T.anything])
96
+ )
91
97
 
92
98
  Dependabot.logger.info("Fetched metadata for #{dependency.name} from #{index} successfully")
93
99
 
@@ -117,15 +123,6 @@ module Dependabot
117
123
  { "Authorization" => token }
118
124
  end
119
125
 
120
- sig { params(url: String, headers: T::Hash[String, String]).returns(Excon::Response) }
121
- def fetch_response(url, headers)
122
- Excon.get(
123
- url,
124
- idempotent: true,
125
- **SharedHelpers.excon_defaults(headers: headers)
126
- )
127
- end
128
-
129
126
  sig { params(response: Excon::Response, index: String).returns(T::Hash[String, T.anything]) }
130
127
  def parse_response(response, index)
131
128
  if index.start_with?("sparse+")
@@ -0,0 +1,45 @@
1
+ # typed: strong
2
+ # frozen_string_literal: true
3
+
4
+ require "excon"
5
+ require "json"
6
+ require "sorbet-runtime"
7
+ require "dependabot/error_report_context"
8
+ require "dependabot/errors"
9
+
10
+ module Dependabot
11
+ module Cargo
12
+ # Registries can answer with non-JSON error bodies (e.g. a 403 with a plain
13
+ # `Forbidden` body), which would otherwise surface as unknown JSON parse errors.
14
+ module RegistryResponse
15
+ extend T::Sig
16
+
17
+ AUTH_FAILURE_STATUSES = [401, 403].freeze
18
+
19
+ sig { params(response: Excon::Response, source: String).void }
20
+ def self.raise_for_error_status!(response, source)
21
+ return if (200..299).cover?(response.status)
22
+
23
+ raise PrivateSourceAuthenticationFailure, source if AUTH_FAILURE_STATUSES.include?(response.status)
24
+
25
+ raise PrivateSourceBadResponse, source
26
+ end
27
+
28
+ # Only the host is attached: registry paths can contain private crate names.
29
+ sig do
30
+ type_parameters(:R)
31
+ .params(response: Excon::Response, url: String, blk: T.proc.returns(T.type_parameter(:R)))
32
+ .returns(T.type_parameter(:R))
33
+ end
34
+ def self.with_parse_error_context(response, url, &blk)
35
+ yield
36
+ rescue JSON::ParserError => e
37
+ ErrorReportContext.attach(
38
+ e,
39
+ { http_method: "GET", host: ErrorReportContext.host_for(url), http_status: response.status }
40
+ )
41
+ raise
42
+ end
43
+ end
44
+ end
45
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dependabot-cargo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.405.0
4
+ version: 0.406.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dependabot
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - '='
17
17
  - !ruby/object:Gem::Version
18
- version: 0.405.0
18
+ version: 0.406.0
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - '='
24
24
  - !ruby/object:Gem::Version
25
- version: 0.405.0
25
+ version: 0.406.0
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: debug
28
28
  requirement: !ruby/object:Gem::Requirement
@@ -254,6 +254,7 @@ files:
254
254
  - lib/dependabot/cargo/package/package_details_fetcher.rb
255
255
  - lib/dependabot/cargo/package_manager.rb
256
256
  - lib/dependabot/cargo/registry_fetcher.rb
257
+ - lib/dependabot/cargo/registry_response.rb
257
258
  - lib/dependabot/cargo/requirement.rb
258
259
  - lib/dependabot/cargo/update_checker.rb
259
260
  - lib/dependabot/cargo/update_checker/file_preparer.rb
@@ -266,7 +267,7 @@ licenses:
266
267
  - MIT
267
268
  metadata:
268
269
  bug_tracker_uri: https://github.com/dependabot/dependabot-core/issues
269
- changelog_uri: https://github.com/dependabot/dependabot-core/releases/tag/v0.405.0
270
+ changelog_uri: https://github.com/dependabot/dependabot-core/releases/tag/v0.406.0
270
271
  rdoc_options: []
271
272
  require_paths:
272
273
  - lib