security_05_subscribe_to_entity_with_token.sh 1.52 KB
Newer Older
1 2 3 4
#!/usr/bin/env bash

# reference doc: https://fiware-tutorials.readthedocs.io/en/latest/pep-proxy/index.html

5 6
[[ -z "$PROXY_HOST" ]] && echo "Please set PROXY_HOST env var. E.g. export PROXY_HOST=127.0.0.1" && exit
echo "Querying Fiware entrypoint (PEP_PROXY) at: ${PROXY_HOST}"
7 8 9

[[ -z "$KEYROCK_TOKEN" ]] && echo "Please set KEYROCK_TOKEN env var. E.g. export KEYROCK_TOKEN=****" && exit

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

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

curl --location --request POST \
18
    "http://$PROXY_HOST:1027/v2/subscriptions/" \
19 20 21 22 23
    --header "Fiware-Service: carouge" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json" \
    --header "X-Auth-Token: $KEYROCK_TOKEN" \
    --data '{
24
      "description": "A subscription to subscribe to FlowerBed.soilMoisture",
25 26 27
      "subject": {
        "entities": [
          {
28
            "id": "urn:ngsi-ld:FlowerBed:FlowerBed-1",
29 30 31 32 33
            "type": "FlowerBed"
          }
        ],
        "condition": {
          "attrs": [
34
            "soilMoisture"
35 36 37 38 39 40 41 42
          ]
        }
      },
      "notification": {
        "http": {
          "url": "'${SUBSCRIPTION_URL}'"
        },
        "attrs": [
43
          "soilMoisture"
44 45 46 47 48 49
        ],
        "attrsFormat": "keyValues"
      },
      "throttling": 5
    }'