Puppet Function: archive::go_md5

Defined in:
lib/puppet/functions/archive/go_md5.rb
Function type:
Ruby 4.x API

Summary

Retrieves and returns specific file's md5 from GoCD server md5 checksum file

Overview

archive::go_md5(String $username, String $password, String[1] $file, Stdlib::HTTPUrl $url)String

Parameters:

  • username (String)

    GoCD username

  • password (String)

    GoCD password

  • file (String[1])

    GoCD filename

  • url (Stdlib::HTTPUrl)

    The GoCD MD5 checkum URL

Returns:

  • (String)

    The MD5 string

See Also:



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
# File 'lib/puppet/functions/archive/go_md5.rb', line 9

Puppet::Functions.create_function(:'archive::go_md5') do
  # @param username
  #   GoCD username
  # @param password
  #   GoCD password
  # @param file
  #   GoCD filename
  # @param url
  #   The GoCD MD5 checkum URL
  # @return [String]
  #   The MD5 string
  dispatch :default_impl do
    param 'String', :username
    param 'String', :password
    param 'String[1]', :file
    param 'Stdlib::HTTPUrl', :url
    return_type 'String'
  end

  def default_impl(username, password, file, url)
    uri = URI(url)
    response = PuppetX::Bodeco::Util.content(uri, username: username, password: password)

    checksums = response.split("\n")
    line = checksums.find { |x| x =~ %r{#{file}=} }
    md5 = line.match(%r{\b[0-9a-f]{5,40}\b}) unless line.nil?
    raise("Could not parse md5 from url #{url} response: #{response}") unless md5

    md5[0]
  end
end