File: go_md5.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 (39 lines) | stat: -rw-r--r-- 1,128 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
# frozen_string_literal: true

require_relative '../../../puppet_x/bodeco/util'

# @summary
#   Retrieves and returns specific file's md5 from GoCD server md5 checksum file
# @api private
# @see http://www.thoughtworks.com/products/docs/go/12.4/help/Artifacts_API.html
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