We have a use case to download or at least list all .xml files from a folder inside a zip in Artifactory from a python script. Is it possible with REST or using AQL ? I am looking for a search query to get all xmls from a folder in zip so that I can use "archive entries download" thing from REST API to make download request for each file individually. Please help me with relevant information about the endpoint or query that I can use to achieve my task(list all xml in a folder in zip). Also please let me know of any other efficient approach to accomplish the task.

1

There are 1 answers

19
Dror Bereznitsky On

You can use an AQL query to get a list of files from a given path inside an archive.

As an example, lets take the my-archive.zip archive deployed in a repository names myrepo inside folder1 folder

enter image description here

The follow AQL query can be used to find all the xml files within this archive under the path level-1/level-2/level-3:

archive.entries.find( {
    "archive.item.path":{"$eq":"folder1"},
    "archive.item.name":{"$eq":"my-archive.zip"},
    "archive.entry.path":{"$eq":"level-1/level-2/level-3"},
    "archive.entry.name":{"$match":"*.xml"}
})

You can run this query using the AQL REST API method and get the following result:

{
"results" : [ {
  "entry.name" : "dummy.xml",
  "entry.path" : "level-1/level-2/level-3"
} ],
"range" : {
  "start_pos" : 0,
  "end_pos" : 1,
  "total" : 1
}
}

Here is an example of calling this REST API using curl (the query itself is stored in a file called aql.json):

curl -XPOST -uadmin:password -H"content-type: text/plain" [email protected] http://localhost:8081/artifactory/api/search/aql

enter image description here