Why isn't salt-api working with this configuration? - api

I'm trying to set up a really basic salt-api configuration just to test it out. I'm using salt-master and salt-minion 2016.3.0 Boron on Ubuntu 14.04
I'm using this tutorial, and my configuration is below.
/srv/salt/top.sls
base:
'*':
- reactor
/etc/salt/master.d/reactor.conf
reactor:
- 'salt/netapi/hook/restart':
- /srv/reactor/test.sls
/srv/reactor/test.sls
{% set postdata = data.get('post', {}) %}
{% if postdata.secretkey == "replacethiswithsomethingbetter" %}
test:
local.cmd.run:
- tgt: '{{ postdata.tgt }}'
-arg:
- touch /home/username/test.txt
{% endif %}
I have restarted the master, and if I run salt '*' state.sls reactor then everything in the state works fine. All it does is touch /home/username/test.txt, and that file is created when I run the state.
The command I'm running to use the API is
curl -H "Accept: application/json" -d tgt='*' -d secretkey="replacethiswithsomethingbetter" -k https://192.168.1.1:8080/hook/services/restart
and that command returns {"success": true}
Then I check on the minion, and the file hasn't been created.
The output of salt-run state.event pretty=True is
salt/netapi/hook/services/restart {
"_stamp": "2016-06-29T19:30:04.193832",
"body": "",
"headers": {
"Accept": "application/json",
"Content-Length": "46",
"Content-Type": "application/x-www-form-urlencoded",
"Host": "192.168.1.1:8080",
"Remote-Addr": "192.168.1.3",
"User-Agent": "curl/7.35.0"
},
"post": {
"secretkey": "replacethiswithsomethingbetter",
"tgt": "*"
}
}
I did go through all of the self signed cert steps. I'm not 100% sure why I need those, but it's done, and they are listed in the rest_cherrypy configs.
Any help is appreciated.
EDIT 1
I edited the reactor stuff, because there's an example of using cmd.run, or local.cmd.run located int he salt docs here
It's still returning true, and not working.

URL is wrong:
https://192.168.1.1:8080/hook/services/restart
should change to :
https://192.168.1.1:8080/hook/restart
because what you defined is :
reactor:
- 'salt/netapi/hook/restart':
- /srv/reactor/test.sls
You can view debug log by run salt-master as salt-master -l debug .

Related

influxdb2.4.0 set auth error authorization not found

i'm a new influxdb user and i want to deploy influxdb2 on a linux server without root authority
so i use influxd from influxdb2-2.4.0-linux-amd64.tar.gz as influxdb and influx from influxdb2-client-2.4.0-linux-amd64.tar.gz as influx-cli.
my influxdb use command
./influxd
to start with config.yaml in the same path, the yaml config is
bolt-path: mypath/.influxdbv2/influxd.bolt
engine-path: mypath/.influxdbv2/engine
http-bind-address: ":18088"
instance-id: ":18088"
sqlite-path: mypath/.influxdbv2/influxd.sqlite
log-level: debug
after start influxdb I connect it by influx with command
./influx config create --active -n test_config -u http://localhost:18088 -t test1234 -o test-org --config-path "mypath/.influxdbv2/config"
(becasue i dont have root authority so i have to save my cli config into another path instead of default)
but after I create config and try to view auth list with command
./influx auth list --config-path "mypath/.influxdbv2/config
I got an Error "Error: could not find authorization with given parameters: 401 Unauthorized: unauthorized access"
and see the text below in the influxdb log
2022-09-30T09:02:51.147998Z info Unauthorized {"log_id": "0dFLgdmW000", "error": "authorization not found"}
2022-09-30T09:02:51.148198Z debug Request {"log_id": "0dFLgdmW000", "service": "http", "method": "GET", "host": "localhost:18088", "path": "/api/v2/authorizations", "query": "", "proto": "HTTP/1.1", "status_code": 401, "response_size": 55, "content_length": 0, "referrer": "", "remote": "[::1]:18370", "user_agent": "influx", "took": "0.263ms", "error": "unauthorized", "error_code": "unauthorized", "body": ""}
I tried ./influx with flag -t "test1234" bug get same return and I wonder how can I handle this problem
Could anyone help me :)

Printful Oauth Api Prod. Upload

Description:
Oki, i am trying to upload products to printful via api
|> __ they changed to oauth and the docs are not matching anymore
|> __ the functionality itself is in their docs, but i cant get it to auth
|> __ their dev support was not helpful and i am not a api person
Assets:
=>> https://developers.printful.com/docs/#section/Products-API-examples/Create-a-new-Sync-Product
=>> https://developers.printful.com/docs/#operation/createSyncProduct
Code:
heres my error and code basically directly from their docs:
{"code":200,"result":"Welcome to the Printful API","extra":[]}
{"code":400,"result":"This API endpoint applies only to Printful stores based on the
Manual Order / API platform.
Find out more at Printful API docs.","error":{"reason":"BadRequest","message":
"This API endpoint applies only to Printful stores based on the Manual Order
/ API platform. Find out more at Printful API docs."}}%
# Authorized CURL request with Basic auth
curl -X GET 'https://api.printful.com/' \
-H 'Authorization: Bearer TOKEN'
curl --location --request POST 'https://api.printful.com/store/products' \
-H 'Authorization: Bearer SAMEtOKEN' \
--data-raw '{
"sync_product": {
"name": "T-Shirt",
"thumbnail": "https://picsum.photos/200/300"
},
"sync_variants": [
{
"retail_price": 21.00,
"variant_id": 4011,
"files": [
{
"url": "https://picsum.photos/200/300?image=1"
},
{
"type": "back",
"url": "https://picsum.photos/200/300?image=1"
}
]
},
{
"retail_price": 21.00,
"variant_id": 4012,
"files": [
{
"url": "https://picsum.photos/200/300?image=1"
},
{
"type": "back",
"url": "https://picsum.photos/200/300?image=1"
}
]
}
]
}'
To save anyone else the headache:
The Printful 'Create Product' and similiar API calls don't work with shops created via the automatic API integrations:
As far as I'm aware there is no workaround, but if I find one I'll update here. The name is a bit misleading, as the 'Sync Products' seem to describe products capable of syncing with external services. However you are limited to the ECommerce Platform Sync API calls. It seems to be possible to modify an existing one, but that doesn't help much for GUI-free automation.
Maybe you can you create a number of placeholders as 'Drafts' and modify, but haven't gotten that running myself yet.

What is the supossed scope for translating file format to SFV?

Im going along with the tutorial from:
https://forge.autodesk.com/en/docs/model-derivative/v2/tutorials/prepare-file-for-viewer/
and i got stuck with translating the file to SVF. I've tried data:write, data:create, bucket:update scopes but each time I get:
Token does not have the privilege for this request.
{
"input": {
"urn": "someUrn="
},
"output": {
"formats": [
{
"type": "svf",
"views": [
"2d",
"3d"
]
}
]
}
}
You will need both data:read and (data:write or data:create) (delimited by space) - see doc here:
curl -v 'https://developer.api.autodesk.com/authentication/v1/authenticate'
-X 'POST'
-H 'Content-Type: application/x-www-form-urlencoded'
-d '
client_id=obQDn8P0GanGFQha4ngKKVWcxwyvFAGE&
client_secret=eUruM8HRyc7BAQ1e&
grant_type=client_credentials&
scope=data:read%20data:write
'
And did you select Model Derivative API when creating the Forge app - if not, start over and create the app again:
Thanks,
I've run also with some different translation errors, but it turns out .rfa files are not supported in the Model Derivative API.
But all in all it worked out

ansible uri module with form

Is it possible to run this command with uri module in ansible ?
- shell: unset http_proxy && curl -X POST -H "Cache-Control:no-cache" -F "access_key={{ api_user }}" -F "secret_key={{ api_pass }}" "http://mydomain.bla/api/v1/login_check"
I tried like this:
- uri:
url: http://mydomain.bla/api/v1/login_check
method: POST
user: "{{ api_user }}"
password: "{{ api_pass }}"
environment:
http_proxy: ''
And like this:
- uri:
url: http://mydomain.bla/api/v1/login_check
method: POST
body: "access_key={{ api_user }}&secret_key={{ api_pass }}"
environment:
http_proxy: ''
And still does not work.
I'm trying to get a token and store it in an ansible variable.
"use_proxy: false" or no does not work - that's why I'm using this ugly environment workaround
You forgot to use return_content: yes
From module's docs:
return_content (default: no) – Whether or not to return the body of the request as a "content" key in the dictionary result.
- uri:
url: http://mydomain.bla/api/v1/login_check
method: POST
body: "access_key={{ api_user }}&secret_key={{ api_pass }}"
return_content: yes
register: token_response
environment:
http_proxy: ''
- debug: var=token_response.content

ICINGA2 API Not making host modification

i have problem with the API of ICINGA2.
i'm trying to add new variables with the POST call ,
i'm getting the required result,
But ICINGA2 didn't add the new var.
According to documentation:
http://docs.icinga.org/icinga2/latest/doc/module/icinga2/chapter/icinga2-api
With the following API, i creates all our hosts in vienna :
curl -k -s -u root:icinga -H 'Accept: application/json' -X PUT 'https://localhost:5665/v1/objects/hosts/server.example.com' \
-d '{ "templates": [ "generic-host" ], "attrs": { "zone": "Vienna", "address": "180.33.1.123", "check_command": "hostalive", "vars.os" : "Linux", "vars.agent" : "ssh" } }' \
| python -m json.tool
While this part works as expected,
The problem is once host created, i need to add various vars for different servers.
for example
Adding of the variable: "vars.servicename" : "DHCP_Servers"
If i'm going back to the documentation, the below API that will need to be execute:
curl -k -s -u root:icinga -H 'Accept: application/json' -X POST 'https://localhost:5665/v1/objects/hosts/server.example.com' \
-d '{ "templates": [ "generic-host" ], "attrs": { "zone": "Vienna", "address": "180.33.1.123", "check_command": "hostalive", "vars.os" : "Linux", "vars.agent" : "ssh", "vars.servicename" : "DHCP_Servers" } }' \
| python -m json.tool
When i ran the API , as expected i'm getting back:
{
"results": [
{
"code": 200.0,
"name": "server.example.com",
"status": "Attributes updated.",
"type": "Host"
}
]
}
But there is no changes that taking place on ICINGA/ host file.
Obviously the same user as in my inbox and the forums (https://monitoring-portal.org/index.php?thread/37160-adding-vars-with-api/&postID=234885#post234885) lately. Leaving this as a note here as it might help others to see why it does not work. That feature is just not implemented as it involves storing the applied changes, do a rollback, and re-apply. Not as simple as it sounds.
https://dev.icinga.org/issues/11501