X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;ds=sidebyside;f=3rdparty%2Fmodules%2Farchive%2Flib%2Fpuppet%2Fparser%2Ffunctions%2Fgo_md5.rb;fp=3rdparty%2Fmodules%2Farchive%2Flib%2Fpuppet%2Fparser%2Ffunctions%2Fgo_md5.rb;h=668cf2d12833a2f7c9c9d92f2ecf10bd18035488;hb=ce70d6baf887ae03a2a6a7f5e73eb2e2c3dea208;hp=0000000000000000000000000000000000000000;hpb=0ba93256399fbad7ed8fabfa39c24dd47169dde3;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/archive/lib/puppet/parser/functions/go_md5.rb b/3rdparty/modules/archive/lib/puppet/parser/functions/go_md5.rb new file mode 100644 index 000000000..668cf2d12 --- /dev/null +++ b/3rdparty/modules/archive/lib/puppet/parser/functions/go_md5.rb @@ -0,0 +1,28 @@ +require 'puppet_x/bodeco/util' + +module Puppet::Parser::Functions + # Public: go file md5 checksum + # + # args[0] - username + # args[1] - password + # args[2] - file_name + # args[3] - go md5 checksum url + # + # http://www.thoughtworks.com/products/docs/go/12.4/help/Artifacts_API.html + # + # Returns specific file's md5 from go server md5 checksum file + newfunction(:go_md5, type: :rvalue) do |args| + raise(ArgumentError, "Invalid go md5 info url #{args}") unless args.size == 4 + + username, password, file, url = args + + 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}) + raise("Could not parse md5 from url#{url} response: #{response.body}") unless md5 + md5[0] + end +end