0

I want to read checksum from artifactory given the artifactory url and append it to an attribute. I tried to look for examples but people are hardcoding the checksum value like below. If I hardcode the value, I will have to update it when I have new artifact. I do not want to do that. Please let me know if there is anyway to get this value from artifactory. I have a code to compute checksum in the my chef code using digest. I will compare the checksum from artifactory and the checksum I computed in the recipe.

  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.....''''
shri Bin
  • 73
  • 1
  • 7

1 Answers1

0
require 'open-uri'
require 'tempfile'

jar_file = 'https://repo1.maven.org/maven2/mysql/mysql-connector-java/8.0.17/mysql-connector-java-8.0.17.jar'

temp = Tempfile.new
temp << open(jar_file).read
temp.flush

actual_sha1 = Digest::SHA1.file(temp.path).hexdigest

sha1_file = 'https://repo1.maven.org/maven2/mysql/mysql-connector-java/8.0.17/mysql-connector-java-8.0.17.jar.sha1'

expected_sha1 = open(sha1_file).read.strip

p actual_sha1 == expected_sha1

  • I have used Digest to compute SHA-256 but is there a way to read the checksum value from artifactory? – shri Bin Sep 27 '19 at 17:00
  • Generally, there is a sha1 or md5 file in public maven repositories. You could access then to obtain that information. For example: https://repo1.maven.org/maven2/org/.../hibernate-core-5.4.5.Final.jar https://repo1.maven.org/maven2/org/.../hibernate-core-5.4.5.Final.jar.md5 https://repo1.maven.org/maven2/org/.../hibernate-core-5.4.5.Final.jar.sha1 I'm using a public repo as an example, but if the jars are from your internal development, you could ask for the development team to generate these files and upload then to artifactory or automate these process during deploy of artifacts – Andrik Albuquerque Sep 27 '19 at 17:05
  • 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_chceksum = Digest::SHA2.file(temp.path).hexdigest Artifactory_checksum = Read from artifactory ? if Artifactory_checksum != computed_chceksum throws error.....``` – shri Bin Sep 27 '19 at 17:34
  • Hum I see, I updated the answer, I'm assuming that you'll have the corresponding sha1 file of the jar in the Artifactory. – Andrik Albuquerque Sep 27 '19 at 17:53
  • suggested code worked but I have a question. Does the below line read checksum from artifactory? ```expected_sha1 = open(sha1_file).read.strip – shri Bin Sep 27 '19 at 19:20
  • As I said earlier, I'm assuming that each artifact has a corresponding sha1 file on Artifactory. If the sha1 file is not available then it won't work. – Andrik Albuquerque Sep 27 '19 at 19:27