I'm trying to figure it out how to retrieve the latest version of each image stored in the Docker repo using AQL. The following code gives me all the versions but I couldn't find a way to get only the latest one for each asset.
curl -u "username:password" -i -X POST <host>/artifactory/api/search/aql -H "Content-Type: text/plain" -d '
items.find(
{
"repo":{"$eq":"my-docker-repo"},
"$or":[
{"path": { "$match" : "application/*" }},
{"path": { "$match" : "service/*" }}
]
}
).include("repo", "path", "name", "created").sort({"$desc" : ["path","created"]})'
Thanks!
Andre
The brainiacs over at R&D created a cool util that also serves the purpose your'e looking to achieve, you can get it here. You can also check the sources for the exact AQL query it runs if you want to implement something similar for your own usecase.
Related
I need help because I'm not good with HTTP Requests.
I am trying to create a Release on my XL Release server with a HTTP request. Right now I'm doing it with Curl, in a batch file, like that
curl "https://{ID}:{password}#{IP}:{port}/api/v1/templates/Applications/Folder{IDFolder}/create" -i -X POST -H 'Content-Type:application/json' -H 'Accept:application/json' -d %0\..\ReleaseConfig.json
The data file, which is in the same directory as the script, I'm calling is a json like that :
{ "releaseTitle" : "API Test", "releaseVariables" : { }, "releasePasswordVariables" : { }, "scheduledStartDate" : null, "autoStart" : false }
The problem is, I get an error like that while executing my command :
RESTEASY003065: Cannot consume content type
Do you have any idea what can help my case ?
Thanks
By looking at your filename, it seems that you are on Windows. I suspect you can't escape your Content-type with quote, you have to use double quotes.
Also, to pass a file as POST data, you have to use an #, like this:
curl "https://{ID}:{password}#{IP}:{port}/api/v1/templates/Applications/Folder{IDFolder}/create" -i -X POST -H "Content-Type:application/json" -H "Accept:application/json" -d #%0\..\ReleaseConfig.json
I'm trying to automate removing the users groups in Artifactory for users who leave the company.
I'm retrieving their user JSON details, then modifying the JSON by deleting the groups section. So far so good. But when I upload the updated JSON the groups are not removed from that user in Artifactory.
I'm using the following command to upload the updated JSON:
curl -u <username>:<password> -XPUT "<server name>/artifactory/api/security/users/<user>" -H "Content-Type: application/json" -T user.json
I'm not getting an error when executing the command, but nothing is updated for that user.
Any ideas what I'm doing wrong here?
As per the Artifactory REST API wiki you should use a POST method to update a User's groups, so as an example - To update a user (u1) and delete his groups I would use:
curl -u<an_admin_user>:<a_password> -XPOST http://<rt_server>:<port>/artifactory/api/security/users/u1 -T /path/to/file/Update_U1_Groups.json
where the JSON file would look like:
{
"name" : "u1",
"groups" : []
}
1. What I'm trying
I'm trying to POST to my Wordpress website with (bash) cURL but what seems to be not working is the user authorization.
So far, what I've been attempting is
curl \
-u ${USERNAME}:${PASSWORD} \
-X POST \
-H "Content-Type: application/json" \
-d '{"title": "this is a test"}' \
--url http://mywebsite.com.br/wp-json/wp/v2/posts/
2. What I get
{
"code": "rest_cannot_create",
"message": "Sorry, you are not allowed to create posts as this user.",
"data": {"status": 401}
}
What am I doing wrong? Maybe the -u flag is not the one I'm looking for? That's what I usually try when using BasicAuth; is it not the case here? Is the wp-json specification correct?
In the question, I'm using Basic Authentication, which actually needs to be enabled.
You can do it by downloading the WP Basic Auth Plugin from Github and then uploading, installing and activating it within your Wordpress website.
Once that's done, the question's code should work fine.
Reading this API guide. My Artifactory version is 4.12.2.
https://www.jfrog.com/confluence/display/RTF/Artifactory+REST+API#ArtifactoryRESTAPI-ItemProperties
It says to deploy an artifact like so.
curl -u myUser:myP455w0rd! -X PUT "http://localhost:8081/artifactory/my-repository/my/new/artifact/directory/file.txt" -T Desktop/myNewFile.txt
That works fine but I also want to add properties to file.txt while also uploading. I did see a separate API to set properties.
PUT /api/storage/libs-release-local/ch/qos/logback/logback-classic/0.9.9?properties=os=win,linux;qa=done&recursive=1
That works. I thought maybe it would work to do this.
curl -u myUser:myP455w0rd! -X PUT "http://localhost:8081/artifactory/my-repository/my/new/artifact/directory/file.txt?properties=os=win,linux;qa=done&recursive=1" -T Desktop/myNewFile.txt
It didn't work. Is it possible to upload an artifact and simultaneously set properties or does it have to be two different API calls?
I do use jfrog cli but I need an API solution.
The correct format would be something like:
curl -u myUser:myP455w0rd! -X PUT "http://localhost:8081/artifactory/my-repository/my/new/artifact/directory/file.txt;propertyA=valueA;propertyB=valueB" -T Desktop/myNewFile.txt
You can find the relevant documentation here (I agree that it was "well hidden")
i have installed latest version of Artifactory Pro (5.8.3) on Centos7. The default admin credentials are admin/password. i want to change the password through command-line but unable to do so.
Does any one has any inputs how to do this?
Following troubleshootings i tried:
jfrog rt c rt-server-1 --url=http://domain/artifactory --user=admin --password=password ...
nothing happens , when i try to use a new password i get 401: unauthorize error
jfrog guide tells to generate security.xml and add the hash code of the new password but security.xml does not get generated even after following all their steps.
also tried to use curl commands but no use.
If any one has gone through similar issue please share your findings. let me know if you need more info.know on case
JFrog CLI currently does not support changing of a user's password. the CLI config method you were using simply lets you configure your server and credentials to be used by other CLI command later.
What you can do is use a simple curl command to invoke the change password API as described here.
specifically, in your example changing the Admin's password to "NewPassword" will be something like:
curl -X POST -u admin:password -H "Content-type: application/json" -d '{ "userName" : "admin", "oldPassword" : "password", "newPassword1" : "NewPassword", "newPassword2" : "NewPassword" }' http://yourartifactory:8081/artifactory/api/security/users/authorization/changePassword