/usr/lib/ruby/vendor_ruby/berkshelf/api/site_connector/supermarket.rb is in berkshelf-api 2.2.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | require 'open-uri'
require 'tempfile'
module OpenURI
class << self
#
# The is a bug in Ruby's implementation of OpenURI that prevents redirects
# from HTTP -> HTTPS. That should totally be a valid redirect, so we
# override that method here and call it a day.
#
# Note: this does NOT permit HTTPS -> HTTP redirects, as that would be a
# major security hole in the fabric of space-time!
#
def redirectable?(uri1, uri2)
a, b = uri1.scheme.downcase, uri2.scheme.downcase
a == b || (a == 'http' && b == 'https')
end
end
end
module Berkshelf::API
module SiteConnector
class Supermarket
include Berkshelf::API::Logging
# The default API server
V1_API = 'https://supermarket.getchef.com/'.freeze
# The timeout for the HTTP request
TIMEOUT = 15
EMPTY_UNIVERSE = {}.freeze
# @return [String]
attr_reader :api_url
# @option options [String] :url ({V1_API})
# url of community site
def initialize(options = {})
@api_url = options[:url] || V1_API
end
# @return [Hash]
def universe
universe_url = URI.parse(File.join(api_url, 'universe.json')).to_s
log.debug "Loading universe from `#{universe_url}'..."
Timeout.timeout(TIMEOUT) do
response = open(universe_url, 'User-Agent' => USER_AGENT)
JSON.parse(response.read)
end
rescue JSON::ParserError => e
log.error "Failed to parse JSON: #{e}"
EMPTY_UNIVERSE
rescue Timeout::Error
log.error "Failed to get `#{universe_url}' in #{TIMEOUT} seconds!"
EMPTY_UNIVERSE
rescue SocketError,
Errno::ECONNREFUSED,
Errno::ECONNRESET,
Errno::ENETUNREACH,
OpenURI::HTTPError => e
log.error "Failed to get `#{universe_url}': #{e}"
EMPTY_UNIVERSE
end
end
end
end
|