How to get docker asset details ? (Last downloaded, Uploader)

Hello,
I was trying to figure out how to get docker asset details which are normally visible via web UI, but using Nexus API…
Particularly
-Last downloaded
-Uploader
-Uploader’s IP Address
-Blob created
any ideas?
/service/rest/v1/assets/id - doesn’t show
/service/rest/v1/components/id - doesn’t show

This can be done with groovy scripting

import org.sonatype.nexus.repository.storage.StorageFacet
import org.sonatype.nexus.repository.Repository
import org.sonatype.nexus.repository.storage.Asset

repository.repositoryManager.browse().each { Repository repo ->
    StorageFacet storageFacet = repo.facet(StorageFacet)
    def tx = storageFacet.txSupplier().get()
    try {
        tx.begin()

        tx.browseAssets(tx.findBucket(repo)).each { Asset asset ->
            log.info(asset.attributes().get('content').get('etag'))
            log.info(asset.attributes().get('content').get('last_modified'))
        }
    } finally {
        tx.close()
    }
}

The attributes available can be found in the component detail UI.

Also see here:


thanks Rich,
It is unpleasant that these information are not available via API directly. I am building a python script for analyzing the repo for further advanced cleanup policies (using API for advanced cleanup policy is recommended by Sonatype) and I have to split the logic to groovy script and python :frowning:

I am sorry, but the script is not working … ‘etag’ is allways null and ‘last_modified’ is required with toString() method

2019-11-21 16:02:31,974+0100 INFO  [quartz-3-thread-19]  *SYSTEM org.sonatype.nexus.internal.script.ScriptTask - null
2019-11-21 16:02:31,974+0100 INFO  [quartz-3-thread-19]  *SYSTEM org.sonatype.nexus.internal.script.ScriptTask - Wed Oct 02 17:14:29 CEST 2019

It’s just an example, check to see what attributes are available for the asset you are querying in the UI, and modify the script as needed.

Ok, I got, thanks … I am able to get sha256+last_modified, but I cannot find last_downloaded … I have tried to download components using groovy script, but it is also not in there… is there some doc where I can find object structure and class methods ? It is very hard to find in source code…

I have just figured it out…
There is much easier way of getting all necessary information,instead of going down through get() method - which may end in null.get() exception - use methods to access asset attributes directly… e.g.
asset.lastDownloaded()
asset.blobUpdated()
class definition