Commit 91c2b2ec authored by Federico Sismondi's avatar Federico Sismondi

Merge branch 'authenticated_requests' into 'master'

Authenticated requests

See merge request !2
parents ca913f1f 1afce8da
.idea/
wms-example/__pycache__/
curl --location --request POST 'http://localhost:1026/v2/entities/' \
--header 'Content-Type: application/json' \
--data-raw '{
"id": "urn:ngsi-ld:FlowerBed:FlowerBed-345",
"type": "FlowerBed",
"category": {
"type": "Property",
"value": ["urbanTreeSpot"]
},
"soilMoistureVwc": {
"type": "Property",
"value": 0.85
},
"dateLastWatering": {
"type": "DateTime",
"value": "2020-02-11T08:00:00Z"
},
"soilTemperature": {
"type": "Property",
"value": 17
},
"address": {
"type": "Property",
"value": {
"addressCountry": "Switzerland",
"streetAddress": "Place de Sardaigne",
"adressLocality": "Carouge",
"type": "PostalAddress"
}
},
"location": {
"type": "GeoProperty",
"value": {
"type": "Point",
"coordinates": [46.184255,6.1378375]
}
}
}
'
curl --location --request GET 'http://localhost:1026/v2/entities'
echo "\n\nPretty print:\n"
curl --location --request GET 'http://localhost:1026/v2/entities' | python -mjson.tool
curl --request GET 'http://localhost:1026/v2/entities/urn:ngsi-ld:FlowerBed:FlowerBed-345?options=keyValues' | python -mjson.tool
curl --request GET 'localhost:1026/v2/entities/urn:ngsi-ld:FlowerBed:FlowerBed-345/attrs/soilMoistureVwc/value'
# this gives same results:
#curl --request GET 'localhost:1026/v2/entities/urn:ngsi-ld:FlowerBed:FlowerBed-345/attrs/soilMoistureVwc/value'
curl --request GET 'localhost:1026/v2/entities/urn:ngsi-ld:FlowerBed:FlowerBed-345/attrs/soilMoistureVwc' | python -mjson.tool
curl --request PUT 'localhost:1026/v2/entities/urn:ngsi-ld:FlowerBed:FlowerBed-345/attrs/soilMoistureVwc/value' -d $(( RANDOM % 10 )) --header 'Content-Type: text/plain'
echo "Nothing to do here. WMS-app-example shloud already be running in docker, check log with: <docker-compose logs wms-app-example>"
curl -v localhost:1026/v2/subscriptions/ -s -S --header 'Content-Type: application/json' \
-d @- <<EOF
{
"description": "A subscription to get info about FlowerBed",
"subject": {
"entities": [
{
"id": "urn:ngsi-ld:FlowerBed:FlowerBed-345",
"type": "FlowerBed"
}
],
"condition": {
"attrs": [
"soilMoistureVwc"
]
}
},
"notification": {
"http": {
"url": "http://172.18.1.11:5000/on_change_soilMoistureVwc"
},
"attrs": [
"soilMoistureVwc"
],
"attrsFormat": "keyValues"
},
"expires": "2040-01-01T14:00:00.00Z",
"throttling": 5
}
EOF
curl 'localhost:1026/v2/subscriptions/' | python -mjson.tool
for a more complete explanation of the scripts included here please refer to the [oficial tutorial](https://fiware-orion.readthedocs.io/en/master/user/walkthrough_apiv2/index.html)
Some scripts depend previous execution of other scripts.
Please start by running `watering` scripts before using `security` scripts.
- For a more complete explanation of the scripts included here please refer to the [oficial tutorial](https://fiware-orion.readthedocs.io/en/master/user/walkthrough_apiv2/index.html)
- For those scripts related to security (authentication and authorization),
please refer to the [FIWARE-IDM documentation](https://fiware-idm.readthedocs.io/en/7.4.0/api/)
If any questions dont hesitate to drop me an email to fsismondi@udgalliance.org
#!/usr/bin/env bash
# reference doc: https://fiware-tutorials.readthedocs.io/en/latest/pep-proxy/index.html
[[ -z "$KEYROCK_HOST" ]] && echo "Please set KEYROCK_HOST env var. E.g. export KEYROCK_HOST=127.0.0.1" && exit
echo "Querying Identity Managed (Keyrock) at: ${KEYROCK_HOST}"
curl -iX POST \
"http://$KEYROCK_HOST:3005/oauth2/token" \
-H 'Accept: application/json' \
-H 'Authorization: Basic dHV0b3JpYWwtZGNrci1zaXRlLTAwMDAteHByZXNzd2ViYXBwOnR1dG9yaWFsLWRja3Itc2l0ZS0wMDAwLWNsaWVudHNlY3JldA==' \
-H 'Content-Type: application/x-www-form-urlencoded' \
--data "username=alice-the-admin@test.com&password=test&grant_type=password"
echo
echo
echo "(!) Please export obtained <access_token> as KEYROCK_TOKEN, e.g. 'export KEYROCK_TOKEN=a0926276fc493fb5c423849bbf45cb5d7593dboo'"
echo
#!/usr/bin/env bash
# reference doc: https://fiware-tutorials.readthedocs.io/en/latest/pep-proxy/index.html
[[ -z "$FIWARE_PROXY_HOST" ]] && echo "Please set FIWARE_PROXY_HOST env var. E.g. export FIWARE_PROXY_HOST=127.0.0.1" && exit
echo "Querying Fiware entrypoint (PEP_PROXY) at: ${FIWARE_PROXY_HOST}"
curl -X GET \
"http://$FIWARE_PROXY_HOST:1027/v2/entities/urn:ngsi-ld:FlowerBed:FlowerBed-345/attrs/soilMoistureVwc/value"\
--header "Fiware-Service: carouge" \
--header "Fiware-ServicePath: /watering"
#!/usr/bin/env bash
# reference doc: https://fiware-tutorials.readthedocs.io/en/latest/pep-proxy/index.html
[[ -z "$FIWARE_PROXY_HOST" ]] && echo "Please set FIWARE_PROXY_HOST env var. E.g. export FIWARE_PROXY_HOST=127.0.0.1" && exit
echo "Querying Fiware entrypoint (PEP_PROXY) at: ${FIWARE_PROXY_HOST}"
[[ -z "$KEYROCK_TOKEN" ]] && echo "Please set KEYROCK_TOKEN env var. E.g. export KEYROCK_TOKEN=****" && exit
curl -X GET \
"http://$FIWARE_PROXY_HOST:1027/v2/entities/urn:ngsi-ld:FlowerBed:FlowerBed-345/attrs/soilMoistureVwc/value"\
--header "Fiware-Service: carouge" \
--header "Fiware-ServicePath: /watering" \
--header "X-Auth-Token: $KEYROCK_TOKEN"
#!/usr/bin/env bash
# reference doc: https://fiware-tutorials.readthedocs.io/en/latest/pep-proxy/index.html
[[ -z "$FIWARE_PROXY_HOST" ]] && echo "Please set FIWARE_PROXY_HOST env var. E.g. export FIWARE_PROXY_HOST=127.0.0.1" && exit
echo "Querying Fiware entrypoint (PEP_PROXY) at: ${FIWARE_PROXY_HOST}"
[[ -z "$KEYROCK_TOKEN" ]] && echo "Please set KEYROCK_TOKEN env var. E.g. export KEYROCK_TOKEN=****" && exit
curl --location --request PUT \
"http://$FIWARE_PROXY_HOST:1027/v2/entities/urn:ngsi-ld:FlowerBed:FlowerBed-345/attrs/soilMoistureVwc/value"\
--header "Fiware-Service: carouge" \
--header "Fiware-ServicePath: /watering" \
--header "X-Auth-Token: $KEYROCK_TOKEN" \
--header "Content-Type: text/plain" \
-d $(( RANDOM % 10 ))
#!/usr/bin/env bash
# reference doc: https://fiware-tutorials.readthedocs.io/en/latest/pep-proxy/index.html
[[ -z "$FIWARE_PROXY_HOST" ]] && echo "Please set FIWARE_PROXY_HOST env var. E.g. export FIWARE_PROXY_HOST=127.0.0.1" && exit
echo "Querying Fiware entrypoint (PEP_PROXY) at: ${FIWARE_PROXY_HOST}"
[[ -z "$KEYROCK_TOKEN" ]] && echo "Please set KEYROCK_TOKEN env var. E.g. export KEYROCK_TOKEN=****" && exit
[[ -z "$SUBSCRIPTION_URL" ]] && echo "Please set SUBSCRIPTION_URL env var. E.g. export SUBSCRIPTION_URL=http://172.18.1.11:5000/on_change_soilMoistureVwc" && exit
echo "Callback URL for subscriptions is: ${SUBSCRIPTION_URL}"
curl --location --request POST \
"http://$ORION_HOST:1026/v2/subscriptions/" \
--header "Fiware-Service: carouge" \
--header "Fiware-ServicePath: /watering" \
--header "Content-Type: application/json" \
--header "Accept: application/json" \
--header "X-Auth-Token: $KEYROCK_TOKEN" \
--data '{
"description": "A subscription to subscribe to FlowerBed.soilMoistureVwc",
"subject": {
"entities": [
{
"id": "urn:ngsi-ld:FlowerBed:FlowerBed-345",
"type": "FlowerBed"
}
],
"condition": {
"attrs": [
"soilMoistureVwc"
]
}
},
"notification": {
"http": {
"url": "'${SUBSCRIPTION_URL}'"
},
"attrs": [
"soilMoistureVwc"
],
"attrsFormat": "keyValues"
},
"throttling": 5
}'
#!/bin/sh
[[ -z "$KEYROCK_HOST" ]] && echo "Please set KEYROCK_HOST env var. E.g. export KEYROCK_HOST=127.0.0.1" && exit
echo "Querying Identity Managed (Keyrock) at: ${KEYROCK_HOST}"
[[ -z "$KEYROCK_TOKEN" ]] && echo "Please set KEYROCK_TOKEN env var. E.g. export KEYROCK_TOKEN=****" && exit
curl -iX GET \
"http://$KEYROCK_HOST:3005/v1/oauth2/user?access_token=$KEYROCK_TOKEN" \
--header "X-Auth-Token: $KEYROCK_TOKEN" \
--header "Content-Type: application/json"
#curl -iX GET \
# "http://$KEYROCK_HOST:3005/v1/user?access_token=2YotnFZFEjr1zCsicMWpAA" \
# --header "Content-Type: application/json" \
# --header "Accept: application/json" \
# --data '{
# "name": "alice-the-admin@test.com",
# "password": "test"
# }'
#
#echo
#echo "\n \n (!) Please export obtained X-Subject-Token as KEYROCK_TOKEN env variable (!)"
#echo
#
#
#/user?access_token=2YotnFZFEjr1zCsicMWpAA
#!/bin/sh
[[ -z "$ORION_HOST" ]] && echo "Please set ORION_HOST env var. E.g. export ORION_HOST=127.0.0.1" && exit
echo "Querying context broker at: ${ORION_HOST}"
curl -iX POST \
"http://$ORION_HOST:1026/v2/entities/" \
--header "Fiware-Service: carouge" \
--header "Fiware-ServicePath: /watering" \
--header "Content-Type: application/json" \
--data '{
"id": "urn:ngsi-ld:FlowerBed:FlowerBed-345",
"type": "FlowerBed",
"category": {
"type": "Property",
"value": ["urbanTreeSpot"]
},
"soilMoistureVwc": {
"type": "Property",
"value": 0.85
},
"dateLastWatering": {
"type": "Property",
"value": {
"@type": "DateTime",
"@value": "2020-02-11T08:00:00Z"
}
},
"soilTemperature": {
"type": "Property",
"value": 17
},
"address": {
"type": "Property",
"value": {
"addressCountry": "Switzerland",
"streetAddress": "Place de Sardaigne",
"adressLocality": "Carouge",
"type": "PostalAddress"
}
},
"location": {
"type": "GeoProperty",
"value": {
"type": "Point",
"coordinates": [46.184255,6.1378375]
}
}
}
'
#!/usr/bin/env bash
[[ -z "$ORION_HOST" ]] && echo "Please set ORION_HOST env var. E.g. export ORION_HOST=127.0.0.1" && exit
echo "Querying context broker at: ${ORION_HOST}"
curl --location --request GET \
"http://$ORION_HOST:1026/v2/entities/" \
--header "Fiware-Service: carouge" \
--header "Fiware-ServicePath: /watering" \
| python -mjson.tool
#!/usr/bin/env bash
[[ -z "$ORION_HOST" ]] && echo "Please set ORION_HOST env var. E.g. export ORION_HOST=127.0.0.1" && exit
echo "Querying context broker at: ${ORION_HOST}"
curl --location --request GET \
"http://$ORION_HOST:1026/v2/entities/urn:ngsi-ld:FlowerBed:FlowerBed-345?options=keyValues" \
--header "Fiware-Service: carouge" \
--header "Fiware-ServicePath: /watering" \
| python -mjson.tool
\ No newline at end of file
#!/usr/bin/env bash
[[ -z "$ORION_HOST" ]] && echo "Please set ORION_HOST env var. E.g. export ORION_HOST=127.0.0.1" && exit
echo "Querying context broker at: ${ORION_HOST}"
curl --location --request GET \
"http://$ORION_HOST:1026/v2/entities/urn:ngsi-ld:FlowerBed:FlowerBed-345/attrs/soilMoistureVwc/value" \
--header "Fiware-Service: carouge" \
--header "Fiware-ServicePath: /watering" \
| python -mjson.tool
#curl --location --request GET \
# "http://$ORION_HOST:1026/v2/entities/urn:ngsi-ld:FlowerBed:FlowerBed-345/attrs/location/value" \
# --header "Fiware-Service: carouge" \
# --header "Fiware-ServicePath: /watering" \
# | python -mjson.tool
\ No newline at end of file
#!/usr/bin/env bash
[[ -z "$ORION_HOST" ]] && echo "Please set ORION_HOST env var. E.g. export ORION_HOST=127.0.0.1" && exit
echo "Querying context broker at: ${ORION_HOST}"
curl --location --request GET \
"http://$ORION_HOST:1026/v2/entities/urn:ngsi-ld:FlowerBed:FlowerBed-345/attrs/soilMoistureVwc" \
--header "Fiware-Service: carouge" \
--header "Fiware-ServicePath: /watering" \
| python -mjson.tool
#curl --location --request GET \
# "http://$ORION_HOST:1026/v2/entities/urn:ngsi-ld:FlowerBed:FlowerBed-345/attrs/location" \
# --header "Fiware-Service: carouge" \
# --header "Fiware-ServicePath: /watering" \
# | python -mjson.tool
\ No newline at end of file
#!/usr/bin/env bash
[[ -z "$ORION_HOST" ]] && echo "Please set ORION_HOST env var. E.g. export ORION_HOST=127.0.0.1" && exit
echo "Querying context broker at: ${ORION_HOST}"
curl --location --request PUT \
"http://$ORION_HOST:1026/v2/entities/urn:ngsi-ld:FlowerBed:FlowerBed-345/attrs/soilMoistureVwc/value"\
--header "Fiware-Service: carouge" \
--header "Fiware-ServicePath: /watering" \
--header "Content-Type: text/plain" \
-d $(( RANDOM % 10 ))
#!/usr/bin/env bash
[[ -z "$ORION_HOST" ]] && echo "Please set ORION_HOST env var. E.g. export ORION_HOST=127.0.0.1" && exit
echo "Querying context broker at: ${ORION_HOST}"
[[ -z "$SUBSCRIPTION_URL" ]] && echo "Please set SUBSCRIPTION_URL env var. E.g. export SUBSCRIPTION_URL=http://172.18.1.11:5000/on_change_soilMoistureVwc" && exit
echo "Callback URL for subscriptions is: ${SUBSCRIPTION_URL}"
curl --location --request POST \
"http://$ORION_HOST:1026/v2/subscriptions/" \
--header "Fiware-Service: carouge" \
--header "Fiware-ServicePath: /watering" \
--header "Content-Type: application/json" \
--header "Accept: application/json" \
--data '{
"description": "A subscription to subscribe to FlowerBed.soilMoistureVwc",
"subject": {
"entities": [
{
"id": "urn:ngsi-ld:FlowerBed:FlowerBed-345",
"type": "FlowerBed"
}
],
"condition": {
"attrs": [
"soilMoistureVwc"
]
}
},
"notification": {
"http": {
"url": "'${SUBSCRIPTION_URL}'"
},
"attrs": [
"soilMoistureVwc"
],
"attrsFormat": "keyValues"
},
"throttling": 5
}'
#!/bin/sh
[[ -z "$ORION_HOST" ]] && echo "Please set ORION_HOST env var. E.g. export ORION_HOST=127.0.0.1" && exit
echo "Querying context broker at: ${ORION_HOST}"
curl --location --request GET \
"http://$ORION_HOST:1026/v2/subscriptions/" \
--header "Fiware-Service: carouge" \
--header "Fiware-ServicePath: /watering" \
| python -mjson.tool
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment