API Access to delete artifacts in repository

2,977 views
Skip to first unread message

Sverre Moe

unread,
Mar 5, 2018, 1:10:54 PM3/5/18
to Nexus Users
Can I use the Nexus REST and Integration API to delete an artifact from yum repository?

Either through REST API or by creating a groovy script to execute within Nexus.

The Components API and Assets API allow for a REST DELETE:
https://help.sonatype.com/display/NXRM3/Components+API
  DELETE /service/rest/beta/components/{id}
https://help.sonatype.com/display/NXRM3/Assets+API
  DELETE /service/rest/beta/assets/{id}

Can I use either of these two to delete an artifact within a hosted yum repository?

It seems though I would need to get the id. Cannot see how I could get that id from query of a given artifact
There are examples to list all the artifacts within a repository, but then I would need to parse this JSON and find my artifact.rpm among them.


The Script API using groovy script seems very interesting and appealing.
I have some experience with groovy scripting with the Jenkins API. Though a different API same scripting language, as long as the Nexus API is well documented it should not be to much work to get a script to do the desired artifact deletion. Never knew there was such scripting API access to Nexus.
Can the Script API do artifact deletion?

After looking at the examples I don't see that the script API support deletion.
Though I have only scratched the surface of this API so far, but how can it not support it, considering that the REST API does support deletion of assets and components.

Rich Seddon

unread,
Mar 5, 2018, 1:42:52 PM3/5/18
to Nexus Users
It seems this isn't currently possible:


Follow the above issue for updates on this.

mdod...@sonatype.com

unread,
Mar 6, 2018, 7:04:27 AM3/6/18
to Nexus Users
Hi Sverre,

You are able to DELETE using the REST API.

I would suggest to firstly use the search endpoint, for example:
http://localhost:8081/service/rest/beta/search?repository=yum-hosted&format=yum&name=hello

this should respond with:
{
    "items": [
        {
            "id": "eXVtLWhvc3RlZDoyMTAzMWRmYWY0NWU1YjU4MzYxNTRiYWEwZGMyMWYwYw",
            "repository": "yum-hosted",
            "format": "yum",
            "group": null,
            "name": "hello",
            "version": "0.3-1.el7.centos",
            "assets": [
                {
                    "downloadUrl": "http://localhost:8081/repository/yum-hosted/packages/hello-0.3-1.el7.centos.x86_64.rpm",
                    "path": "packages/hello-0.3-1.el7.centos.x86_64.rpm",
                    "id": "eXVtLWhvc3RlZDpkNmU0YTUwYWJhM2M4YTE5ZmU3NjQ1OTFhMDlkOTY0YQ",
                    "repository": "yum-hosted",
                    "format": "yum",
                    "checksum": {
                        "sha1": "7f6eb40c02462fe1b633ecbbf86f981670cb4b16",
                        "sha512": "a49126e4c4a834fc17f653fb7e2124618ce3be28f67195fc28f88652f25522e9bb0b456e5bad0bd08a89ab1693d52bf81ec7bc0ff59f00c71a3cee8c9726d5f9",
                        "sha256": "aaff8223090388abc9a3216f2aecf3448098c6f373beee919698995bab67d12d",
                        "md5": "86231c84a1d4c3ab837fde7fd42c6d9b"
                    }
                }
            ],
            "tags": []
        }
    ],
    "continuationToken": null
}


then use the "id" value as highlighted in the example above to delete the component:
http://localhost:8081/service/rest/beta/components/eXVtLWhvc3RlZDoyMTAzMWRmYWY0NWU1YjU4MzYxNTRiYWEwZGMyMWYwYw

you can perform the search again to check it has been deleted:
http://localhost:8081/service/rest/beta/search?repository=yum-hosted&format=yum&name=hello

now responds with:
{
    "items": [],
    "continuationToken": null
}

Hope that helps

Mark 

Sverre Moe

unread,
Mar 6, 2018, 4:56:52 PM3/6/18
to Nexus Users
tirsdag 6. mars 2018 13.04.27 UTC+1 skrev mdod...@sonatype.com følgende:
Hi Sverre,

You are able to DELETE using the REST API.

I would suggest to firstly use the search endpoint, for example:
http://localhost:8081/service/rest/beta/search?repository=yum-hosted&format=yum&name=hello

this should respond with:
{
    "items": [
        {
            "id": "eXVtLWhvc3RlZDoyMTAzMWRmYWY0NWU1YjU4MzYxNTRiYWEwZGMyMWYwYw",
            "repository": "yum-hosted",
            "format": "yum",
            "group": null,
            "name": "hello",
            "version": "0.3-1.el7.centos",
            "assets": [
                {
                    "downloadUrl": "http://localhost:8081/repository/yum-hosted/packages/hello-0.3-1.el7.centos.x86_64.rpm",
                    "path": "packages/hello-0.3-1.el7.centos.x86_64.rpm",
                    "id": "eXVtLWhvc3RlZDpkNmU0YTUwYWJhM2M4YTE5ZmU3NjQ1OTFhMDlkOTY0YQ",
 
then use the "id" value as highlighted in the example above to delete the component:
http://localhost:8081/service/rest/beta/components/eXVtLWhvc3RlZDoyMTAzMWRmYWY0NWU1YjU4MzYxNTRiYWEwZGMyMWYwYw
 
What is the difference from deleting this component, instead of the underlying asset?

This looks great. I have requested that we could archive old RPMs, and with this we can.
First by downloading/moving the RPM to a raw storage, then delete it and last upload the new RPM.

Does it work with the latest Nexus REST API? Considering that Rich Seddon mentioned a feature request to support DELETE on rpms in yum (NEXUS-16409).

/Sverre 

mdod...@sonatype.com

unread,
Mar 7, 2018, 9:36:09 AM3/7/18
to Nexus Users
Hi Sverre,

Currently the REST API is assumed to have a 1-1 relationship between asset and component. So, deleting a component will delete all assets that are associated with the component and deleting an asset will in turn delete its associated component which will then iterate through all the remaining assets.

In the case of yum the same RPMs that have different architectures will be associated with the same component.

For example, if a search of:

http://localhost:8081/service/rest/beta/search?repository=yum-hosted&format=yum&name=bakefile&version=0.2.8-3.el6.centos


returns the following (note two assets of different architectures are present for the same rpm):


{
   
"items": [
       
{
           
"id": "eXVtLWhvc3RlZDpkMDY0ODA0YThlZDVhZDZlNjhmZGU5MWNmM2NiZTgzMw",

           
"repository": "yum-hosted",
           
"format": "yum",
           
"group": null,

           
"name": "bakefile",
           
"version": "0.2.8-3.el6.centos",
           
"assets": [
               
{
                   
"downloadUrl": "http://localhost:8081/repository/yum-hosted/Packages/bakefile-0.2.8-3.el6.centos.i686.rpm",
                   
"path": "Packages/bakefile-0.2.8-3.el6.centos.i686.rpm",
                   
"id": "eXVtLWhvc3RlZDoyZmZmNTA5YTdjMmE5ZWJlMjI1MmIxNTY5OWI3MzdjYg",

                   
"repository": "yum-hosted",
                   
"format": "yum",

                   
"checksum": {
                       
"sha1": "998b85a31cf312a606d60f8bdd39ba4e0a8a6c48",
                       
"sha512": "1d46970a27058884860da581cd569a75c7266e31c7512f9eced9613e663bd9796ea0b117eea442fe69950d37cc6d2b4c6ed07dfd14ef1e847a719b4fd1817c78",
                       
"sha256": "4dbabf0c42761b478cd64379d46ed903567e655ca1d345f16e17c5ffb122563b",
                       
"md5": "0b59132945f9d60ec000e21c480d864a"
                   
}
               
},
               
{
                   
"downloadUrl": "http://localhost:8081/repository/yum-hosted/Packages/bakefile-0.2.8-3.el6.centos.x86_64.rpm",
                   
"path": "Packages/bakefile-0.2.8-3.el6.centos.x86_64.rpm",
                   
"id": "eXVtLWhvc3RlZDoyNGMxZmUzMzVkMjY2NTJmODdmYTdhNzQ5ZWI0YTUwYQ",

                   
"repository": "yum-hosted",
                   
"format": "yum",

                   
"checksum": {
                       
"sha1": "24ec6ddf8bbcdf0eefaed3daeac705747f025eb9",
                       
"sha512": "6d2f131fac7fb69073c88bfbe7f689b54b0e1d943292483e8a455d80764fd8183f2cbdbf05cb4c9071a36ca3897bd61c4fabbf204c276b73df0f7cac195c32b3",
                       
"sha256": "261f2006a15aae21008181b687878d8b81081b52a1df74f82e8cc326c40c78c3",
                       
"md5": "71c01c1f9a0f155650e517609ecc065a"

                   
}
               
}
           
],
           
"tags": []
       
}
   
],
   
"continuationToken": null
 

will result in the deletion of both RPMs and the associated component.

To summarise, currently there is no difference between deleting by component or asset but I have just raised a new ticket (https://issues.sonatype.org/browse/NEXUS-16475) to stop a delete by asset for yum from deleting the component. See the Acceptance Criteria section for what will happen once the ticket is completed.


The NEXUS-16409 ticket is not for the REST API, it is to be able to delete using the repository name endpoint.

Hope that helps

Mark

Sverre Moe

unread,
Mar 7, 2018, 12:35:44 PM3/7/18
to Nexus Users
onsdag 7. mars 2018 15.36.09 UTC+1 skrev mdod...@sonatype.com følgende:
Hi Sverre,

Hope that helps

Mark


Thanks for clarifying. 

The JSON search result should have had an parameter for architecture.
"arch": "i686",
but not a showstopper at the moment. 

Also perhaps it is necessary, but it is a waste of data having repository and format parameter on both component and asset.
"repository": "yum-hosted",
"format": "yum",
The version parameter is not duplicated and is only on the component, so why these two?

Sverre Moe

unread,
Apr 5, 2018, 11:02:18 AM4/5/18
to Nexus Users
onsdag 7. mars 2018 15.36.09 UTC+1 skrev mdod...@sonatype.com følgende:
Hi Sverre,

Currently the REST API is assumed to have a 1-1 relationship between asset and component. So, deleting a component will delete all assets that are associated with the component and deleting an asset will in turn delete its associated component which will then iterate through all the remaining assets.

 
In the case of yum the same RPMs that have different architectures will be associated with the same component.


Then I can't delete on a single yum repository without deleting all the other packages in other yum repositories.

I have set up a hosted yum repository with depth=2
I have uploaded our RPMs for master and ReleaseA branches.
After a search using the REST-API I got result for both branches. One component, 4 assets

releaserepo
  -- master
    -- opensuse42.3
      -- noarch
      -- x86_64
          -- my-package-1.1.0-master.c245a45.x86_64.rpm
    -- sles12.3
      -- noarch
      -- x86_64
          -- my-package-1.1.0-master.c245a45.x86_64.rpm
  -- releaseA 
    -- opensuse42.3
      -- noarch
      -- x86_64
          -- my-package-1.0.0-ReleaseA.a45bc3a.x86_64.rpm
    -- sles12.3
      -- noarch
      -- x86_64
          -- my-package-1.0.0-ReleaseA.a45bc3a.x86_64.rpm

When I search for a package the the releaserepo repository, I got one component, with 4 assets.

Deleting the component would cause it to delete my-packages from every branch in the repository.
If I want to only delete the packages for the master repository how could I do that if deleting the assets causes Nexus to iterate through the component and delete all the assets?

{
 
"items" : [ {
   
"id" : "cmVsZWFzZXJlcG86NzZkN2Q3ZTQxODZhMzkwZjdhODQ5ODE0OGUxZDkxYjc",
   
"repository" : "releaserepo",

   
"format" : "yum",
   
"group" : null,

   
"name" : "my-package",
   
"version" : "1.1.0-master.c245a45",
   
"assets" : [ {
     
"downloadUrl" : "https://nexus.company.com:8443/repository/releaserepo/master/opensuse42.3/x86_64/my-package-1.1.0-master.c245a45.x86_64.rpm",
     
"path" : "master/opensuse42.3/x86_64/my-package-1.1.0-master.c245a45.x86_64.rpm",
     
"id" : "cmVsZWFzZXJlcG86MGFiODBhNzQzOTIxZTQyNjkxOWQ4ZGZkNDZiMWE3NmU",
     
"repository" : "releaserepo",
     
"format" : "yum",
     
"checksum" : {
       
"sha1" : "b009716ea836c5556b5176ea37ffe799074be3db",
       
"sha512" : "880770918d95855c60dda52270140933ac6df23617b91d5ca9aabda80dad7455dc9ebe174578a67b7461ce0596bbbc8ff171d9cad8cf6ca89ee73cf4ea458c17",
       
"sha256" : "27c8d51f52cde2c0c4ed3295a491110494e3db218202de2925c60e79a1ad6e05",
       
"md5" : "d82c460890456e6b5cd06645b97941c1"
     
}
   
}, {
     
"downloadUrl" : "https://nexus.company.com:8443/repository/releaserepo/master/sles12.3/x86_64/my-package-1.1.0-master.c245a45.x86_64.rpm",
     
"path" : "master/sles12.3/x86_64/my-package-1.1.0-master.c245a45.x86_64.rpm",
     
"id" : "cmVsZWFzZXJlcG86ZDQ4MTE3NTQxZGNiODllYzg0MGIzMjIxN2Q5YjNhNTM",
     
"repository" : "releaserepo",
     
"format" : "yum",
     
"checksum" : {
       
"sha1" : "1c46b06a3a48ede07cddcc941db0019eddf16caa",
       
"sha512" : "72df390912eb01d3f27f3abb40382c0330d0e5930c402556a2e8ab39b05e2f28fc19abd1089d0f1fc01d66cde134fc3a711d85459bd5e97e9716fee7f21976a2",
       
"sha256" : "f190bb23842cad4602682c4408651d71c8bee3d7dba20545a81f769d294e67a4",
       
"md5" : "76c3b1e33c0af35da2622228fd211d43"
     
}
   
} ]
 
}, {
   
"id" : "cmVsZWFzZXJlcG86ZGZiZWYwOWVmZTE2NDRlYTE3ZmQzNTMyNjk0ZWYyMjA",
   
"repository" : "releaserepo",

   
"format" : "yum",
   
"group" : null,

   
"name" : "my-package",
   
"version" : "1.0.0-ReleaseA.a45bc3a",
   
"assets" : [ {
     
"downloadUrl" : "https://nexus.company.com:8443/repository/releaserepo/ReleaseA/opensuse42.3/x86_64/my-package-1.0.0-ReleaseA.a45bc3a.x86_64.rpm",
     
"path" : "ReleaseA/opensuse42.3/x86_64/my-package-1.0.0-ReleaseA.a45bc3a.x86_64.rpm",
     
"id" : "cmVsZWFzZXJlcG86ZDQ4MTE3NTQxZGNiODllY2E3MzBlYTczYTNkNTBlNmI",
     
"repository" : "releaserepo",
     
"format" : "yum",
     
"checksum" : {
       
"sha1" : "f74859c1707dd6e32f9e61ce5cb830e359c267ea",
       
"sha512" : "03c907b61653e84d5efa4e85ed7c3939f6dc6bd3c7f1cc1c449e9c9eaaad51d006533b6b842e6b675ab26deb906e3eb26e8a6b9be4fcb1563a60bd7124c6ebac",
       
"sha256" : "3b4df734513af567f877f29f35e79c6f61961a3e47ba1e9cb7f5f920579d1664",
       
"md5" : "844a3c484b5cf4b4c1c2effafd385df4"
     
}
   
}, {
     
"downloadUrl" : "https://nexus.company.com:8443/repository/releaserepo/ReleaseA/sles12.3/x86_64/my-package-1.0.0-ReleaseA.a45bc3a.x86_64.rpm",
     
"path" : "ReleaseA/sles12.3/x86_64/my-package-1.0.0-ReleaseA.a45bc3a.x86_64.rpm",
     
"id" : "cmVsZWFzZXJlcG86MTNiMjllNDQ5ZjBlM2I4ZDY4OGI2ZWQ3YzdjODk2MzI",
     
"repository" : "releaserepo",
     
"format" : "yum",
     
"checksum" : {
       
"sha1" : "9c7c3c0a09e2d7d43f58e0146c7f915eeb569468",
       
"sha512" : "e31a13e75278939237baaa2f249ff526bf52782f6419695bdfe826fe49ff28d04a7705b54be6a7a7ef4d8b39925efec51197b1b3e0c8913745ffb2a69e562e0a",
       
"sha256" : "f75bb7007cadfd473e1581c621fd3fc8c588a8f7302e561192276fb95c512415",
       
"md5" : "c296e7523fda85e9b66594932f6bda25"
     
}
   
} ]
 
} ],
 
"continuationToken" : null
}


Perhaps then what I need is several distinct nexus yum repositories for each branch.
I hope this can be avoided, as it makes maintenance more difficult. I don't want to create a new release repository in Nexus every time we make a new release.
master-repo (depth=1)
    -- opensuse42.3
      -- noarch
      -- x86_64
    -- sles12.3
      -- noarch
      -- x86_64
ReleaseA-repo (depth=1)
    -- opensuse42.3
      -- noarch
      -- x86_64
    -- sles12.3
      -- noarch
      -- x86_64

Sverre Moe

unread,
Apr 5, 2018, 11:06:24 AM4/5/18
to Nexus Users
My bad... I think I need a break, my eyes are tired.
I really had two components, each with 2 assets.

So deleting the component for a single branch would then work.
I would have to parse either version or path to find the component with a given branch
Reply all
Reply to author
Forward
0 new messages