[英]How do I retrieve an artifact checksum from Nexus using their rest api via curl?
I am trying to verify the checksum of the artifacts I am downloading from Nexus.我正在尝试验证我从 Nexus 下载的工件的校验和。 I can grab the artifact and download them and check their md5sum or sha1sum, but I need to check this against the actual sum from Nexus so I can verify they are correct.我可以获取工件并下载它们并检查它们的 md5sum 或 sha1sum,但我需要对照来自 Nexus 的实际总和进行检查,以便我可以验证它们是否正确。
This is the command I'm using to grab files from Nexus:这是我用来从 Nexus 抓取文件的命令:
curl -v -L -o /mylocation/artifact.war -u 'myuser:mypass' --get 'http://ournexus.com/service/local/artifact/maven/content?g=com.ours.stuff&a=our-service-war&v=LATEST&r=snapshots&p=war'
Via http://nexus.xwiki.org/nexus/nexus-indexer-lucene-plugin/default/docs/path__lucene_search.html , it would appear that I can also search for the sha1 sum, but when I do &sha1 I get nothing extra or sha1=(sum), nothing is pulled up, even if I omit all the above options.通过http://nexus.xwiki.org/nexus/nexus-indexer-lucene-plugin/default/docs/path__lucene_search.html ,看起来我也可以搜索 sha1 总和,但是当我做 &sha1 时我什么也没得到extra 或 sha1=(sum),即使我省略了上述所有选项,也没有任何内容。
This works, but it goes to a specific war, and we need the latest (obviously):这有效,但它涉及特定的战争,我们需要最新的(显然):
http://ournexus.com/service/local/repositories/snapshots/content/com/ours/stuff/ourapp/1.0.0-SNAPSHOT/ourapp-1.0.0-20140730.173704-88.war.sha1
Is this possible, am I on the right track?这可能吗,我在正确的轨道上吗?
You can either fetch the file directly or use the Nexus API to retrieve it programmatically.您可以直接获取文件,也可以使用 Nexus API 以编程方式检索它。
The following URL:以下网址:
http://localhost:8081/nexus/service/local/artifact/maven/resolve?g=log4j&a=log4j&v=1.2.9&r=central
Returns the following result:返回以下结果:
<artifact-resolution>
<data>
<presentLocally>true</presentLocally>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.9</version>
<extension>jar</extension>
<snapshot>false</snapshot>
<snapshotBuildNumber>0</snapshotBuildNumber>
<snapshotTimeStamp>0</snapshotTimeStamp>
<sha1>55856d711ab8b88f8c7b04fd85ff1643ffbfde7c</sha1>
<repositoryPath>/log4j/log4j/1.2.9/log4j-1.2.9.jar</repositoryPath>
</data>
</artifact-resolution>
The xmllint command can be used to parse out the sha1 checksum value as follows: xmllint 命令可用于解析出 sha1 校验和值,如下所示:
$ curl -s "http://localhost:8081/nexus/service/local/artifact/maven/resolve?g=log4j&a=log4j&v=1.2.9&r=central" | xmllint --xpath "///sha1/text()" -
55856d711ab8b88f8c7b04fd85ff1643ffbfde7c
Nexus 2连结 2
Use the artifact content API to directly get the MD5/SHA1 checksum file by specifying the p
(packaging) or e
(extension) parameter as jar.md5
or jar.sha1
(or other relevant for your actual packaging).通过将p
(打包)或e
(扩展名)参数指定为jar.md5
或jar.sha1
(或其他与您的实际打包相关的参数),使用工件内容 API直接获取 MD5/SHA1 校验和文件。
Example:例子:
$ curl -s 'http://mynexus/service/local/artifact/maven/content?g=com.example&a=example&v=1.2.3&r=my-repo&e=jar.sha1'
55856d711ab8b88f8c7b04fd85ff1643ffbfde7c
Nexus 3连结 3
Use the Search API to find and download the asset.使用Search API查找和下载资产。
$ curl -sL 'https://mynexus/service/rest/v1/search/assets/download?repository=my-repo&sort=version&maven.groupId=com.example&maven.artifactId=example&maven.baseVersion=LATEST-SNAPSHOT&maven.extension=jar.sha1&maven.classifier='
7ff1ca9fb889c73d095b69a52d5c8609482b63ab
The query below works for me下面的查询对我有用
curl -u USER:PASS -X GET 'https://nexus.example.com:8443/service/rest/v1/search?repository=REPO_NAME&name=FILE_NAME' | jq '.items[0].assets[0].checksum'
Always good to check the API doc .检查 API 文档总是好的。
ps: username and password might be not needed for GET ps:GET 可能不需要用户名和密码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.