blob: 3ddc120facd2958959d53dee34d53a1fef2d597b [file] [log] [blame]
Jim Hahn8f8a6d82021-04-07 09:32:31 -04001#!/usr/bin/env sh
Pamela Dragosh0e16acf2017-02-14 19:45:48 -05002
3###
4# ============LICENSE_START=======================================================
5# policy-management
6# ================================================================================
Jim Hahn8f8a6d82021-04-07 09:32:31 -04007# Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved.
adheli.tavarescc1d3d32024-01-26 15:28:56 +00008# Modifications Copyright (C) 2024 Nordix Foundation.
Pamela Dragosh0e16acf2017-02-14 19:45:48 -05009# ================================================================================
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
Taka Cho8583b512020-11-12 17:48:30 -050013#
Pamela Dragosh0e16acf2017-02-14 19:45:48 -050014# http://www.apache.org/licenses/LICENSE-2.0
Taka Cho8583b512020-11-12 17:48:30 -050015#
Pamela Dragosh0e16acf2017-02-14 19:45:48 -050016# 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
24function usage() {
Taka Cho8583b512020-11-12 17:48:30 -050025 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> "
Pamela Dragosh0e16acf2017-02-14 19:45:48 -050034}
35
36BUS_PORT=3904
37
38# command line options parsing
Taka Cho8583b512020-11-12 17:48:30 -050039until [ -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
Pamela Dragosh0e16acf2017-02-14 19:45:48 -050073done
74
Taka Cho8583b512020-11-12 17:48:30 -050075if [ -z "${BUS_HOST}" ]; then
adheli.tavarescc1d3d32024-01-26 15:28:56 +000076 echo "An UEB/KAFKA server must be provided."
Taka Cho8583b512020-11-12 17:48:30 -050077 echo
78 usage
79 exit 1
Pamela Dragosh0e16acf2017-02-14 19:45:48 -050080fi
81
Taka Cho8583b512020-11-12 17:48:30 -050082if [ -z "${API_KEY}" ]; then
83 echo "The API Key must be provided."
84 usage
85 exit 2
Pamela Dragosh0e16acf2017-02-14 19:45:48 -050086fi
87
Taka Cho8583b512020-11-12 17:48:30 -050088if [ -z "${API_SECRET}" ]; then
89 echo "The API Secret must be provided."
90 usage
91 exit 3
Pamela Dragosh0e16acf2017-02-14 19:45:48 -050092fi
93
Taka Cho8583b512020-11-12 17:48:30 -050094if [ -z "${TOPIC}" ]; then
95 echo "The Topic Name must be provided."
96 usage
97 exit 3
Pamela Dragosh0e16acf2017-02-14 19:45:48 -050098fi
99
Taka Cho8583b512020-11-12 17:48:30 -0500100if [ -z "${PRODUCER_KEY}" ] && [ -z "${CONSUMER_KEY}" ]; then
101 echo "Either the Producer or Consumer options must be provided."
102 usage
103 exit 4
Pamela Dragosh0e16acf2017-02-14 19:45:48 -0500104fi
105
Taka Cho8583b512020-11-12 17:48:30 -0500106if [ -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
Pamela Dragosh0e16acf2017-02-14 19:45:48 -0500110fi
111
112
113DATE=$(date)
114DATE_HASH=$(echo -n "${DATE}" | openssl sha1 -hmac "${API_SECRET}" -binary | openssl base64)
115
116unset http_proxy
117curl --silent -X PUT \
Taka Cho8583b512020-11-12 17:48:30 -0500118 --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}