Removing deprecated DMAAP library
[policy/drools-pdp.git] / policy-management / src / main / server-gen / bin / pdpd-configuration
1 #!/usr/bin/env sh
2
3 # ============LICENSE_START=======================================================
4 # ONAP
5 # ================================================================================
6 # Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved.
7 # Modifications Copyright (C) 2024 Nordix Foundation.
8 # ================================================================================
9 # Licensed under the Apache License, Version 2.0 (the "License");
10 # you may not use this file except in compliance with the License.
11 # You may obtain a copy of the License at
12 #
13 #      http://www.apache.org/licenses/LICENSE-2.0
14 #
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
20 # ============LICENSE_END=========================================================
21
22 source ${POLICY_HOME}/etc/profile.d/env.sh
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 "[(-r|--request-id) <request-id>] "
32     echo -n "(-c|--controller-name) <controller-name> "
33     echo -n "(-o|--operation) <create|update|lock|unlock> "
34     echo -n "[(-g|--group-id) <group-id> "
35     echo -n "(-a|--artifact-id) <artifact-id> "
36     echo -n "(-v|--version) <version>] "
37     echo -n "[(-t|--topic) <topic>] "
38     echo ""
39 }
40
41 BUS_PORT=9092
42 REQUEST_ID="7f5474ca-16a9-42ac-abc0-d86f62296fbc"
43 TOPIC="PDPD-CONFIGURATION"
44
45 # command line options parsing
46 until [ -z "$1" ]; do
47     case $1 in
48         -d|--debug)     set -x
49                 ;;
50         -h|--host)         shift
51                     BUS_HOST=$1
52                     ;;                        
53         -p|--port)         shift
54                     BUS_PORT=$1
55                     ;;
56         -r|--request-id)         shift
57                     REQUEST_ID=$1
58                     ;;
59         -k|--key)         shift
60                     API_KEY=$1
61                     ;;    
62         -s|--secret)         shift
63                     API_SECRET=$1
64                     ;;    
65         -c|--controller-name)         shift
66                     CONTROLLER_NAME=$1
67                     ;;
68         -o|--operation)         shift
69                     OPERATION=$1
70                     ;;                            
71         -g|--group-id)     shift
72                     GROUP_ID=$1
73                     ;;
74         -a|--artifact-id) shift
75                     ARTIFACT_ID=$1
76                     ;;
77         -v|--version) shift
78                     VERSION=$1
79                     ;;        
80         -t|--topic) shift
81                     TOPIC=$1
82                     ;;                                                            
83         *)            usage
84                     exit 1
85                     ;;
86     esac
87     shift
88 done
89
90 if [ -z "${BUS_HOST}" ]; then
91     echo "An UEB/KAFKA server must be provided."
92     echo
93     usage
94     exit 1
95 fi
96
97 if [ -z "${CONTROLLER_NAME}" ]; then
98     echo "The controller-name must be provided."
99     usage
100     exit 2
101 fi
102
103 if [ -z "${OPERATION}" ]; then
104     echo "The operation  must be provided: create|update|lock|unlock"
105     usage
106     exit 3
107 fi
108
109 if [ "${OPERATION}" = "create" ] || [ "${OPERATION}" = "update" ]; then
110     if [ -z "${GROUP_ID}" ]; then
111         echo "The maven group id must be provided when operation is create|update"
112         usage
113         exit 4
114     fi
115     
116     if [ -z "${ARTIFACT_ID}" ]; then
117         echo "The maven artifact id must be provided when operation is create|update"
118         usage
119         exit 5
120     fi
121     
122     if [ -z "${VERSION}" ]; then
123         echo "The maven version must be provided when operation is create|update"
124         usage
125         exit 6
126     fi
127 fi
128
129 UPDATE_BODY=$(cat <<EOF
130 {
131       "requestID": "${REQUEST_ID}",
132       "entity": "controller",
133       "controllers": [{
134             "name": "${CONTROLLER_NAME}",
135             "drools": {
136                   "groupId": "${GROUP_ID}",
137                   "artifactId": "${ARTIFACT_ID}",
138                   "version": "${VERSION}"
139             },
140             "operation": "${OPERATION}"
141       }]
142 }
143 EOF
144 )
145
146 LOCK_BODY=$(cat <<EOF
147 {
148       "requestID": "${REQUEST_ID}",
149       "entity": "controller",
150       "controllers": [{
151             "name": "${CONTROLLER_NAME}",
152             "operation": "${OPERATION}"
153       }]
154 }
155
156 EOF
157 )
158
159 unset http_proxy
160
161 if [ "${OPERATION}" = "lock" ] || [ "${OPERATION}" = "unlock" ]; then
162     if [ -n "${API_KEY}" ]; then
163         DATE=$(date)
164         DATE_HASH=$(echo -n "${DATE}" | openssl sha1 -hmac "${API_SECRET}" -binary | openssl base64)
165         curl --silent -X POST \
166             --header "Accept:" \
167             --header "X-CambriaDate: ${DATE}" \
168             --header "X-CambriaAuth: ${API_KEY}:${DATE_HASH}" \
169             --header "Content-Type: application/json" \
170             --data "${LOCK_BODY}" \
171             http://${BUS_HOST}:${BUS_PORT}/events/${TOPIC}
172     else
173         curl --silent -X POST \
174             --header "Accept:" \
175             --header "Content-Type: application/json" \
176             --data "${LOCK_BODY}" \
177             http://${BUS_HOST}:${BUS_PORT}/events/${TOPIC}
178     fi
179 fi
180
181 if [ "${OPERATION}" = "create" ] || [ "${OPERATION}" = "update" ]; then
182     if [ -n "${API_KEY}" ]; then
183         DATE=$(date)
184         DATE_HASH=$(echo -n "${DATE}" | openssl sha1 -hmac "${API_SECRET}" -binary | openssl base64)
185         curl --silent -X POST \
186             --header "Accept:" \
187             --header "X-CambriaDate: ${DATE}" \
188             --header "X-CambriaAuth: ${API_KEY}:${DATE_HASH}" \
189             --header "Content-Type: application/json" \
190             --data "${UPDATE_BODY}" \
191             http://${BUS_HOST}:${BUS_PORT}/events/${TOPIC}
192     else
193         curl --silent -X POST \
194             --header "Accept:" \
195             --header "Content-Type: application/json" \
196             --data "${UPDATE_BODY}" \
197             http://${BUS_HOST}:${BUS_PORT}/events/${TOPIC}
198     fi
199 fi