2 require 'puppet_x/bodeco/util'
4 module Puppet::Parser::Functions
5 # Public: artifactory file sha1 checksum
7 # args[0] - artifactory file info url
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
15 response = PuppetX::Bodeco::Util.content(uri)
16 content = JSON.parse(response)
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}