Get checksum of a raw repository asset with curl

1,682 views
Skip to first unread message

Artyom Grebyonkin

unread,
Nov 19, 2016, 11:36:29 AM11/19/16
to Nexus Users
Hi folks,

I'm struggling to get SHA1 of an asset from the raw repository in Nexus 3 with curl. The ?describe is not working anymore. Any hint?

Kind regards
Artem

Niels Bertram

unread,
May 16, 2017, 9:41:47 PM5/16/17
to Nexus Users, gre...@gmail.com
Try adding ?describe=json to the end of your query. Just tested on nexus 3.2.0 ... well checksums are missing but at least you'll get some info.

Marcos C

unread,
Oct 17, 2017, 3:14:24 AM10/17/17
to Nexus Users, gre...@gmail.com

Hi, i am by no means any expert but i think that currently the Nexus 3.0 repository does not expose this functionality on any REST API (at least that i know), so we have to work around it until something stable releases. We have been using this script (please note that you need the "jq" command present in your machine) to retrieve a file hash (if you want the sh1 instead change it on the attributes):


# Gets the MD5 hash of a component from a raw repository:
# Arg1: The raw repository (e.g. raw-dataset-example)
# Arg2: The component (living inside the raw repository) of which we want the md5
# Arg3: The credentials for the repository in the following format "user:pass"
# Return value: It will output to stdout the hash of the file, you can capture it with $(getRepositoryMD5 args...)
function getRepositoryMD5 {
   
local REPO=$1
   
local COMPONENT=$2
   
local CREDENTIALS=$3
   
local data="[{\"action\":\"coreui_Component\",\"method\":\"readAssets\",\"data\":[{\"page\":0,\"start\":0,\"limit\":1000,\"filter\":[{\"property\":\"repositoryName\",\"value\":\"$REPO\"}]}],\"type\":\"rpc\",\"tid\":0}]"
    local hash=$(curl -k --silent --request POST \
    --url https://x.x.x.x/nexus/service/extdirect \
    --header 'accept: application/json' \
    --user ${CREDENTIALS} \
    --connect-timeout 5 \
    --header 'content-type: application/json' \
    --data ${data} | jq --arg COMPONENT ${COMPONENT} '.result.data[] | select(.name==$COMPONENT) |.attributes.checksum.md5'| tr -d '"')
    # Use the tr call to remove the quotes around the hash (e.g "abs3" -> abs3)
    #  Check that we have all the necessary variables, or fail otherwise
   
    echo ${hash}

}


I have been using this code snippet for quite some time to check files that need to be downloaded as build artifacts (very big files) so i can check the md5/sha1 of the file and compare against server so i know if i have to re-download that file. I think you can also tune this to use the modification/update time to make it even faster.

Hope it works out for you!
Reply all
Reply to author
Forward
0 new messages