Created
April 1, 2016 20:43
-
-
Save spuder/32f803d439ccc2f10ef382ccd6bef6fa to your computer and use it in GitHub Desktop.
A working, but ugly way to fetch from a url
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ruby_block 'get build' do | |
block do | |
require "net/https" | |
require "uri" | |
require "json" | |
uri = URI.parse("http://nexus.example.com/nexus/service/local/repositories/foobar/content/master-5678.zip?describe=info") | |
http = Net::HTTP.new(uri.host, uri.port) | |
request = Net::HTTP::Get.new(uri.request_uri) | |
request.initialize_http_header({ "Accept" => "application/json" }) | |
response = http.request(request) | |
metadata = JSON.parse(response.body) | |
# metadata['data']['md5Hash'] is a string like "1234" | |
# Save the string to the node_state https://docs.chef.io/recipes.html#node-run-state | |
node.run_state['artifact_md5'] = metadata['data']['md5Hash'] | |
end | |
action :run | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The following works as a library
However it has a huge limitation in that
remote_file
only works with sha256 hashes. Your artifact repository would need to expose that metadata aswell.