Removing deprecated DMAAP library
[policy/drools-pdp.git] / policy-management / src / main / server-gen / bin / add-secured-participant
1 #!/usr/bin/env sh
2
3 ###
4 # ============LICENSE_START=======================================================
5 # policy-management
6 # ================================================================================
7 # Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved.
8 # Modifications Copyright (C) 2024 Nordix Foundation.
9 # ================================================================================
10 # Licensed under the Apache License, Version 2.0 (the "License");
11 # you may not use this file except in compliance with the License.
12 # You may obtain a copy of the License at
13 #
14 #      http://www.apache.org/licenses/LICENSE-2.0
15 #
16 # Unless required by applicable law or agreed to in writing, software
17 # distributed under the License is distributed on an "AS IS" BASIS,
18 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 # See the License for the specific language governing permissions and
20 # limitations under the License.
21 # ============LICENSE_END=========================================================
22 ###
23
24 function usage() {
25     echo -n "Usage: $(basename $0) "
26     echo -n "[(-d|--debug)] "
27     echo -n "(-h|--host) <bus-host> "
28     echo -n "[(-p|--port) <bus-port>] "
29     echo -n "(-k|--key) <api-key> "
30     echo -n "(-s|--secret) <api-secret> "
31     echo -n "(-P|--producer-key) <producer-key> "
32     echo -n "(-C|--consumer-key) <consumer-key> "
33     echo "(-t|--topic) <topic> "
34 }
35
36 BUS_PORT=3904
37
38 # command line options parsing
39 until [ -z "$1" ]; do
40     case $1 in
41         -d|--debug)     set -x
42              ;;
43         -h|--host)      shift
44              BUS_HOST=$1
45              ;;
46         -p|--port)      shift
47              BUS_PORT=$1
48              ;;
49         -k|--key)       shift
50              API_KEY=$1
51              ;;
52         -s|--secret)    shift
53              API_SECRET=$1
54              ;;
55         -t|--topic)     shift
56              TOPIC=$1
57              ;;
58         -P|--producer-key)     shift
59              URL_CONTEXT="producers"
60              PRODUCER_KEY=$1
61              KEY=$1
62              ;;
63         -C|--consumer-key)     shift
64              URL_CONTEXT="consumers"
65              CONSUMER_KEY=$1
66              KEY=$1
67              ;;
68         *)   usage
69              exit 1
70              ;;
71     esac
72     shift
73 done
74
75 if [ -z "${BUS_HOST}" ]; then
76     echo "An UEB/KAFKA server must be provided."
77     echo
78     usage
79     exit 1
80 fi
81
82 if [ -z "${API_KEY}" ]; then
83     echo "The API Key must be provided."
84     usage
85     exit 2
86 fi
87
88 if [ -z "${API_SECRET}" ]; then
89     echo "The API Secret must be provided."
90     usage
91     exit 3
92 fi
93
94 if [ -z "${TOPIC}" ]; then
95     echo "The Topic Name must be provided."
96     usage
97     exit 3
98 fi
99
100 if [ -z "${PRODUCER_KEY}" ] && [ -z "${CONSUMER_KEY}" ]; then
101     echo "Either the Producer or Consumer options must be provided."
102     usage
103     exit 4
104 fi
105
106 if [ -n "${PRODUCER_KEY}" ] && [ -n "${CONSUMER_KEY}" ]; then
107     echo "Only and only one of the Producer or Consumer options must be provided."
108     usage
109     exit 5
110 fi
111
112
113 DATE=$(date)
114 DATE_HASH=$(echo -n "${DATE}" | openssl sha1 -hmac "${API_SECRET}" -binary | openssl base64)
115
116 unset http_proxy
117 curl --silent -X PUT \
118     --header "Accept:" \
119     --header "X-CambriaDate: ${DATE}" \
120     --header "X-CambriaAuth: ${API_KEY}:${DATE_HASH}" \
121     --header "Content-Type: application/json" \
122     --data "{}" \
123     http://${BUS_HOST}:${BUS_PORT}/topics/${TOPIC}/${URL_CONTEXT}/${KEY}