dependabot-terraform 0.391.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: e24a14dee0dc8761bf44668574a3ccf978f2482ff2862fc45223bca7dac8124d
4
- data.tar.gz: cbd1c5ee07fb7023805629cebe856055f0cad0348b3111216f81731e080730a5
3
+ metadata.gz: 8967cf03e79ccf2048ee8899931fe7c5c84b61626ad1434821d4ea9c44116178
4
+ data.tar.gz: a0e6c8d998eebbc10c0041859cdb48e2006a9367dddafc270ade1aa0ce43dfed
5
5
  SHA512:
6
- metadata.gz: 0f4a2452beada2067ca6b959248e7c6ca881f3e7b7d2d65d37a5dc4b1dbdf30728df105331629333dd7762cb834ae0776ac5835c5e3c0edc94425394d72d72e3
7
- data.tar.gz: 0ef042851c6d98f182e234291f96699fabd96d5858618bf9a5ab5f9b827483e1a0c26ebeff913e2c270634367d57145c25a55d050eb498a2b7d8af5a3692f581
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)
@@ -111,7 +111,7 @@ module Dependabot
111
111
  # @return [nil, Dependabot::Source]
112
112
  sig { params(dependency: Dependabot::Dependency).returns(T.nilable(Dependabot::Source)) }
113
113
  def source(dependency:)
114
- type = T.must(dependency.requirements.first)[:source][:type]
114
+ type = T.must(dependency.source_string("type"))
115
115
  base_url = service_url_for(service_key_for(type))
116
116
  case type
117
117
  # https://www.terraform.io/internals/module-registry-protocol#download-source-code-for-a-specific-module-version
@@ -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,20 +106,22 @@ 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
 
@@ -135,6 +137,33 @@ module Dependabot
135
137
  Dependabot::DependencyRequirement.create(req.merge(requirement: new_req))
136
138
  end
137
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
+
138
167
  # Updates the version in a "~>" constraint to allow the given version
139
168
  sig { params(req_string: String).returns(String) }
140
169
  def update_twiddle_version(req_string)
@@ -92,13 +92,13 @@ module Dependabot
92
92
 
93
93
  sig { returns(T::Array[Dependabot::Terraform::Version]) }
94
94
  def all_module_versions
95
- identifier = dependency_source_details&.fetch(:module_identifier)
95
+ identifier = T.must(dependency.source_string("module_identifier", allowed_types: ELIGIBLE_SOURCE_TYPES))
96
96
  registry_client.all_module_versions(identifier: identifier)
97
97
  end
98
98
 
99
99
  sig { returns(T::Array[Dependabot::Terraform::Version]) }
100
100
  def all_provider_versions
101
- identifier = dependency_source_details&.fetch(:module_identifier)
101
+ identifier = T.must(dependency.source_string("module_identifier", allowed_types: ELIGIBLE_SOURCE_TYPES))
102
102
  registry_client.all_provider_versions(identifier: identifier)
103
103
  end
104
104
 
@@ -115,7 +115,10 @@ module Dependabot
115
115
 
116
116
  sig { returns(String) }
117
117
  def registry_hostname
118
- 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
119
122
  return hostname unless hostname == RegistryClient::PUBLIC_HOSTNAME
120
123
 
121
124
  base_registry = credentials.find do |cred|
@@ -155,7 +158,7 @@ module Dependabot
155
158
  end
156
159
 
157
160
  dependency.requirements.any? do |req|
158
- req[:requirement]&.match?(/\d-[A-Za-z0-9]/)
161
+ req.requirement_string&.match?(/\d-[A-Za-z0-9]/)
159
162
  end
160
163
  end
161
164
 
@@ -198,28 +201,17 @@ module Dependabot
198
201
 
199
202
  sig { returns(T::Boolean) }
200
203
  def proxy_requirement?
201
- dependency.requirements.any? do |req|
202
- req.fetch(:source)&.fetch(:proxy_url, nil)
203
- end
204
+ dependency.requirements.any? { |req| req.source_string("proxy_url") }
204
205
  end
205
206
 
206
207
  sig { returns(T::Boolean) }
207
208
  def registry_dependency?
208
- return false if dependency_source_details.nil?
209
-
210
- dependency_source_details&.fetch(:type) == "registry"
209
+ dependency.source_string("type", allowed_types: ELIGIBLE_SOURCE_TYPES) == "registry"
211
210
  end
212
211
 
213
212
  sig { returns(T::Boolean) }
214
213
  def provider_dependency?
215
- return false if dependency_source_details.nil?
216
-
217
- dependency_source_details&.fetch(:type) == "provider"
218
- end
219
-
220
- sig { returns(T.nilable(T::Hash[T.any(String, Symbol), T.untyped])) }
221
- def dependency_source_details
222
- dependency.source_details(allowed_types: ELIGIBLE_SOURCE_TYPES)
214
+ dependency.source_string("type", allowed_types: ELIGIBLE_SOURCE_TYPES) == "provider"
223
215
  end
224
216
 
225
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.391.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.391.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.391.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.391.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