Class: OpenC3::PypiUrl

Inherits:
Object show all
Defined in:
lib/openc3/utilities/pypi_url.rb

Constant Summary collapse

DEFAULT =
'https://pypi.org/simple'

Class Method Summary collapse

Class Method Details

.validate(pypi_url) ⇒ String

Validate that a resolved pypi_url is an http(s) URL before it is handed to pip. The value can come from a user-writable setting or ENV, so a malformed or non-http value is rejected and replaced with the default rather than passed through to pip.

Parameters:

  • pypi_url (String)

    the resolved pypi index url to validate

Returns:

  • (String)

    the original url if valid, otherwise DEFAULT



28
29
30
31
32
33
34
35
36
37
# File 'lib/openc3/utilities/pypi_url.rb', line 28

def self.validate(pypi_url)
  uri = URI.parse(pypi_url)
  unless uri.is_a?(URI::HTTP) && !uri.host.to_s.empty?
    raise URI::InvalidURIError, "not an http(s) URL"
  end
  pypi_url
rescue URI::InvalidURIError => e
  Logger.error("Invalid pypi_url '#{pypi_url}' (#{e.message}); falling back to #{DEFAULT}")
  DEFAULT
end