Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added basic: now you can pass on basic auth to open-uri #212

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/librarian/puppet/source/forge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ def vendor_cache(name, version)
end
end

def read_url(url, parsed_url)
if (parsed_url.user || parsed_url.password)
open(url, :http_basic_authentication=>[parsed_url.user, parsed_url.password]) {|f| f.read}
else
open(url) {|f| f.read}
end
end

private

# get and cache the API data for a specific module with all its versions and dependencies
Expand All @@ -186,14 +194,16 @@ def api_version_data(module_name, version)
end

def api_call(module_name, version=nil)
base_url = source.uri
parsed_url = URI.parse(source.uri)
base_url = "#{parsed_url.scheme}://#{parsed_url.host}#{parsed_url.path}"
path = "api/v1/releases.json?module=#{module_name}"
path = "#{path}&version=#{version}" unless version.nil?
url = "#{base_url}/#{path}"
debug { "Querying Forge API for module #{name}#{" and version #{version}" unless version.nil?}: #{url}" }

begin
data = open(url) {|f| f.read}
data = read_url(url, parsed_url)

JSON.parse(data)
rescue OpenURI::HTTPError => e
case e.io.status[0].to_i
Expand Down