provision_key is not coming in kong oauth2 - oauth-2.0

I tried to use kong api manager with oauth2. As per documentation i did api registration in kong and I added oauth2 plugin to that service but provision_key is not came in my response. please help on this
http://10.20.0.151:8001/apis/myservice/plugins
**Request** : name=oauth2
**Response**:
{
"api_id": "df79169c-dcdb-4b3f-98ea-a19d79f5b5f3",
"id": "657b319c-cfb8-44c5-86c9-e2847c6d98db",
"created_at": 1473007130000,
"enabled": true,
"name": "oauth2",
"config": {
"hide_credentials": false,
"mandatory_scope": false,
"enable_password_grant": false,
"token_expiration": 7200,
"accept_http_if_already_terminated": false,
"enable_implicit_grant": false,
"enable_client_credentials": false,
"enable_authorization_code": true
}
}

You can provide your own provision_key in the OAuth2 plugin configuration
$ curl -X POST http://127.0.0.1:8001/apis/{API}/plugins/ -d "name=oauth2" \
-d "config.scopes=email, phone, address" \
-d "config.mandatory_scope=true" \
-d "config.enable_authorization_code=true" \
-d "config.provision_key=987654321ACB"

Related

Dockerize FIWARE can't notify a service

I just started to use FIWARE. I downloaded the latest version on the website (v2) using docker-compose on a PopOs distro.
I'm using Postman to make requests (create the entities and subscriptions) and a Laravel application to listen the notification from the FIWARE subscriptions. But for some reason, today, when I started the docker service and start to send requests: the FIWARE notifications suddenly stopped to work.
When I access the subscriptions endpoint FIWARE returns:
"notification": {
"timesSent": 1,
"lastNotification": "2021-09-02T01:19:39.000Z",
"attrs": [],
"onlyChangedAttrs": false,
"attrsFormat": "keyValues",
"http": {
"url": "http://localhost:8000/api/notifications"
},
"lastFailure": "2021-09-02T01:19:39.000Z",
"lastFailureReason": "Couldn't connect to server"
}
FIWARE can't comunicate, but if I make a POST request using Postman for that endpoint (http://localhost:8000/api/notifications) it returns 200.
There's some aditional configuration between the FIWARE docker container and the local machine? Or I'm doing something wrong?
This is my entity:
// http://{{orion}}/v2/subscription
{
"id": "movie",
"type": "movie",
"name": {
"type": "text",
"value": "movie name"
},
"gender": {
"type": "text",
"value": "drama"
}
}
This is how I'm doing the subscription:
// http://{{orion}}/v2/subscriptions
{
"description": "Notify me about any movie of gender drama",
"subject": {
"entities": [{"idPattern": ".*","type": "movie"}],
"condition": {
"attrs": ["gender"],
"expression": {
"q": "gender==drama"
}
}
},
"notification": {
"http": {
"url": "http://127.0.0.1:8000/api/notifications"
}
}
}
If you are using Docker, then you need to consider what http://localhost:8000/api/notifications actually means. localhost will mean the localhost as experienced by the Orion container itself. Generally Orion listens on 1026 and there is nothing listening on 8000 within a dockerized Orion, therefore your subscription fails.
If you have another micro-service running within the same docker network and in a separate container you must use the hostname of that container (or an alias or defined IP) to describe the notification URL, not localhost.
So for example in the following tutorial where a subscription payload is displayed on screen:
curl -iX POST \
--url 'http://localhost:1026/v2/subscriptions' \
--header 'content-type: application/json' \
--data '{
"description": "Notify me of all product price changes",
"subject": {
"entities": [{"idPattern": ".*", "type": "Product"}],
"condition": {
"attrs": [ "price" ]
}
},
"notification": {
"http": {
"url": "http://tutorial:3000/subscription/price-change"
}
}
}'
refers to a container which is called tutorial within the docker network
tutorial:
image: fiware/tutorials.context-provider
hostname: tutorial
container_name: fiware-tutorial
depends_on:
- orion
networks:
default:
aliases:
- iot-sensors
- context-provider
expose:
- 3000
As it happens the tutorial container is also exposing its internal port 3000 to the localhost of the machine it is running on so it can be viewed by a user, but Orion can only access it via the hostname on the docker network.

IoT Agent plus MQTT - invoking command as a measurement

I'm using IoTAgent over MQTT configuration. After going step by step with the tutorial presented on FIWARE's website is there a way to invoke command using measurment input of the IoT Agent?
Let's say i have 2 arduinos: one is an actuator and the other one is a sensor. The actuator has LED attached, sensor has a button. I want to send a message from sensor-arduino with command ON (to MQTT Broker or directly as an Ultralight message via HTTP - as far as I tested IoTA for Ultralight can run simultaneously both modes which is great) what will invoke sending the command defined for given device.
Let's say im using this config:
curl -iX POST \
'http://localhost:4041/iot/devices' \
-H 'Content-Type: application/json' \
-H 'fiware-service: openiot' \
-H 'fiware-servicepath: /' \
-d '{
"devices": [
{
"device_id": "bell001",
"entity_name": "urn:ngsi-ld:Bell:001",
"entity_type": "Bell",
"protocol": "PDI-IoTA-UltraLight",
"transport": "MQTT",
"commands": [
{ "name": "ring", "type": "command" }
],
"static_attributes": [
{"name":"refStore", "type": "Relationship","value": "urn:ngsi-ld:Store:001"}
]
}
]
}
'
I can invoke command like this (which is very inconvenient):
curl -iX POST \
'http://localhost:4041/v1/updateContext' \
-H 'Content-Type: application/json' \
-H 'fiware-service: openiot' \
-H 'fiware-servicepath: /' \
-d '{
"contextElements": [
{
"type": "Bell",
"isPattern": "false",
"id": "urn:ngsi-ld:Bell:001",
"attributes": [
{ "name": "ring", "type": "command", "value": "" }
],
"static_attributes": [
{"name":"refStore", "type": "Relationship","value": "urn:ngsi-ld:Store:001"}
]
}
],
"updateAction": "UPDATE"
}'
Or after registering the command, I can use Orion Context Broker:
curl -iX PATCH \
'http://localhost:1026/v2/entities/urn:ngsi-ld:Lamp:001/attrs' \
-H 'Content-Type: application/json' \
-H 'fiware-service: openiot' \
-H 'fiware-servicepath: /' \
-d '{
"on": {
"type" : "command",
"value" : ""
}
}'
Those approaches give me a response in Mosquitto subscriber.
How can I create a message sent to IoTAgent (via MQTT or HTTP) that will invoke command sent to MQTT Broker? The command is further managed in actuator-arduino as long as is received in the MQTT Broker.
Using the IoT Agent North Port
I can invoke command like this (which is very inconvenient):
This is a command direct to the North Port of the IoT Agent itself - as the tutorial states it should only be used for testing the connectivity. You should never need to do this yourself - this is the command the Orion Context Broker sends to the IoT Agent
Using NSGI v2
Or after registering the command, I can use Orion Context Broker:
Using the PATCH command is the way to go - pre-registration of commands is not necessary in the more recent releases of the IoT Agent Library.
How to use FIWARE to send Commands to Arduino
How can I create a message sent to IoTAgent (via MQTT or HTTP) that will invoke the command sent to MQTT Broker? The command is further managed in actuator-arduino as long as is received in the MQTT Broker.
The context broker is merely receiving changes of context and informing subscribed services. Within the tutorial an NSGI v2 PATCH request is programmatically sent to the Context Broker using an HTTP request :
https://github.com/FIWARE/tutorials.Step-by-Step/blob/master/context-provider/controllers/ultraLight.js
const options = {
method: 'PATCH',
url: UL_CONTEXT_BROKER + '/entities/' + UL_NGSI_PREFIX + id + '/attrs',
headers: {
'Content-Type': 'application/json',
'fiware-servicepath': '/',
'fiware-service': 'openiot'
},
body: payload,
json: true
};
request(options, error => {
if (error) {
debug(error);
}
});
With a configured IoT Agent the result will be a topic posted to the MQTT broker.
There needs to be some code in the device to ensure it is subscribed to the right topic and then receive the payload.
https://github.com/FIWARE/tutorials.Step-by-Step/blob/master/context-provider/iot.js
const mqtt = require('mqtt');
const apiKey = process.env.DUMMY_DEVICES_API_KEY || '1234';
const topics = '/' + apiKey + '/#';
const mqttBrokerUrl = process.env.MQTT_BROKER_URL || 'mqtt://mosquitto';
global.MQTT_CLIENT = mqtt.connect(mqttBrokerUrl);
MQTT_CLIENT.on('connect', () => {
debug('Subscribing to MQTT Broker: ' + mqttBrokerUrl + ' ' + topics);
MQTT_CLIENT.subscribe(topics);
MQTT_CLIENT.subscribe(topics + '/#');
});
mqtt.connect(mqttBrokerUrl);
MQTT_CLIENT.on('message', function(topic, message) {
// message is Buffer
Ultralight.processMqttMessage(topic.toString(), message.toString());
});

Google speech-to-text API key not valid

I just following the Google-speech-to-text API examples..
reading quickstart guide.
but it has some trouble...
just curl command in this.
I just tried to change the Credential keys ..
but still not working .
just using windows and powershell.
curl -s -H "Content-Type:application/json" -H "Authorization:Bearer "$(gcloud auth application-default print-access-token)
https://speech.googleapis.com/v1/speech:recognize -d #sync-request.json
{
"error": {
"code": 403,
"message": "The request is missing a valid API key.",
"status": "PERMISSION_DENIED"
}
}

Icinga: How to enable maintenance mode through remote api or tool?

I am using Icinga Version 2.4.2 to monitor services on several hosts. I would like to be able to place certain hosts in maintenance mode for a set amount of time using a cli tool or rest API instead of the Web UI.
Is this possible and if so what tool/api should I use?
If I cannot do this through a remote tool/api what command should I use on the server or client to place clients in maintenance mode?
Update: It seems like the rest api has a solution. This set of permissions works:
object ApiUser "root" {
password = "foobar"
permissions = [ "console", "objects/query/Host", "objects/query/Service", "actions/schedule-downtime", "actions/remove-downtime"]
}
Then the following allows me to make and remove downtimes:
curl -k -s -u root:foobar -H 'Accept: application/json' -X POST "https://localhost:5665/v1/actions/schedule-downtime?filter=host.name==%22${TARGET}%22&type=Host" -d '{ "start_time": "1528239116", "end_time": "1528325561", "duration": 1000, "author": "root", "comment": "downtime on $TARGET" }' | jq .
curl -k -s -u root:foobar -H 'Accept: application/json' -X POST "https://localhost:5665/v1/actions/remove-downtime?filter=host.name==%22${TARGET}%22&type=Host" | jq .
Right now the only issue with this I am having is how to pass in variables for the start and stop dates. Attempting this keeps resulting in the following error:
{
"status": "Invalid request body: Error: lexical error: invalid char in json text.\n { \"start_time\": $current_time,\n (right here) ------^\n\n",
"error": 400
}

How to use docker remote api to create container?

I'm new to docker. I have read the tutorial in docker remote API . In aspect of creating container. It show me too many param to fill. I want to know what is equivalent to this command :
docker run -d -p 5000:5000 --restart=always --name registry
registry:2.
I have no idea about it. Can anyone tell me? Thanks!
Original answer (July 2015):
That would be (not tested directly), as in this tutorial (provided the remote API is enabled):
First create the container:
curl -v -X POST -H "Content-Type: application/json" -d '{"Image": " registry:2.",}' http://localhost:2376/containers/create?name=registry
Then start it:
curl -v -X POST -H "Content-Type: application/json" -d '{"PortBindings": { "5000/tcp": [{ "HostPort": "5000" }] },"RestartPolicy": { "Name": "always",},}' http://localhost:2376/containers/registry/start?name=registry
Update February 2017, for docker 1.13+ see rocksteady's answer, using a similar idea but with the current engine/api/v1.26.
More or less just copying VonCs answer in order to update to todays version of docker (1.13) and docker remote api version (v1.26).
What is different:
All the configuration needs to be done when the container is created, otherwise the following error message is returned when starting the container the way VonC did.
{"message":"starting container with non-empty request body was deprecated since v1.10 and removed in v1.12"}
First create the container: (including all the configuration)
curl -v -X POST -H "Content-Type: application/json" -d #docker.conf http://localhost:2376/containers/create?name=registry
The file docker.conf looks like this:
{
"Image": registry:2.",
"ExposedPorts": {
"5000/tcp": {}
},
"HostConfig": {
"PortBindings": {
"5000/tcp": [
{
"HostPort": "5000"
}
]
},
"RestartPolicy": {
"Name": "always"
}
"AutoRemove": true
}
}
Then start it: (the parameter name is not necessary, the container is just named registry)
curl -v -X POST -H "Content-Type: application/json" http://localhost:2376/containers/registry/start
Create docker container in Docker Engine v1.24
Execute the post request -
curl -X POST -H "Content-Type: application/json" http://DOCKER_SERVER_HOST:DOCKER_PORT/v1.24/containers/create?name=containername
In the request body, you can specify the JSON parameters like
{
"Hostname": "172.x.x.x",
"Image": "docker-image-name",
"Volumes": "",
"Entrypoint": "",
"Tty": true
}
It creates your docker container
Start the container
Execute the POST request
curl -X POST http://DOCKER_SERVER_HOST:DOCKER_PORT/v1.24/containers/containername/start
Reference link - https://docs.docker.com/engine/api/v1.24/

Resources