Reputation: 1947
So I previously had a script to search for folders in my Artifactory repositories for a certain property.
curl -i -X GET "${ARTIFACTORY_URI}/api/search/prop?my-prop=aaa&repos=my-repo
So far so good. The way I deployed my artifacts was that I placed them in sub folders and each of the sub folders got assigned the property my-prop. Then when I ran this command, I got back a list of the sub folders that satisfied my search criteria. This worked because the sub folders where all directly inside the repo my-repo.
However now we have had to do some restructuring of the Artifactory. Now the sub folders that I'm trying to list are located in a sub folder inside a sub folder inside the repo. My command still works, but it returns all the sub folders.
For example consider this:
my-repo:
* folder1
+ folder1-1
- folder1-1-1 (my-prop=aaa)
- folder1-1-2 (my-prop=bbb)
+ folder1-2
- folder1-2-1 (my-prop=aaa)
* folder2
+ folder2-1
- folder2-1-1 (my-prop=aaa)
So what I get now when searching for my-prop=aaa using the same command is folder1-1-1, folder1-2-1 and folder2-1-1. But what I want to do is limit the search to the sub-sub-folder folder1-1. I tried to simply add the path to the repos
parameter but it doesn't work.
curl -i -X GET "${ARTIFACTORY_URI}/api/search/prop?my-prop=aaa&repos=my-repo/folder1/folder1-1
So my question is how would one do that? The Artifactory website being the train wreck that it is, is of course not very helpful. Is there an additional folder/path parameter that I can use? I want to note, that I am working on an incredibly restrictive customer system and do not have access to the JFrog CLI tool, so I've got to do everything using curl and wget.
Upvotes: 0
Views: 2463
Reputation: 81
Somewhat related to this question and I thought I would add my solution here
So I was trying to query whether an artifact for a given version exists in this structure
repoName
- folderA
- folderA0
- 0.0.1.zip
- 0.0.2.zip
...
- folderA1
- 0.0.1.zip
- 0.0.2.zip
...
- folderB
- folderB1
...
With this curl
command I was able to narrow down to a given artifact:
curl -u USERNAME:PASSWORD -X POST "${ARTIFACTORY_URI}/api/search/aql" -H 'Content-Type: text/plain' --data 'items.find({"repo":"repoName","path":"folderA/folderA0","name":"0.0.1.zip","type":"file"})'
The output I got looked like this, which I can then parse with a JSON parser (jq
, a programming language library)
{
"results" : [ {
"repo" : "repoName",
"path" : "folderA/folderA0",
"name" : "0.0.1.zip",
"type" : "file",
"size" : 75069478,
"created" : "2022-10-24T17:22:10.260Z",
"created_by" : "USER",
"modified" : "2022-10-24T17:22:09.401Z",
"modified_by" : "USER",
"updated" : "2022-10-24T17:22:10.261Z"
} ],
"range" : {
"start_pos" : 0,
"end_pos" : 1,
"total" : 1
}
}
If the artifact did not exist, I got:
{
"results" : [ ],
"range" : {
"start_pos" : 0,
"end_pos" : 0,
"total" : 0
}
}
Upvotes: 0
Reputation: 1554
You should be able to use AQL (Artifactory Query Language) for that.
For your example, use something like:
curl -X POST "${ARTIFACTORY_URI}/api/search/aql" \
-H 'Content-Type: text/plain' \
--data 'items.find({"repo":"my-repo","@my-prop":"aaa","path":"folder1","type":"folder"})'
This will do a search in my-repo
for folders with the given property and under the exact path folder1
. You can use other operators, like $match
, if the path should be a pattern instead of an exact match.
For the full AQL syntax and guidelines, see: Artifactory Query Language
Upvotes: 2