Class: Registration::EulaDownloader

Inherits:
Object
  • Object
show all
Includes:
Yast::Logger
Defined in:
src/lib/registration/eula_downloader.rb

Overview

class for downloading addon EULAs from the registration server

Constant Summary collapse

INDEX_FILE =

name of the directory index file with list of available files

"directory.yast".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url, target_dir, insecure: false) ⇒ EulaDownloader

the constructor


43
44
45
46
47
# File 'src/lib/registration/eula_downloader.rb', line 43

def initialize(base_url, target_dir, insecure: false)
  @base_url = base_url
  @target_dir = target_dir
  @insecure = insecure
end

Instance Attribute Details

#base_urlObject (readonly)

Returns the value of attribute base_url


32
33
34
# File 'src/lib/registration/eula_downloader.rb', line 32

def base_url
  @base_url
end

#insecureObject (readonly)

Returns the value of attribute insecure


32
33
34
# File 'src/lib/registration/eula_downloader.rb', line 32

def insecure
  @insecure
end

#target_dirObject (readonly)

Returns the value of attribute target_dir


32
33
34
# File 'src/lib/registration/eula_downloader.rb', line 32

def target_dir
  @target_dir
end

Instance Method Details

#downloadObject

start the download, downloads the EULAS to the target directory


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'src/lib/registration/eula_downloader.rb', line 50

def download
  licenses = available_licenses

  # download the files listed in the index
  licenses.each do |license|
    license_file_url = URI(base_url)
    license_file_url.path = File.join(license_file_url.path, license)

    log.info "Downloading license from #{license_file_url}..."
    license_text = Downloader.download(license_file_url, insecure: insecure)
    log.info "Downloaded license: #{license_text[0..32].inspect}... " \
      "(#{license_text.bytesize} bytes)"

    license_file_name = File.join(target_dir, license)

    log.info "Saving the license to file: #{license_file_name}"
    File.write(license_file_name, license_text)
  end
end