security_05_subscribe_to_entity_with_token.sh 1.61 KB
Newer Older
1 2 3 4 5 6 7 8 9
#!/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

10 11 12 13 14
[[ -z "$SUBSCRIPTION_URL" ]] &&
    echo "Please set SUBSCRIPTION_URL env var. E.g. export SUBSCRIPTION_URL=http://172.18.1.11:5000/on_change_soilMoistureVwc" &&
    echo "You can check out the wms-example source code for a server implementation example." &&
    exit

15 16 17 18 19
echo "Callback URL for subscriptions is: ${SUBSCRIPTION_URL}"

curl --location --request POST \
    "http://$ORION_HOST:1026/v2/subscriptions/" \
    --header "Fiware-Service: carouge" \
20
    --header "Fiware-ServicePath: /Watering" \
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
    --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
    }'