Add puppet/archive module, required for newer puppet/rabbitmq
[mirror/dsa-puppet.git] / 3rdparty / modules / archive / lib / puppet / parser / functions / artifactory_sha1.rb
1 require 'json'
2 require 'puppet_x/bodeco/util'
3
4 module Puppet::Parser::Functions
5   # Public: artifactory file sha1 checksum
6   #
7   # args[0] - artifactory file info url
8   #
9   # http://www.jfrog.com/confluence/display/RTF/Artifactory+REST+API#ArtifactoryRESTAPI-FileInfo
10   # Returns sha1 from artifactory file info
11   newfunction(:artifactory_sha1, type: :rvalue) do |args|
12     raise(ArgumentError, "Invalid artifactory file info url #{args}") unless args.size == 1
13
14     uri = URI(args[0])
15     response = PuppetX::Bodeco::Util.content(uri)
16     content = JSON.parse(response)
17
18     sha1 = content['checksums'] && content['checksums']['sha1']
19     raise("Could not parse sha1 from url: #{args[0]}\nresponse: #{response.body}") unless sha1 =~ %r{\b[0-9a-f]{5,40}\b}
20     sha1
21   end
22 end