File: wget.rb

package info (click to toggle)
puppet-module-voxpupuli-archive 7.1.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 744 kB
  • sloc: ruby: 2,483; sh: 10; makefile: 4
file content (46 lines) | stat: -rw-r--r-- 1,472 bytes parent folder | download
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
# frozen_string_literal: true

Puppet::Type.type(:archive).provide(:wget, parent: :ruby) do
  commands wget: 'wget'

  def wget_params(params)
    username = Shellwords.shellescape(resource[:username]) if resource[:username]
    password = Shellwords.shellescape(resource[:password]) if resource[:password]
    params += optional_switch(username, ['--user=%s'])
    params += optional_switch(password, ['--password=%s'])
    params += optional_switch(resource[:cookie], ['--header="Cookie: %s"'])
    params += optional_switch(resource[:proxy_server], ['-e use_proxy=yes', "-e #{resource[:proxy_type]}_proxy=#{resource[:proxy_server]}"])
    params += ['--no-check-certificate'] if resource[:allow_insecure]
    params += resource[:download_options] if resource[:download_options]

    params
  end

  def download(filepath)
    params = wget_params(
      [
        Shellwords.shellescape(resource[:source]),
        '-O',
        filepath,
        '--max-redirect=5'
      ]
    )

    # NOTE: Do NOT use wget(params) until https://tickets.puppetlabs.com/browse/PUP-6066 is resolved.
    command = "wget #{params.join(' ')}"
    Puppet::Util::Execution.execute(command)
  end

  def remote_checksum
    params = wget_params(
      [
        '-qO-',
        Shellwords.shellescape(resource[:checksum_url]),
        '--max-redirect=5'
      ]
    )

    command = "wget #{params.join(' ')}"
    Puppet::Util::Execution.execute(command)[%r{\b[\da-f]{32,128}\b}i]
  end
end