dependabot-cargo 0.404.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: cc1005436795ef9625a3a6ea0bd82989c5f736bc9b0a9005d7062e9df50ee050
4
- data.tar.gz: 2a76d52fcea41bdc97f7774e764cf3c48a2cace477ebe3c4f7bb7ea88ca52873
3
+ metadata.gz: f77e4941a1f5d332902b10eba379330fe1b91c6529dcc1d7f8c376b870d16c9d
4
+ data.tar.gz: 3fcdb4bb89136473c898b09f475c77885ef601a098393fb575fd24409b5f5baf
5
5
  SHA512:
6
- metadata.gz: 9e3ff63837c1e4d33ebfffbe71f4130bb18c25913f6984a5d238bf30267f53a922fe8092cb7e70f503bba48d667af84bf1b68e9f2967cc2b7ca305a6504bb95e
7
- data.tar.gz: 891667fa1b9ed313360204bb6b1ce23ce653222f3516d23f2e90635eec26fa58c1bec50b3c35b65ccd92f138099747ce7a664bc7e20179d95fe6335247b15e80
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",
@@ -39,7 +39,7 @@ module Dependabot
39
39
  updated_file(file: T.must(lockfile), content: updated_lockfile_content)
40
40
  end
41
41
 
42
- raise "No files changed!" if updated_files.empty?
42
+ raise no_files_changed_error("No files changed!") if updated_files.empty?
43
43
 
44
44
  updated_files
45
45
  end
@@ -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
@@ -221,7 +221,7 @@ module Dependabot
221
221
  # of the latest tag that looks like a version.
222
222
  if git_commit_checker.pinned_ref_looks_like_version?
223
223
  latest_tag = git_commit_checker.local_tag_for_latest_version(update_cooldown)
224
- commit_sha = latest_tag && tag_commit_sha(latest_tag)
224
+ commit_sha = latest_tag&.commit_sha
225
225
  return commit_sha || dependency.version
226
226
  end
227
227
 
@@ -242,7 +242,7 @@ module Dependabot
242
242
  if git_commit_checker.pinned_ref_looks_like_version? &&
243
243
  latest_git_tag_is_resolvable?
244
244
  new_tag = git_commit_checker.local_tag_for_latest_version(update_cooldown)
245
- return T.must(tag_commit_sha(T.must(new_tag)))
245
+ return T.must(T.must(new_tag).commit_sha)
246
246
  end
247
247
 
248
248
  # If the dependency is pinned then there's nothing we can do.
@@ -271,7 +271,7 @@ module Dependabot
271
271
  dependency_files: dependency_files,
272
272
  dependency: dependency,
273
273
  unlock_requirement: true,
274
- replacement_git_pin: tag_name(replacement_tag)
274
+ replacement_git_pin: replacement_tag.tag
275
275
  ).prepared_dependency_files
276
276
 
277
277
  VersionResolver.new(
@@ -363,7 +363,7 @@ module Dependabot
363
363
  if git_commit_checker.pinned_ref_looks_like_version? &&
364
364
  latest_git_tag_is_resolvable?
365
365
  new_tag = T.must(git_commit_checker.local_tag_for_latest_version(update_cooldown))
366
- return source_with_ref(T.must(dependency_source_details), tag_name(new_tag))
366
+ return source_with_ref(T.must(dependency_source_details), new_tag.tag)
367
367
  end
368
368
 
369
369
  # Otherwise return the original source
@@ -396,20 +396,6 @@ module Dependabot
396
396
  updated_source
397
397
  end
398
398
 
399
- sig { params(tag: T::Hash[Symbol, Object]).returns(String) }
400
- def tag_name(tag)
401
- return tag.tag if tag.is_a?(Dependabot::GitTagDetails)
402
-
403
- T.cast(tag.fetch(:tag), String)
404
- end
405
-
406
- sig { params(tag: T::Hash[Symbol, Object]).returns(T.nilable(String)) }
407
- def tag_commit_sha(tag)
408
- return tag.commit_sha if tag.is_a?(Dependabot::GitTagDetails)
409
-
410
- T.cast(tag[:commit_sha], T.nilable(String))
411
- end
412
-
413
399
  sig { returns(T::Boolean) }
414
400
  def git_dependency?
415
401
  git_commit_checker.git_dependency?
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.404.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.404.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.404.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.404.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