我想从给定工件URL的工件中读取校验和,并将其附加到属性中。我试图寻找示例,但人们正在对如下所示的校验和值进行硬编码。如果我对值进行硬编码,那么当我拥有新工件时就必须对其进行更新。我不想那样做。请让我知道是否有任何方法可以从人工制品中获取此值。我在我的厨师代码中使用摘要来计算校验和的代码。我将比较来自人工制品的校验和和我在配方中计算出的校验和。
source 'http://www.example.com/tempfiles/testfile'
mode '0755'
checksum '3a7dac00b1' # A SHA256 (or portion thereof) of the file.
end
To compare the computed checksum with the local checksum, I have seen people hardcoding local checksum value. Instead I want to read it from artifactory through chef. ex:
```computed_checksum = Digest::SHA2.file(temp.path).hexdigest Artifactory_checksum = Read from artifactory ?
if Artifactory_checksum != computed_chceksum throws error.....''''
require 'open-uri'
require 'tempfile'
url = 'http://www.example.com/tempfiles/testfile'
temp = Tempfile.new
temp << open(url).read
temp.flush
result = Digest::SHA2.file(temp.path).hexdigest