Skip to content

Commit

Permalink
code review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed May 16, 2014
1 parent 3a866ee commit 06ff28d
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/lib/registration/eula_downloader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module Registration

# class for downloading addon EULAs from the registration server
class EulaDownloader
attr_accessor :base_url, :target_dir, :insecure
attr_reader :base_url, :target_dir, :insecure

include Yast::Logger

Expand All @@ -46,7 +46,7 @@ def initialize(base_url, target_dir, insecure: false)

# start the download
def download
licenses = download_license_index
licenses = available_licenses

# download the files listed in the index
licenses.each do |license|
Expand All @@ -55,7 +55,7 @@ def download

log.info "Downloading license from #{license_file_url}..."
license_text = download_file(license_file_url)
log.info "Downloaded license size: #{license_text.size}"
log.info "Downloaded license: #{license_text[0..32].inspect}... (#{license_text.size} bytes)"

license_file_name = File.join(target_dir, license)

Expand All @@ -67,20 +67,20 @@ def download
private

def download_file(file_url)
url = file_url.is_a?(URI) ? file_url : URI(file_url)
http = Net::HTTP.new(url.host, url.port)
file_url = URI(file_url) unless file_url.is_a?(URI)
http = Net::HTTP.new(file_url.host, file_url.port)

# switch to HTTPS connection if needed
if url.is_a? URI::HTTPS
if file_url.is_a? URI::HTTPS
http.use_ssl = true
http.verify_mode = insecure ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER
log.warn("Warning: SSL certificate verification disabled") if insecure
else
log.warn("Warning: Using insecure \"#{url.scheme}\" transfer protocol")
log.warn("Warning: Using insecure \"#{file_url.scheme}\" transfer protocol")
end

# TODO: handle redirection?
request = Net::HTTP::Get.new(url.request_uri)
request = Net::HTTP::Get.new(file_url.request_uri)
response = http.request(request)

if response.is_a?(Net::HTTPSuccess)
Expand All @@ -92,7 +92,7 @@ def download_file(file_url)
end

# returns list of available files in a remote location
def download_license_index
def available_licenses
# download the index file (directory.yast)
index_url = URI(base_url)

Expand All @@ -104,7 +104,7 @@ def download_license_index
licenses = download_file(index_url).split

# the index file itself might be also present in the list, just remove it
licenses.reject!{|license| license == INDEX_FILE}
licenses.delete(INDEX_FILE)
log.info "Downloaded license index: #{licenses}"

licenses
Expand Down

0 comments on commit 06ff28d

Please sign in to comment.