3 # ============LICENSE_START=======================================================
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
13 # http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 source ${POLICY_HOME}/etc/profile.d/env.sh
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>] "
42 REQUEST_ID="7f5474ca-16a9-42ac-abc0-d86f62296fbc"
43 TOPIC="PDPD-CONFIGURATION"
45 # command line options parsing
56 -r|--request-id) shift
65 -c|--controller-name) shift
74 -a|--artifact-id) shift
90 if [ -z "${BUS_HOST}" ]; then
91 echo "An UEB/KAFKA server must be provided."
97 if [ -z "${CONTROLLER_NAME}" ]; then
98 echo "The controller-name must be provided."
103 if [ -z "${OPERATION}" ]; then
104 echo "The operation must be provided: create|update|lock|unlock"
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"
116 if [ -z "${ARTIFACT_ID}" ]; then
117 echo "The maven artifact id must be provided when operation is create|update"
122 if [ -z "${VERSION}" ]; then
123 echo "The maven version must be provided when operation is create|update"
129 UPDATE_BODY=$(cat <<EOF
131 "requestID": "${REQUEST_ID}",
132 "entity": "controller",
134 "name": "${CONTROLLER_NAME}",
136 "groupId": "${GROUP_ID}",
137 "artifactId": "${ARTIFACT_ID}",
138 "version": "${VERSION}"
140 "operation": "${OPERATION}"
146 LOCK_BODY=$(cat <<EOF
148 "requestID": "${REQUEST_ID}",
149 "entity": "controller",
151 "name": "${CONTROLLER_NAME}",
152 "operation": "${OPERATION}"
161 if [ "${OPERATION}" = "lock" ] || [ "${OPERATION}" = "unlock" ]; then
162 if [ -n "${API_KEY}" ]; then
164 DATE_HASH=$(echo -n "${DATE}" | openssl sha1 -hmac "${API_SECRET}" -binary | openssl base64)
165 curl --silent -X POST \
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}
173 curl --silent -X POST \
175 --header "Content-Type: application/json" \
176 --data "${LOCK_BODY}" \
177 http://${BUS_HOST}:${BUS_PORT}/events/${TOPIC}
181 if [ "${OPERATION}" = "create" ] || [ "${OPERATION}" = "update" ]; then
182 if [ -n "${API_KEY}" ]; then
184 DATE_HASH=$(echo -n "${DATE}" | openssl sha1 -hmac "${API_SECRET}" -binary | openssl base64)
185 curl --silent -X POST \
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}
193 curl --silent -X POST \
195 --header "Content-Type: application/json" \
196 --data "${UPDATE_BODY}" \
197 http://${BUS_HOST}:${BUS_PORT}/events/${TOPIC}