dependabot-terraform 0.390.0 → 0.392.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: 6b961c5a78a81d4b3d75d0a9a6627140e8244377952fde7b237c3f5c743d4d05
4
- data.tar.gz: 20b2ad33f1650d9437df55efc906c7dd8674f910334b01f54c15a7196f15c0c7
3
+ metadata.gz: 8967cf03e79ccf2048ee8899931fe7c5c84b61626ad1434821d4ea9c44116178
4
+ data.tar.gz: a0e6c8d998eebbc10c0041859cdb48e2006a9367dddafc270ade1aa0ce43dfed
5
5
  SHA512:
6
- metadata.gz: 694f1d184f523c4c553922c22d2e2fb780246334a7a3d93630261c35971ef3a97a1f6586a0ed5ec62ab5f67b1f6c57e4c906e4a5aabf16296d0e7c0334b6e9bd
7
- data.tar.gz: 3c5c5a40f09269b1f84d5ab19ba2092bfdf62ec63211950daee4cdd3dd13016df6955705e62aac5a6e06ecd83c8c131d66d5f6fd08e4b1f63a36ef155cb2ade6
6
+ metadata.gz: 781749e9fd5bc08e9292ac4eebb9e857149aab0cee47e7d63e4984ca249dfb32044ce5e372828f6c5949f8fa3704c3e49c4c2d174523fb82e26abee6b2301c81
7
+ data.tar.gz: 5bb5d99c9be118bb96bae5f66eb4329648b465259d2bf5b4ace83c645b4d9f5177c3ce6122531cb606b1b8b22ad9be6fce2604305dc67709cf6dd1639eeef91a
@@ -75,12 +75,10 @@ module Dependabot
75
75
  def target_provider_source
76
76
  req = dependency.requirements.first
77
77
  return unless req
78
+ return unless req.source_string("type") == "provider"
78
79
 
79
- source = req[:source]
80
- return unless source && source[:type] == "provider"
81
-
82
- hostname = source[:registry_hostname] || DEFAULT_REGISTRY
83
- identifier = source[:module_identifier]
80
+ hostname = req.source_string("registry_hostname") || DEFAULT_REGISTRY
81
+ identifier = req.source_string("module_identifier")
84
82
  return unless identifier
85
83
 
86
84
  "#{hostname}/#{identifier}".downcase
@@ -1,10 +1,11 @@
1
- # typed: strict
1
+ # typed: strong
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "sorbet-runtime"
5
5
 
6
6
  require "dependabot/file_updaters"
7
7
  require "dependabot/file_updaters/base"
8
+ require "dependabot/dependency_requirement"
8
9
  require "dependabot/errors"
9
10
  require "dependabot/terraform/file_selector"
10
11
  require "dependabot/shared_helpers"
@@ -76,7 +77,7 @@ module Dependabot
76
77
  (dependency.requirements - T.must(dependency.previous_requirements)) |
77
78
  (T.must(dependency.previous_requirements) - dependency.requirements)
78
79
 
79
- changed_requirements.any? { |f| f[:file] == file.name }
80
+ changed_requirements.any? { |requirement| requirement.file == file.name }
80
81
  end
81
82
 
82
83
  sig { params(file: Dependabot::DependencyFile).returns(String) }
@@ -88,17 +89,17 @@ module Dependabot
88
89
 
89
90
  # Loop through each changed requirement and update the files and lockfile
90
91
  reqs.each do |new_req, old_req|
91
- raise "Bad req match" unless new_req[:file] == old_req&.fetch(:file)
92
- next unless new_req.fetch(:file) == file.name
92
+ raise "Bad req match" unless new_req.file == old_req&.file
93
+ next unless new_req.file == file.name
93
94
 
94
- case new_req[:source][:type]
95
+ source_type = T.must(new_req.source_string("type"))
96
+ case source_type
95
97
  when "git"
96
98
  update_git_declaration(new_req, old_req, content, file.name)
97
99
  when "registry", "provider"
98
100
  update_registry_declaration(new_req, old_req, content)
99
101
  else
100
- raise "Don't know how to update a #{new_req[:source][:type]} " \
101
- "declaration!"
102
+ raise "Don't know how to update a #{source_type} declaration!"
102
103
  end
103
104
  end
104
105
 
@@ -107,50 +108,55 @@ module Dependabot
107
108
 
108
109
  sig do
109
110
  params(
110
- new_req: T::Hash[Symbol, T.untyped],
111
- old_req: T.nilable(T::Hash[Symbol, T.untyped]),
111
+ new_req: Dependabot::DependencyRequirement,
112
+ old_req: T.nilable(Dependabot::DependencyRequirement),
112
113
  updated_content: String,
113
114
  filename: String
114
115
  )
115
116
  .void
116
117
  end
117
118
  def update_git_declaration(new_req, old_req, updated_content, filename)
118
- url = old_req&.dig(:source, :url)&.gsub(%r{^https://}, "")
119
- tag = old_req&.dig(:source, :ref)
119
+ url = T.must(old_req&.source_string("url")).gsub(%r{^https://}, "")
120
+ old_ref = T.must(old_req&.source_string("ref"))
121
+ new_ref = T.must(new_req.source_string("ref"))
122
+ tag = old_ref
120
123
  url_regex = /#{Regexp.quote(url)}.*ref=#{Regexp.quote(tag)}/
121
124
 
122
125
  declaration_regex = git_declaration_regex(filename)
123
126
 
124
127
  updated_content.sub!(declaration_regex) do |regex_match|
125
128
  regex_match.sub(url_regex) do |url_match|
126
- url_match.sub(old_req&.dig(:source, :ref), new_req[:source][:ref])
129
+ url_match.sub(old_ref, new_ref)
127
130
  end
128
131
  end
129
132
  end
130
133
 
131
134
  sig do
132
135
  params(
133
- new_req: T::Hash[Symbol, T.untyped],
134
- old_req: T.nilable(T::Hash[Symbol, T.untyped]),
136
+ new_req: Dependabot::DependencyRequirement,
137
+ old_req: T.nilable(Dependabot::DependencyRequirement),
135
138
  updated_content: String
136
139
  )
137
140
  .void
138
141
  end
139
142
  def update_registry_declaration(new_req, old_req, updated_content)
140
- regex = if new_req[:source][:type] == "provider"
143
+ regex = if new_req.source_string("type") == "provider"
141
144
  provider_declaration_regex(updated_content)
142
145
  else
143
146
  registry_declaration_regex
144
147
  end
145
148
 
149
+ old_requirement = T.must(old_req&.requirement_string)
150
+ new_requirement = T.must(new_req.requirement_string)
151
+
146
152
  # Define and break down the version regex for better clarity
147
153
  version_key_pattern = /^\s*version\s*=\s*/
148
- version_value_pattern = /["'].*#{Regexp.escape(old_req&.fetch(:requirement))}.*['"]/
154
+ version_value_pattern = /["'].*#{Regexp.escape(old_requirement)}.*['"]/
149
155
  version_regex = /#{version_key_pattern}#{version_value_pattern}/
150
156
 
151
157
  updated_content.gsub!(regex) do |regex_match|
152
158
  regex_match.sub(version_regex) do |req_line_match|
153
- req_line_match.sub!(old_req&.fetch(:requirement), new_req[:requirement])
159
+ req_line_match.sub!(old_requirement, new_requirement)
154
160
  end
155
161
  end
156
162
  end
@@ -171,13 +177,15 @@ module Dependabot
171
177
 
172
178
  sig do
173
179
  params(
174
- new_req: T::Hash[Symbol, T.untyped]
180
+ new_req: Dependabot::DependencyRequirement
175
181
  )
176
182
  .returns([String, String, Regexp])
177
183
  end
178
184
  def lockfile_details(new_req)
179
185
  content = T.must(lockfile).content.dup
180
- provider_source = new_req[:source][:registry_hostname] + "/" + new_req[:source][:module_identifier]
186
+ registry_hostname = T.must(new_req.source_string("registry_hostname"))
187
+ module_identifier = T.must(new_req.source_string("module_identifier"))
188
+ provider_source = "#{registry_hostname}/#{module_identifier}"
181
189
  declaration_regex = lockfile_declaration_regex(provider_source)
182
190
 
183
191
  [T.must(content), provider_source, declaration_regex]
@@ -188,7 +196,7 @@ module Dependabot
188
196
  new_req = T.must(dependency.requirements.first)
189
197
 
190
198
  # NOTE: Only providers are included in the lockfile, modules are not
191
- return unless new_req[:source][:type] == "provider"
199
+ return unless new_req.source_string("type") == "provider"
192
200
 
193
201
  architectures = []
194
202
  content, provider_source, declaration_regex = lockfile_details(new_req)
@@ -270,7 +278,7 @@ module Dependabot
270
278
 
271
279
  new_req = T.must(dependency.requirements.first)
272
280
  # NOTE: Only providers are included in the lockfile, modules are not
273
- return unless new_req[:source][:type] == "provider"
281
+ return unless new_req.source_string("type") == "provider"
274
282
 
275
283
  content, provider_source, declaration_regex = lockfile_details(new_req)
276
284
  lockfile_dependency_removed = content.sub(declaration_regex, "")
@@ -353,7 +361,7 @@ module Dependabot
353
361
 
354
362
  sig { returns(T::Array[Dependabot::DependencyFile]) }
355
363
  def files_with_requirement
356
- filenames = dependency.requirements.map { |r| r[:file] }
364
+ filenames = dependency.requirements.map(&:file)
357
365
  dependency_files.select { |file| filenames.include?(file.name) }
358
366
  end
359
367
 
@@ -425,8 +433,7 @@ module Dependabot
425
433
 
426
434
  sig { params(dependency: Dependabot::Dependency).returns(String) }
427
435
  def registry_host_for(dependency)
428
- source = dependency.requirements.filter_map { |r| r[:source] }.first
429
- source[:registry_hostname] || source["registry_hostname"] || "registry.terraform.io"
436
+ dependency.requirements.first&.source_string("registry_hostname") || "registry.terraform.io"
430
437
  end
431
438
 
432
439
  sig { params(provider_source: String).returns(Regexp) }
@@ -1,4 +1,4 @@
1
- # typed: strict
1
+ # typed: strong
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "excon"
@@ -32,16 +32,16 @@ module Dependabot
32
32
 
33
33
  sig { returns(T.nilable(Dependabot::Source)) }
34
34
  def find_source_from_git_url
35
- info = dependency.requirements.filter_map { |r| r[:source] }.first
36
-
37
- url = info[:url] || info.fetch("url")
35
+ url = T.must(dependency.source_string("url", allowed_types: ["git"]))
38
36
  Source.from_url(url)
39
37
  end
40
38
 
41
39
  sig { returns(T.nilable(Dependabot::Source)) }
42
40
  def find_source_from_registry_details
43
- info = dependency.requirements.filter_map { |r| r[:source] }.first
44
- hostname = info[:registry_hostname] || info["registry_hostname"]
41
+ hostname = dependency.source_string(
42
+ "registry_hostname",
43
+ allowed_types: %w(registry provider)
44
+ ) || RegistryClient::PUBLIC_HOSTNAME
45
45
 
46
46
  RegistryClient
47
47
  .new(hostname: hostname, credentials: credentials)
@@ -21,10 +21,7 @@ module Dependabot
21
21
  # https://registry.terraform.io/v2/providers/hashicorp/aws?include=provider-versions
22
22
  # https://registry.terraform.io/v2/modules/terraform-aws-modules/iam/aws?include=module-versions
23
23
 
24
- ELIGIBLE_SOURCE_TYPES = T.let(
25
- %w(git provider registry).freeze,
26
- T::Array[String]
27
- )
24
+ ELIGIBLE_SOURCE_TYPES = %w(git provider registry).freeze
28
25
 
29
26
  sig do
30
27
  params(
@@ -16,15 +16,9 @@ module Dependabot
16
16
 
17
17
  # Archive extensions supported by Terraform for HTTP URLs
18
18
  # https://developer.hashicorp.com/terraform/language/modules/sources#http-urls
19
- ARCHIVE_EXTENSIONS = T.let(
20
- %w(.zip .bz2 .tar.bz2 .tar.tbz2 .tbz2 .gz .tar.gz .tgz .xz .tar.xz .txz).freeze,
21
- T::Array[String]
22
- )
19
+ ARCHIVE_EXTENSIONS = %w(.zip .bz2 .tar.bz2 .tar.tbz2 .tbz2 .gz .tar.gz .tgz .xz .tar.xz .txz).freeze
23
20
  PUBLIC_HOSTNAME = "registry.terraform.io"
24
- CERTIFICATE_ERROR_KEYWORDS = T.let(
25
- %w(certificate SSL x509 verify).freeze,
26
- T::Array[String]
27
- )
21
+ CERTIFICATE_ERROR_KEYWORDS = %w(certificate SSL x509 verify).freeze
28
22
 
29
23
  sig { params(hostname: String, credentials: T::Array[Dependabot::Credential]).void }
30
24
  def initialize(hostname: PUBLIC_HOSTNAME, credentials: [])
@@ -117,7 +111,7 @@ module Dependabot
117
111
  # @return [nil, Dependabot::Source]
118
112
  sig { params(dependency: Dependabot::Dependency).returns(T.nilable(Dependabot::Source)) }
119
113
  def source(dependency:)
120
- type = T.must(dependency.requirements.first)[:source][:type]
114
+ type = T.must(dependency.source_string("type"))
121
115
  base_url = service_url_for(service_key_for(type))
122
116
  case type
123
117
  # https://www.terraform.io/internals/module-registry-protocol#download-source-code-for-a-specific-module-version
@@ -255,7 +249,7 @@ module Dependabot
255
249
 
256
250
  sig { params(message: String).returns(T::Boolean) }
257
251
  def certificate_error?(message)
258
- CERTIFICATE_ERROR_KEYWORDS.any? { |keyword| message.include?(keyword) }
252
+ CERTIFICATE_ERROR_KEYWORDS.any? { |keyword| message.index(keyword) }
259
253
  end
260
254
  end
261
255
  end
@@ -85,7 +85,7 @@ module Dependabot
85
85
  # requirement at index `i` to correspond to the previous requirement
86
86
  # at the same index.
87
87
  requirements.map do |req|
88
- case req.dig(:source, :type)
88
+ case req.source_string("type")
89
89
  when "git" then update_git_requirement(req)
90
90
  when "registry", "provider" then update_registry_requirement(req)
91
91
  else req
@@ -106,25 +106,28 @@ module Dependabot
106
106
 
107
107
  sig { params(req: Dependabot::DependencyRequirement).returns(Dependabot::DependencyRequirement) }
108
108
  def update_git_requirement(req)
109
- return req unless req.dig(:source, :ref)
109
+ return req unless req.source_string("ref")
110
110
  return req unless tag_for_latest_version
111
111
 
112
- Dependabot::DependencyRequirement.create(req.merge(source: req[:source].merge(ref: tag_for_latest_version)))
112
+ source = updated_source(req, "ref" => tag_for_latest_version)
113
+ Dependabot::DependencyRequirement.create(req.merge(source: source))
113
114
  end
114
115
 
115
116
  sig { params(req: Dependabot::DependencyRequirement).returns(Dependabot::DependencyRequirement) }
116
117
  def update_registry_requirement(req)
117
- return req if req.fetch(:requirement).nil?
118
+ string_req = req.requirement_string
119
+ return req if string_req.nil?
118
120
 
119
121
  latest = latest_version
120
122
  return req if latest.nil?
121
123
 
122
- string_req = req.fetch(:requirement).strip
124
+ string_req = string_req.strip
123
125
  ruby_req = requirement_class.new(string_req)
124
126
  return req if ruby_req.satisfied_by?(latest)
125
127
 
126
128
  new_req =
127
- if ruby_req.exact? then latest.to_s
129
+ if ruby_req.exact?
130
+ latest.to_s
128
131
  elsif string_req.start_with?("~>")
129
132
  update_twiddle_version(string_req).to_s
130
133
  else
@@ -134,6 +137,33 @@ module Dependabot
134
137
  Dependabot::DependencyRequirement.create(req.merge(requirement: new_req))
135
138
  end
136
139
 
140
+ sig do
141
+ params(
142
+ req: Dependabot::DependencyRequirement,
143
+ updates: T::Hash[String, String]
144
+ ).returns(Dependabot::DependencyRequirement::ObjectHash)
145
+ end
146
+ def updated_source(req, updates)
147
+ source = T.must(req.source_hash).dup
148
+ updates.each do |key, value|
149
+ source[source_key(source, key)] = value
150
+ end
151
+ source
152
+ end
153
+
154
+ sig do
155
+ params(
156
+ source: Dependabot::DependencyRequirement::ObjectHash,
157
+ key: String
158
+ ).returns(T.any(String, Symbol))
159
+ end
160
+ def source_key(source, key)
161
+ return key.to_sym if source.key?(key.to_sym)
162
+ return key if source.key?(key)
163
+
164
+ source.keys.any?(Symbol) ? key.to_sym : key
165
+ end
166
+
137
167
  # Updates the version in a "~>" constraint to allow the given version
138
168
  sig { params(req_string: String).returns(String) }
139
169
  def update_twiddle_version(req_string)
@@ -26,10 +26,7 @@ module Dependabot
26
26
  @dependency = dependency
27
27
  @credentials = credentials
28
28
  @cooldown_options = cooldown_options
29
- @git_commit_checker = T.let(
30
- git_commit_checker,
31
- Dependabot::GitCommitChecker
32
- )
29
+ @git_commit_checker = git_commit_checker
33
30
  end
34
31
 
35
32
  sig { returns(Dependabot::Dependency) }
@@ -18,10 +18,7 @@ module Dependabot
18
18
 
19
19
  require_relative "update_checker/latest_version_resolver"
20
20
 
21
- ELIGIBLE_SOURCE_TYPES = T.let(
22
- %w(git provider registry).freeze,
23
- T::Array[String]
24
- )
21
+ ELIGIBLE_SOURCE_TYPES = %w(git provider registry).freeze
25
22
 
26
23
  sig { override.returns(T.nilable(T.any(String, Gem::Version))) }
27
24
  def latest_version
@@ -95,13 +92,13 @@ module Dependabot
95
92
 
96
93
  sig { returns(T::Array[Dependabot::Terraform::Version]) }
97
94
  def all_module_versions
98
- identifier = dependency_source_details&.fetch(:module_identifier)
95
+ identifier = T.must(dependency.source_string("module_identifier", allowed_types: ELIGIBLE_SOURCE_TYPES))
99
96
  registry_client.all_module_versions(identifier: identifier)
100
97
  end
101
98
 
102
99
  sig { returns(T::Array[Dependabot::Terraform::Version]) }
103
100
  def all_provider_versions
104
- identifier = dependency_source_details&.fetch(:module_identifier)
101
+ identifier = T.must(dependency.source_string("module_identifier", allowed_types: ELIGIBLE_SOURCE_TYPES))
105
102
  registry_client.all_provider_versions(identifier: identifier)
106
103
  end
107
104
 
@@ -118,7 +115,10 @@ module Dependabot
118
115
 
119
116
  sig { returns(String) }
120
117
  def registry_hostname
121
- hostname = dependency_source_details&.fetch(:registry_hostname) || RegistryClient::PUBLIC_HOSTNAME
118
+ hostname = dependency.source_string(
119
+ "registry_hostname",
120
+ allowed_types: ELIGIBLE_SOURCE_TYPES
121
+ ) || RegistryClient::PUBLIC_HOSTNAME
122
122
  return hostname unless hostname == RegistryClient::PUBLIC_HOSTNAME
123
123
 
124
124
  base_registry = credentials.find do |cred|
@@ -158,7 +158,7 @@ module Dependabot
158
158
  end
159
159
 
160
160
  dependency.requirements.any? do |req|
161
- req[:requirement]&.match?(/\d-[A-Za-z0-9]/)
161
+ req.requirement_string&.match?(/\d-[A-Za-z0-9]/)
162
162
  end
163
163
  end
164
164
 
@@ -201,28 +201,17 @@ module Dependabot
201
201
 
202
202
  sig { returns(T::Boolean) }
203
203
  def proxy_requirement?
204
- dependency.requirements.any? do |req|
205
- req.fetch(:source)&.fetch(:proxy_url, nil)
206
- end
204
+ dependency.requirements.any? { |req| req.source_string("proxy_url") }
207
205
  end
208
206
 
209
207
  sig { returns(T::Boolean) }
210
208
  def registry_dependency?
211
- return false if dependency_source_details.nil?
212
-
213
- dependency_source_details&.fetch(:type) == "registry"
209
+ dependency.source_string("type", allowed_types: ELIGIBLE_SOURCE_TYPES) == "registry"
214
210
  end
215
211
 
216
212
  sig { returns(T::Boolean) }
217
213
  def provider_dependency?
218
- return false if dependency_source_details.nil?
219
-
220
- dependency_source_details&.fetch(:type) == "provider"
221
- end
222
-
223
- sig { returns(T.nilable(T::Hash[T.any(String, Symbol), T.untyped])) }
224
- def dependency_source_details
225
- dependency.source_details(allowed_types: ELIGIBLE_SOURCE_TYPES)
214
+ dependency.source_string("type", allowed_types: ELIGIBLE_SOURCE_TYPES) == "provider"
226
215
  end
227
216
 
228
217
  sig { returns(T::Boolean) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dependabot-terraform
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.390.0
4
+ version: 0.392.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.390.0
18
+ version: 0.392.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.390.0
25
+ version: 0.392.0
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: debug
28
28
  requirement: !ruby/object:Gem::Requirement
@@ -263,7 +263,7 @@ licenses:
263
263
  - MIT
264
264
  metadata:
265
265
  bug_tracker_uri: https://github.com/dependabot/dependabot-core/issues
266
- changelog_uri: https://github.com/dependabot/dependabot-core/releases/tag/v0.390.0
266
+ changelog_uri: https://github.com/dependabot/dependabot-core/releases/tag/v0.392.0
267
267
  rdoc_options: []
268
268
  require_paths:
269
269
  - lib