summaryrefslogtreecommitdiffstats
path: root/heat/vFW_CNF_CDS/templates/policy/policy.sh
blob: a09ab0a8c90d200474bfc445671d31b21bfec6b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
51
#!/bin/bash

set -e

check(){
    if ! which curl >/dev/null 2>&1; then
        echo "Fatal error, curl command not available" >&2
        return 1
    fi

    for arg; do
        if ! test -f "$arg"; then
            echo "Fatal error, REST payload - $arg - not found in current directory" >&2
            return 1
        fi
    done
}

query_policy(){
    local mode="$1"
    local content="$2"
    local url="$3"

    declare -a flags=(-kf -H 'Content-Type: application/json'
                      -H 'ClientAuth: cHl0aG9uOnRlc3Q=' -u testpdp:alpha123
                      -H 'Environment: TEST')

    check "$content"

    curl -X "$mode" -d @"$content" "${flags[@]}" "${PDP_URL:-https://pdp:8081}/$url"
}

case "$1" in
    -h|--help|help|?|"")
        echo "Script usage:"
        echo "$0 get|verify - query policy for CNF policy"
        echo "$0 create - Create CNF naming policy and push it"
        echo "$0 update - Update CNF naming policy and push it"
        ;;
    get|verify)
        query_policy POST get.json pdp/api/getConfig
        ;;
    create|update)
        query_policy PUT create.json "pdp/api/$1Policy"
        query_policy PUT push.json "pdp/api/pushPolicy"
        ;;
    *)
        echo "Wrong usage, check '$0 -h'" >&2
        exit 1
        ;;
esac