Team,
I'm facing difficulties setting up salt-api.
I'm in a setup ubuntu 16 and CherryPy 3.5. Which is a open bug https://github.com/saltstack/salt/issues/37783 .
I managed to downgrade to CherryPy 3.2.3.
rest_cherrypy:
port: 8000
disable_ssl: True
external_auth: pam:
saltuser:
- .*
Upon salt-api and salt-master restart
curl -k http://localhost:8000
{"clients": ["local", "local_async",
> "local_batch", "local_subset", "runner", "runner_async", "ssh",
> "wheel", "wheel_async"], "return": "Welcome"}
While login or submitting a job I get 401 Unauthorized .
curl -sSk http://localhost:8000/login -H 'Accept: application/x-yaml' -d username=saltuser -d password=passwd -d eauth=pam
curl -vki http://localhost:8000 -H "Accept: application/x-yaml" -d client=local -d tgt='stg-ubuntu102*' -d fun='cmd.run' -d "kwarg": {"cmd": "touch /tmp/mannoj"}
Can someone please guide me here?
In order to execute commands through the Salt API you need either to login while executing the command or passing X-Auth-Token. So what you need to do is to use the token that was generated by executing the login command
First make sure that you have a system user before executing the following
curl -sSk http://localhost:8000/login -H 'Accept: application/x-yaml' -d username=saltuser -d password=passwd -d eauth=pam
In your next request:
curl -vki http://localhost:8000 -H "Accept: application/x-yaml" -H "X-Auth-Token: TOKEN_GOES_HERE" -d client=local -d tgt='stg-ubuntu102*' -d fun='cmd.run' -d "kwarg": {"cmd": "touch /tmp/mannoj"}
Note that I have added -H "X-Auth-Token: TOKEN_GOES_HERE"
For more information check the following page
Related
I've got a curl request which looks like:
curl -s http://someurl1.com -H 'Accept: application/json' -u 'emv:LgKrAVkFf2c6mr4DFBQUdjBK' -d grant_type='password' -d scope='offline_access' -d username='datafiles#random.com' -d password='456Qwer()' -d acr_values='tenant:sdfdfsdf-e5e7-42d5-9881-sdfsdf' | python -m json.tool
How can I construct a simple HTTP request from it? I've tried to import it with postman but got Error while importing Curl: Zero or Multiple option-less arguments. Only one is supported (the URL)
curl http://someurl1.com -H 'Accept: application/json' -u 'emv:LgKrAVkFf2c6mr4DFBQUdjBK' -d grant_type='password' -d scope='offline_access' -d username='datafiles#random.com' -d password='456Qwer()' -d acr_values='tenant:sdfdfsdf-e5e7-42d5-9881-sdfsdf'
this string can be imported by Postman.
I get the error curl: Can't open 'files=#1.txt'! when trying to run code:
curl -v -XPOST -k -H "Accept: application/json" -T "files=#1.txt" https://192.168.1.102/
any suggestion on how to pass the text file's name properly?
-T is for PUT and wants a file name only:
curl -T 1.txt https://192.168.1.102/
You seem to want to POST a file? If you want it sent "plainly", you probably want:
curl -H "Accept: application/json" --data-binary #1.txt https://192.168.1.102/
If you want to instead send the file as a multipart formpost, you might do it similar to:
curl -F files=#1.txt https://192.168.1.102/
I am using the url at the developer-api.nest.com site, and my request is re-directed to the firebase-apiserver01...01.dapi.production.nest.com
I get the correct structured data back, using this dos command:
curl -v -k -L -X GET "https://developer-api.nest.com/structures/Za6hCZpmt4g6mBTaaA96yuY87lzLtsucYjbxW_b_thAuJJ7oUOelKA/?auth=c.om2...AeiE"
I get the error 'Invalid content sent' when I send this PATCH
curl -v -k -L -X PATCH "https://developer-api.nest.com/structures/Za6hCZpmt4g6mBTaaA96yuY87lzLtsucYjbxW_b_thAuJJ7oUOelKA/?auth=c.om2...AeiE" -H "Content-Type: application/json" -d '{"away":"home"}'
I have tried adding '.json' before the question mark, but get the same error.
To set the structure to home/away you'll need to send a PUT request for example as follows:
curl -v -L -X PUT "https://developer-api.nest.com/structures/g-9y-2xkHpBh1MGkVaqXOGJiKOB9MkoW1hhYyQk2vAunCK8a731jbg?auth=<AUTH_TOKEN>" -H "Content-Type: application/json" -d '{"away":"home"}'
Hope that helps
--Nagesh
how I do post multiple values to the same key using cURL?
for example when I ran the following to my example.com URL, it complained...is the format correct or is this a problem with the backend not being able to handle the request?
curl -k -H 'Accept: application/json' --user admin:admin example.com -d name=peter -d name=paul -d name=mary
Multiple -d looks fine. The docs said -d name=daniel -d skill=lousy will generate name=daniel&skill=lousy
http://curl.haxx.se/docs/manpage.html#-d
So if you want send an array, you have to use the [] brackets.
-d name[]=peter -d name[]=paul -d name[]=mary
It looks like you can also use
-d "name[]=peter&name[]=paul&name=mary"
I am trying to update an object using curl.
There are 2 approaches I am trying:
1] Provide usr/pswd in patch reques
=> says "Warning: You can only select one HTTP request!"
2] Save login cookie first and use it to perform patch
with -I => says "Warning: You can only select one HTTP request!"
without -I => [{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]
Here are the requests:
1] Provide usr/pswd in patch request
curl -I -H "Content-Type: application/json" -H "charset=UTF-8" -H "Accept: application/json" -X PATCH -d '{"field":"new_value"}' -D- 'https://url?un=<uname>&pw=<pwd>/<path to obj>/<key>' --trace-ascii trace.OUT
Warning: You can only select one HTTP request!
2] Save login cookie first and use it to perform patch
curl -c cookies.txt 'https://url?un=<uname>&pw=<pwd>'
curl -b cookies.txt -H "Content-Type: application/json" -H "charset=UTF-8" -H "Accept: application/json" -X PATCH -d '{"field":"new_value"}' -D- 'https://url/<path to obj>/<key>'
=>[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]
curl **-I** cookies.txt -H "Content-Type: application/json" -H "charset=UTF-8" -H "Accept: application/json" -X PATCH -d '{"field":"new_value"}' -D- 'https://url/<path to obj>/<key>'
=> Warning: You can only select one HTTP request!
We have a tool that can perform the patch using a UI and I checked the request/headers in firebug and seems like I have everything in the request. However I want to script this call.
Any suggestions?
Thanks!
"-I" implies a HEAD request, but you specify a HTTP method of "PATCH". Curl complains that it can't do both at the same time.