Module: GetaroundUtils::Utils::ConfigUrl

Defined in:
lib/getaround_utils/utils/config_url.rb

Class Method Summary collapse

Class Method Details

.from_env(config_name) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/getaround_utils/utils/config_url.rb', line 10

def self.from_env(config_name, ...)
  env_url = ENV.fetch("#{config_name}_URL", ...)
  env_pwd = ENV.fetch("#{config_name}_PASSWORD", nil)
  return if env_url.nil?

  ::URI.parse(env_url).tap do |uri|
    if env_pwd && !uri.userinfo
      uri.userinfo = ":#{env_pwd}"
    elsif env_pwd
      uri.password ||= env_pwd
    end
  end
end