Artifactory user update removes admin - artifactory

Consider the following POST to the Artifactory REST API:
curl -f -u admin:password \
-X POST \
-H 'Content-Type: application/json; charset=UTF-8' \
-d '{ "groups": ["oldgroup", "newgroup"] }' \
http://localhost/artifactory/api/security/users/targetuser
This request does ensure that the user is a member of both the "oldgroup" and the "newgroup" but additionally it removes admin privileges from the user (if they had it): Ex. { "admin": true } changes to { "admin": false } after the update.
It would appear that one would need to additionally pass { "admin": true } if the user was an admin originally in order to avoid this strange side effect of the update:
curl -f -u admin:password \
-X POST \
-H 'Content-Type: application/json; charset=UTF-8' \
-d '{ "admin": true, "groups": ["oldgroup", "newgroup"] }' \
http://localhost/artifactory/api/security/users/targetuser
This does not seem to be implemented as a true update. Is this a bug? Am I missing something?
Additionally, I was wondering if this had to do with the 'Content-Type' header I was originally passing as I was using the full application/vnd.org.jfrog.artifactory.security.User+json but a change to just application/json has the same result.
I could see if I was using the PUT method to Create or Replace a user but this is the POST request and doesn't seem to be working as I expect it to.
Artifactory REST API Documentation and my research:
Method: Update User
Object: application/vnd.org.jfrog.artifactory.security.User+json
Similar unanswered post from the old Jfrog forums: thread

As Artifactory, upon getting the update REST API command, can't tell which params you intended to change, for example in your case change the groups, it will take your input and apply it to the user. That means that the value of Admin will be set to false as this is the default value to that field. In case that you wish to save the existing configuration for the user, I would suggest doing a get request for the user details > saving it to a JSON file > edit it to the desired values > post it to Artifactory. That way you won't change the values that you intend to keep.

Related

Automating removing user groups

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" : []
}

How to POST to Wordpress with Basic Auth using (ba)sh cURL?

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.

external_account not accepting dictionary?

I am using stripe to update the card on a managed account external_account, but the error is asking for a token but the docs are saying wither token or dictionary.
https://stripe.com/docs/api#account_create_card
-d external_account={"object":"card", "exp_month":"04", "exp_year":"2019", "number":"5200828282828210"}
Error
{
"error": {
"type": "invalid_request_error",
"message": "Received unknown parameter: number",
"param": "number"
}
}
The reason that your example curl command doesn't work is that the Stripe API requires that the Content-Type header of requests sent to it be application/x-www-form-urlencoded and you are sending a JSON string.
curl https://api.stripe.com/v1/accounts/acct_XXYYZZ/external_accounts \
-u sk_test_AABBCC: \
-d external_account[object]="card" \
-d external_account[number]=5200828282828210 \
-d external_account[exp_month]=04 \
-d external_account[exp_year]=2019 \
-d external_account[cvc]=123
From the curl man-page, the "-d" switch on the curl command "Sends the specified data in a POST request to the HTTP server, in the same way that a browser does when a user has filled in an HTML form and presses the submit button. This will cause curl to pass the data to the server using the content-type application/x-www-form-urlencoded" which what you want, and the square bracket notation is how you send a hash/dictionary as Content-Type: application/x-www-form-urlencoded.

Fiware Keystone API Create User

We are trying to create users in Fiware IDM using Keystone Identity API.
We are sending the following curl command
curl -s \
-H "X-Auth-Token: e746971040657101bb1e" \
-H "Content-Type: application/json" \
-d '{"user": {"name": "newuser", "password": "changeme"}}' \
http://localhost:35357/v3/users | python -mjson.tool
The token we have used is the one configured in keystone.conf
admin_token=e746971040657101bb1e
But the result we are getting is the following
{
"error": {
"code": 401,
"message": "The request you have made requires authentication.",
"title": "Unauthorized"
}
}
Does anyone have an idea about what can happen?
A couple of ideas for you.
One is that the port value 35357 is not for the admin API calls, it's intended for user calls.
Also since you are using the v3 API I believe that the token can't be used when creating a user unless you are indicating a domain.
However I can't tell from your curl command what action you are trying to do.

How do you create a user using RESTServer in Drupal?

Using REST Server 6.x-2.0-beta3, I'm trying to understand how to post to user.save.
curl -d 'XX' -v http://localhost/services/rest/service_user/save
I've tried to replace XX with:
account{'name':'myname','pass':'mypassword','mail':'my#email.org'}
account = {'name':'myname','pass':'mypassword','mail':'my#email.org'}
account="name=myname,pass=mypassword,mail=myemail.org"
account=name=myname,pass=mypassword,mail=myemail.org
account=myname,mypassword,myemail.org
But none of these seems to be right and finding any documention regarding this is next to impossible.
I've also tried the following:
curl -H "Content-Type: application/json" -d 'account={"name":"myname","pass":"mypassword","email":"123"}' -v http://localhost/services/rest/service_user/save
The error I get in this case is:
HTTP/1.0 406 Not Acceptable: Missing required argument account
Hi I also just started working with this module and wondering how to create content using JSON.
Just been able to create a simple node using this:
Post URL: http://path-to-site/services/rest/node
Request Header: Content-Type: application/json
Request Body: {"type":"story","title":"REST Test","body":"REST using JSON"}
I think you're using the wrong URL
I figured it out:
curl -H “application/x-www-form-urlencoded” -d "sessid=xxxx" -d "account[name]=MyName&account[pass]=mypass&account[mail]=myemail#gmail.com&account[conf_mail]=myemail#gmail.com" -v http://path-to-site/services/rest/service_user/save
You only have to add -d "sessid=xxxx" if you have configured Services to require a session. Make sure in that case to replace xxxx with your actual session id (from system.connect).

Resources