instance method
Gem::GemcutterUtilities#rubygems_api_request
rubygems_api_request(method, path, host = nil, allowed_push_host = nil, scope: nil, credentials: {}, &block)
lib/rubygems/gemcutter_utilities.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.0.0/lib/rubygems/gemcutter_utilities.rb, line 91
def rubygems_api_request(method, path, host = nil, allowed_push_host = nil, scope: nil, credentials: {}, &block)
require_relative "vendored_net_http"
self.host = host if host
unless self.host
alert_error "You must specify a gem server"
terminate_interaction(ERROR_CODE)
end
if allowed_push_host
allowed_host_uri = Gem::URI.parse(allowed_push_host)
host_uri = Gem::URI.parse(self.host)
unless (host_uri.scheme == allowed_host_uri.scheme) && (host_uri.host == allowed_host_uri.host)
alert_error "#{self.host.inspect} is not allowed by the gemspec, which only allows #{allowed_push_host.inspect}"
terminate_interaction(ERROR_CODE)
end
end
uri = Gem::URI.parse "#{self.host}/#{path}"
response = request_with_otp(method, uri, &block)
if mfa_unauthorized?(response)
fetch_otp(credentials)
response = request_with_otp(method, uri, &block)
end
if api_key_forbidden?(response)
update_scope(scope)
request_with_otp(method, uri, &block)
else
response
end
end
Creates an RubyGems API to host and path with the given HTTP method.
If allowed_push_host metadata is present, then it will only allow that host.
See also
#request_with_otp
#set_api_key
#pretty_host
#sign_in
also in
4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0