rubygems-update 3.7.0 → 3.7.2

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.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +47 -0
  3. data/CODE_OF_CONDUCT.md +1 -1
  4. data/bundler/CHANGELOG.md +43 -0
  5. data/bundler/lib/bundler/build_metadata.rb +2 -2
  6. data/bundler/lib/bundler/checksum.rb +6 -0
  7. data/bundler/lib/bundler/cli/cache.rb +0 -1
  8. data/bundler/lib/bundler/cli/common.rb +1 -1
  9. data/bundler/lib/bundler/cli/install.rb +1 -3
  10. data/bundler/lib/bundler/cli/lock.rb +5 -5
  11. data/bundler/lib/bundler/cli/show.rb +2 -6
  12. data/bundler/lib/bundler/cli/update.rb +1 -1
  13. data/bundler/lib/bundler/cli.rb +43 -43
  14. data/bundler/lib/bundler/definition.rb +77 -60
  15. data/bundler/lib/bundler/dsl.rb +1 -1
  16. data/bundler/lib/bundler/feature_flag.rb +1 -1
  17. data/bundler/lib/bundler/man/bundle-add.1 +1 -1
  18. data/bundler/lib/bundler/man/bundle-binstubs.1 +1 -1
  19. data/bundler/lib/bundler/man/bundle-cache.1 +1 -1
  20. data/bundler/lib/bundler/man/bundle-check.1 +1 -1
  21. data/bundler/lib/bundler/man/bundle-clean.1 +1 -1
  22. data/bundler/lib/bundler/man/bundle-config.1 +31 -14
  23. data/bundler/lib/bundler/man/bundle-config.1.ronn +49 -20
  24. data/bundler/lib/bundler/man/bundle-console.1 +1 -1
  25. data/bundler/lib/bundler/man/bundle-doctor.1 +4 -4
  26. data/bundler/lib/bundler/man/bundle-doctor.1.ronn +4 -4
  27. data/bundler/lib/bundler/man/bundle-env.1 +1 -1
  28. data/bundler/lib/bundler/man/bundle-exec.1 +1 -1
  29. data/bundler/lib/bundler/man/bundle-fund.1 +1 -1
  30. data/bundler/lib/bundler/man/bundle-gem.1 +1 -1
  31. data/bundler/lib/bundler/man/bundle-help.1 +1 -1
  32. data/bundler/lib/bundler/man/bundle-info.1 +1 -1
  33. data/bundler/lib/bundler/man/bundle-init.1 +1 -1
  34. data/bundler/lib/bundler/man/bundle-inject.1 +1 -1
  35. data/bundler/lib/bundler/man/bundle-install.1 +4 -4
  36. data/bundler/lib/bundler/man/bundle-install.1.ronn +3 -4
  37. data/bundler/lib/bundler/man/bundle-issue.1 +1 -1
  38. data/bundler/lib/bundler/man/bundle-licenses.1 +1 -1
  39. data/bundler/lib/bundler/man/bundle-list.1 +1 -1
  40. data/bundler/lib/bundler/man/bundle-lock.1 +1 -1
  41. data/bundler/lib/bundler/man/bundle-open.1 +1 -1
  42. data/bundler/lib/bundler/man/bundle-outdated.1 +1 -1
  43. data/bundler/lib/bundler/man/bundle-platform.1 +1 -1
  44. data/bundler/lib/bundler/man/bundle-plugin.1 +40 -15
  45. data/bundler/lib/bundler/man/bundle-plugin.1.ronn +44 -15
  46. data/bundler/lib/bundler/man/bundle-pristine.1 +1 -1
  47. data/bundler/lib/bundler/man/bundle-remove.1 +1 -1
  48. data/bundler/lib/bundler/man/bundle-show.1 +1 -1
  49. data/bundler/lib/bundler/man/bundle-update.1 +5 -5
  50. data/bundler/lib/bundler/man/bundle-update.1.ronn +4 -4
  51. data/bundler/lib/bundler/man/bundle-version.1 +1 -1
  52. data/bundler/lib/bundler/man/bundle-viz.1 +1 -1
  53. data/bundler/lib/bundler/man/bundle.1 +1 -1
  54. data/bundler/lib/bundler/man/gemfile.5 +1 -1
  55. data/bundler/lib/bundler/resolver/package.rb +1 -0
  56. data/bundler/lib/bundler/settings.rb +1 -1
  57. data/bundler/lib/bundler/source/gemspec.rb +4 -0
  58. data/bundler/lib/bundler/source/path.rb +2 -0
  59. data/bundler/lib/bundler/templates/newgem/newgem.gemspec.tt +3 -3
  60. data/bundler/lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb +42 -6
  61. data/bundler/lib/bundler/vendor/thor/lib/thor/parser/options.rb +1 -1
  62. data/bundler/lib/bundler/vendor/thor/lib/thor/runner.rb +1 -1
  63. data/bundler/lib/bundler/vendor/thor/lib/thor/shell/basic.rb +3 -7
  64. data/bundler/lib/bundler/vendor/thor/lib/thor/version.rb +1 -1
  65. data/bundler/lib/bundler/version.rb +1 -1
  66. data/doc/bundler/UPGRADING.md +0 -27
  67. data/lib/rubygems/commands/sources_command.rb +122 -18
  68. data/lib/rubygems/defaults.rb +1 -1
  69. data/lib/rubygems/exceptions.rb +3 -12
  70. data/lib/rubygems/platform.rb +1 -1
  71. data/lib/rubygems/s3_uri_signer.rb +54 -7
  72. data/lib/rubygems/source_list.rb +36 -0
  73. data/lib/rubygems.rb +8 -1
  74. data/rubygems-update.gemspec +1 -1
  75. metadata +2 -2
@@ -18,6 +18,14 @@ class Gem::Commands::SourcesCommand < Gem::Command
18
18
  options[:add] = value
19
19
  end
20
20
 
21
+ add_option "--append SOURCE_URI", "Append source (can be used multiple times)" do |value, options|
22
+ options[:append] = value
23
+ end
24
+
25
+ add_option "-p", "--prepend SOURCE_URI", "Prepend source (can be used multiple times)" do |value, options|
26
+ options[:prepend] = value
27
+ end
28
+
21
29
  add_option "-l", "--list", "List sources" do |value, options|
22
30
  options[:list] = value
23
31
  end
@@ -26,8 +34,7 @@ class Gem::Commands::SourcesCommand < Gem::Command
26
34
  options[:remove] = value
27
35
  end
28
36
 
29
- add_option "-c", "--clear-all",
30
- "Remove all sources (clear the cache)" do |value, options|
37
+ add_option "-c", "--clear-all", "Remove all sources (clear the cache)" do |value, options|
31
38
  options[:clear_all] = value
32
39
  end
33
40
 
@@ -68,6 +75,60 @@ class Gem::Commands::SourcesCommand < Gem::Command
68
75
  end
69
76
  end
70
77
 
78
+ def append_source(source_uri) # :nodoc:
79
+ check_rubygems_https source_uri
80
+
81
+ source = Gem::Source.new source_uri
82
+
83
+ check_typo_squatting(source)
84
+
85
+ begin
86
+ source.load_specs :released
87
+ was_present = Gem.sources.include?(source)
88
+ Gem.sources.append source
89
+ Gem.configuration.write
90
+
91
+ if was_present
92
+ say "#{source_uri} moved to end of sources"
93
+ else
94
+ say "#{source_uri} added to sources"
95
+ end
96
+ rescue Gem::URI::Error, ArgumentError
97
+ say "#{source_uri} is not a URI"
98
+ terminate_interaction 1
99
+ rescue Gem::RemoteFetcher::FetchError => e
100
+ say "Error fetching #{Gem::Uri.redact(source.uri)}:\n\t#{e.message}"
101
+ terminate_interaction 1
102
+ end
103
+ end
104
+
105
+ def prepend_source(source_uri) # :nodoc:
106
+ check_rubygems_https source_uri
107
+
108
+ source = Gem::Source.new source_uri
109
+
110
+ check_typo_squatting(source)
111
+
112
+ begin
113
+ source.load_specs :released
114
+ was_present = Gem.sources.include?(source)
115
+ Gem.sources.prepend source
116
+ Gem.configuration.write
117
+
118
+ if was_present
119
+ say "#{source_uri} moved to top of sources"
120
+ else
121
+ say "#{source_uri} added to sources"
122
+ end
123
+ rescue Gem::URI::Error, ArgumentError
124
+ say "#{source_uri} is not a URI"
125
+ terminate_interaction 1
126
+ rescue Gem::RemoteFetcher::FetchError => e
127
+ say "Error fetching #{Gem::Uri.redact(source.uri)}:\n\t#{e.message}"
128
+ terminate_interaction 1
129
+ end
130
+ end
131
+
71
132
  def check_typo_squatting(source)
72
133
  if source.typo_squatting?("rubygems.org")
73
134
  question = <<-QUESTION.chomp
@@ -128,7 +189,7 @@ yourself to use your own gem server.
128
189
  Without any arguments the sources lists your currently configured sources:
129
190
 
130
191
  $ gem sources
131
- *** CURRENT SOURCES ***
192
+ *** NO CONFIGURED SOURCES, DEFAULT SOURCES LISTED BELOW ***
132
193
 
133
194
  https://rubygems.org
134
195
 
@@ -147,33 +208,49 @@ Since all of these sources point to the same set of gems you only need one
147
208
  of them in your list. https://rubygems.org is recommended as it brings the
148
209
  protections of an SSL connection to gem downloads.
149
210
 
150
- To add a source use the --add argument:
211
+ To add a private gem source use the --prepend argument to insert it before
212
+ the default source. This is usually the best place for private gem sources:
151
213
 
152
- $ gem sources --add https://rubygems.org
153
- https://rubygems.org added to sources
214
+ $ gem sources --prepend https://my.private.source
215
+ https://my.private.source added to sources
154
216
 
155
217
  RubyGems will check to see if gems can be installed from the source given
156
218
  before it is added.
157
219
 
220
+ To add or move a source after all other sources, use --append:
221
+
222
+ $ gem sources --append https://rubygems.org
223
+ https://rubygems.org moved to end of sources
224
+
158
225
  To remove a source use the --remove argument:
159
226
 
160
- $ gem sources --remove https://rubygems.org/
161
- https://rubygems.org/ removed from sources
227
+ $ gem sources --remove https://my.private.source/
228
+ https://my.private.source/ removed from sources
162
229
 
163
230
  EOF
164
231
  end
165
232
 
166
233
  def list # :nodoc:
167
- say "*** CURRENT SOURCES ***"
234
+ if configured_sources
235
+ header = "*** CURRENT SOURCES ***"
236
+ list = configured_sources
237
+ else
238
+ header = "*** NO CONFIGURED SOURCES, DEFAULT SOURCES LISTED BELOW ***"
239
+ list = Gem.sources
240
+ end
241
+
242
+ say header
168
243
  say
169
244
 
170
- Gem.sources.each do |src|
245
+ list.each do |src|
171
246
  say src
172
247
  end
173
248
  end
174
249
 
175
250
  def list? # :nodoc:
176
251
  !(options[:add] ||
252
+ options[:prepend] ||
253
+ options[:append] ||
177
254
  options[:clear_all] ||
178
255
  options[:remove] ||
179
256
  options[:update])
@@ -182,11 +259,13 @@ To remove a source use the --remove argument:
182
259
  def execute
183
260
  clear_all if options[:clear_all]
184
261
 
185
- source_uri = options[:add]
186
- add_source source_uri if source_uri
262
+ add_source options[:add] if options[:add]
263
+
264
+ prepend_source options[:prepend] if options[:prepend]
265
+
266
+ append_source options[:append] if options[:append]
187
267
 
188
- source_uri = options[:remove]
189
- remove_source source_uri if source_uri
268
+ remove_source options[:remove] if options[:remove]
190
269
 
191
270
  update if options[:update]
192
271
 
@@ -194,13 +273,21 @@ To remove a source use the --remove argument:
194
273
  end
195
274
 
196
275
  def remove_source(source_uri) # :nodoc:
197
- if Gem.sources.include? source_uri
198
- Gem.sources.delete source_uri
276
+ source = Gem::Source.new source_uri
277
+
278
+ if configured_sources&.include? source
279
+ Gem.sources.delete source
199
280
  Gem.configuration.write
200
281
 
201
- say "#{source_uri} removed from sources"
282
+ if default_sources.include?(source) && configured_sources.one?
283
+ alert_warning "Removing a default source when it is the only source has no effect. Add a different source to #{config_file_name} if you want to stop using it as a source."
284
+ else
285
+ say "#{source_uri} removed from sources"
286
+ end
287
+ elsif configured_sources
288
+ say "source #{source_uri} cannot be removed because it's not present in #{config_file_name}"
202
289
  else
203
- say "source #{source_uri} not present in cache"
290
+ say "source #{source_uri} cannot be removed because there are no configured sources in #{config_file_name}"
204
291
  end
205
292
  end
206
293
 
@@ -224,4 +311,21 @@ To remove a source use the --remove argument:
224
311
  say "*** Unable to remove #{desc} source cache ***"
225
312
  end
226
313
  end
314
+
315
+ private
316
+
317
+ def default_sources
318
+ Gem::SourceList.from(Gem.default_sources)
319
+ end
320
+
321
+ def configured_sources
322
+ return @configured_sources if defined?(@configured_sources)
323
+
324
+ configuration_sources = Gem.configuration.sources
325
+ @configured_sources = Gem::SourceList.from(configuration_sources) if configuration_sources
326
+ end
327
+
328
+ def config_file_name
329
+ Gem.configuration.config_file_name
330
+ end
227
331
  end
@@ -13,7 +13,7 @@ module Gem
13
13
  # An Array of the default sources that come with RubyGems
14
14
 
15
15
  def self.default_sources
16
- %w[https://rubygems.org/]
16
+ @default_sources ||= %w[https://rubygems.org/]
17
17
  end
18
18
 
19
19
  ##
@@ -21,20 +21,11 @@ class Gem::UnknownCommandError < Gem::Exception
21
21
  end
22
22
 
23
23
  def self.attach_correctable
24
- return if defined?(@attached)
24
+ return if method_defined?(:corrections)
25
25
 
26
- if defined?(DidYouMean::SPELL_CHECKERS) && defined?(DidYouMean::Correctable)
27
- if DidYouMean.respond_to?(:correct_error)
28
- DidYouMean.correct_error(Gem::UnknownCommandError, Gem::UnknownCommandSpellChecker)
29
- else
30
- DidYouMean::SPELL_CHECKERS["Gem::UnknownCommandError"] =
31
- Gem::UnknownCommandSpellChecker
32
-
33
- prepend DidYouMean::Correctable
34
- end
26
+ if defined?(DidYouMean) && DidYouMean.respond_to?(:correct_error)
27
+ DidYouMean.correct_error(Gem::UnknownCommandError, Gem::UnknownCommandSpellChecker)
35
28
  end
36
-
37
- @attached = true
38
29
  end
39
30
  end
40
31
 
@@ -90,7 +90,7 @@ class Gem::Platform
90
90
  when String then
91
91
  cpu, os = arch.sub(/-+$/, "").split("-", 2)
92
92
 
93
- @cpu = if cpu.match?(/i\d86/)
93
+ @cpu = if cpu&.match?(/i\d86/)
94
94
  "x86"
95
95
  else
96
96
  cpu
@@ -1,11 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "openssl"
4
+ require_relative "user_interaction"
4
5
 
5
6
  ##
6
7
  # S3URISigner implements AWS SigV4 for S3 Source to avoid a dependency on the aws-sdk-* gems
7
8
  # More on AWS SigV4: https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-authenticating-requests.html
8
9
  class Gem::S3URISigner
10
+ include Gem::UserInteraction
11
+
9
12
  class ConfigurationError < Gem::Exception
10
13
  def initialize(message)
11
14
  super message
@@ -147,17 +150,40 @@ class Gem::S3URISigner
147
150
  require_relative "request/connection_pools"
148
151
  require "json"
149
152
 
150
- iam_info = ec2_metadata_request(EC2_IAM_INFO)
153
+ # First try V2 fallback to V1
154
+ res = nil
155
+ begin
156
+ res = ec2_metadata_credentials_imds_v2
157
+ rescue InstanceProfileError
158
+ alert_warning "Unable to access ec2 credentials via IMDSv2, falling back to IMDSv1"
159
+ res = ec2_metadata_credentials_imds_v1
160
+ end
161
+ res
162
+ end
163
+
164
+ def ec2_metadata_credentials_imds_v2
165
+ token = ec2_metadata_token
166
+ iam_info = ec2_metadata_request(EC2_IAM_INFO, token:)
151
167
  # Expected format: arn:aws:iam::<id>:instance-profile/<role_name>
152
168
  role_name = iam_info["InstanceProfileArn"].split("/").last
153
- ec2_metadata_request(EC2_IAM_SECURITY_CREDENTIALS + role_name)
169
+ ec2_metadata_request(EC2_IAM_SECURITY_CREDENTIALS + role_name, token:)
154
170
  end
155
171
 
156
- def ec2_metadata_request(url)
157
- uri = Gem::URI(url)
158
- @request_pool ||= create_request_pool(uri)
159
- request = Gem::Request.new(uri, Gem::Net::HTTP::Get, nil, @request_pool)
160
- response = request.fetch
172
+ def ec2_metadata_credentials_imds_v1
173
+ iam_info = ec2_metadata_request(EC2_IAM_INFO, token: nil)
174
+ # Expected format: arn:aws:iam::<id>:instance-profile/<role_name>
175
+ role_name = iam_info["InstanceProfileArn"].split("/").last
176
+ ec2_metadata_request(EC2_IAM_SECURITY_CREDENTIALS + role_name, token: nil)
177
+ end
178
+
179
+ def ec2_metadata_request(url, token:)
180
+ request = ec2_iam_request(Gem::URI(url), Gem::Net::HTTP::Get)
181
+
182
+ response = request.fetch do |req|
183
+ if token
184
+ req.add_field "X-aws-ec2-metadata-token", token
185
+ end
186
+ end
161
187
 
162
188
  case response
163
189
  when Gem::Net::HTTPOK then
@@ -167,6 +193,26 @@ class Gem::S3URISigner
167
193
  end
168
194
  end
169
195
 
196
+ def ec2_metadata_token
197
+ request = ec2_iam_request(Gem::URI(EC2_IAM_TOKEN), Gem::Net::HTTP::Put)
198
+
199
+ response = request.fetch do |req|
200
+ req.add_field "X-aws-ec2-metadata-token-ttl-seconds", 60
201
+ end
202
+
203
+ case response
204
+ when Gem::Net::HTTPOK then
205
+ response.body
206
+ else
207
+ raise InstanceProfileError.new("Unable to fetch AWS metadata from #{uri}: #{response.message} #{response.code}")
208
+ end
209
+ end
210
+
211
+ def ec2_iam_request(uri, verb)
212
+ @request_pool ||= create_request_pool(uri)
213
+ Gem::Request.new(uri, verb, nil, @request_pool)
214
+ end
215
+
170
216
  def create_request_pool(uri)
171
217
  proxy_uri = Gem::Request.proxy_uri(Gem::Request.get_proxy_from_env(uri.scheme))
172
218
  certs = Gem::Request.get_cert_files
@@ -174,6 +220,7 @@ class Gem::S3URISigner
174
220
  end
175
221
 
176
222
  BASE64_URI_TRANSLATE = { "+" => "%2B", "/" => "%2F", "=" => "%3D", "\n" => "" }.freeze
223
+ EC2_IAM_TOKEN = "http://169.254.169.254/latest/api/token"
177
224
  EC2_IAM_INFO = "http://169.254.169.254/latest/meta-data/iam/info"
178
225
  EC2_IAM_SECURITY_CREDENTIALS = "http://169.254.169.254/latest/meta-data/iam/security-credentials/"
179
226
  end
@@ -59,6 +59,42 @@ class Gem::SourceList
59
59
  src
60
60
  end
61
61
 
62
+ ##
63
+ # Prepends +obj+ to the beginning of the source list which may be a Gem::Source, Gem::URI or URI
64
+ # Moves +obj+ to the beginning of the list if already present.
65
+ # String.
66
+
67
+ def prepend(obj)
68
+ src = case obj
69
+ when Gem::Source
70
+ obj
71
+ else
72
+ Gem::Source.new(obj)
73
+ end
74
+
75
+ @sources.delete(src) if @sources.include?(src)
76
+ @sources.unshift(src)
77
+ src
78
+ end
79
+
80
+ ##
81
+ # Appends +obj+ to the end of the source list, moving it if already present.
82
+ # +obj+ may be a Gem::Source, Gem::URI or URI String.
83
+ # Moves +obj+ to the end of the list if already present.
84
+
85
+ def append(obj)
86
+ src = case obj
87
+ when Gem::Source
88
+ obj
89
+ else
90
+ Gem::Source.new(obj)
91
+ end
92
+
93
+ @sources.delete(src) if @sources.include?(src)
94
+ @sources << src
95
+ src
96
+ end
97
+
62
98
  ##
63
99
  # Replaces this SourceList with the sources in +other+ See #<< for
64
100
  # acceptable items in +other+.
data/lib/rubygems.rb CHANGED
@@ -9,7 +9,7 @@
9
9
  require "rbconfig"
10
10
 
11
11
  module Gem
12
- VERSION = "3.7.0"
12
+ VERSION = "3.7.2"
13
13
  end
14
14
 
15
15
  # Must be first since it unloads the prelude from 1.9.2
@@ -298,6 +298,13 @@ module Gem
298
298
  spec = find_and_activate_spec_for_exe name, exec_name, requirements
299
299
 
300
300
  if spec.name == "bundler"
301
+ # Old versions of Bundler need a workaround to support nested `bundle
302
+ # exec` invocations by overriding `Gem.activate_bin_path`. However,
303
+ # RubyGems now uses this new `Gem.activate_and_load_bin_path` helper in
304
+ # binstubs, which is of course not overridden in Bundler since it didn't
305
+ # exist at the time. So, include the override here to workaround that.
306
+ load ENV["BUNDLE_BIN_PATH"] if ENV["BUNDLE_BIN_PATH"] && spec.version <= "2.5.22"
307
+
301
308
  # Make sure there's no version of Bundler in `$LOAD_PATH` that's different
302
309
  # from the version we just activated. If that was the case (it happens
303
310
  # when testing Bundler from ruby/ruby), we would load Bundler extensions
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "rubygems-update"
5
- s.version = "3.7.0"
5
+ s.version = "3.7.2"
6
6
  s.authors = ["Jim Weirich", "Chad Fowler", "Eric Hodel", "Luis Lavena", "Aaron Patterson", "Samuel Giddins", "André Arko", "Evan Phoenix", "Hiroshi SHIBATA"]
7
7
  s.email = ["", "", "drbrain@segment7.net", "luislavena@gmail.com", "aaron@tenderlovemaking.com", "segiddins@segiddins.me", "andre@arko.net", "evan@phx.io", "hsbt@ruby-lang.org"]
8
8
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubygems-update
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.0
4
+ version: 3.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Weirich
@@ -731,7 +731,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
731
731
  - !ruby/object:Gem::Version
732
732
  version: '0'
733
733
  requirements: []
734
- rubygems_version: 3.7.0
734
+ rubygems_version: 3.7.2
735
735
  specification_version: 4
736
736
  summary: RubyGems is a package management framework for Ruby. This gem is downloaded
737
737
  and installed by `gem update --system`, so that the `gem` CLI can update itself.