Module: PuppetfileResolver::Util
- Defined in:
- lib/puppetfile-resolver/util.rb
Class Method Summary collapse
-
.net_http_get(uri, proxy = nil) ⇒ Net::HTTPResponse
Execute a HTTP/S GET query and return the response.
- .static_ca_cert_file ⇒ Object
- .symbolise_object(object) ⇒ Object
Class Method Details
.net_http_get(uri, proxy = nil) ⇒ Net::HTTPResponse
Execute a HTTP/S GET query and return the response
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/puppetfile-resolver/util.rb', line 27 def self.net_http_get(uri, proxy = nil) uri = URI.parse(uri) unless uri.is_a?(URI) = { :use_ssl => uri.class == URI::HTTPS } # Because on Windows Ruby doesn't use the Windows certificate store which has up-to date # CA certs, we can't depend on someone setting the environment variable correctly. So use our # static CA PEM file if SSL_CERT_FILE is not set. [:ca_file] = PuppetfileResolver::Util.static_ca_cert_file if ENV['SSL_CERT_FILE'].nil? start_args = [uri.host, uri.port] unless proxy.nil? proxy = URI.parse(proxy) unless proxy.is_a?(URI) start_args.concat([proxy.host, proxy.port, proxy.user, proxy.password]) end Net::HTTP.start(*start_args, ) { |http| return http.request(Net::HTTP::Get.new(uri)) } nil end |
.static_ca_cert_file ⇒ Object
19 20 21 |
# File 'lib/puppetfile-resolver/util.rb', line 19 def self.static_ca_cert_file @static_ca_cert_file ||= File.(File.join(__dir__, 'data', 'ruby_ca_certs.pem')) end |
.symbolise_object(object) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/puppetfile-resolver/util.rb', line 5 def self.symbolise_object(object) case # rubocop:disable Style/EmptyCaseCondition Ignore when object.is_a?(Hash) object.inject({}) do |memo, (k, v)| # rubocop:disable Style/EachWithObject Ignore memo[k.to_sym] = symbolise_object(v) memo end when object.is_a?(Array) object.map { |i| symbolise_object(i) } else object end end |