blob: 2aed99ae305ef9caf20602da36b1b4b8b73546c5 [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|--partition) <partition-count>] "
32 echo -n "[(-R|--replication) <replication-count>] "
33 echo "(-t|--topic) <topic> "
34 echo ""
Pamela Dragosh0e16acf2017-02-14 19:45:48 -050035}
36
37BUS_PORT=3904
38PARTITION_COUNT=1
39REPLICATION_COUNT=1
40
41# command line options parsing
Taka Cho8583b512020-11-12 17:48:30 -050042until [ -z "$1" ]; do
43 case $1 in
44 -d|--debug) set -x
45 ;;
46 -h|--host) shift
47 BUS_HOST=$1
48 ;;
49 -p|--port) shift
50 BUS_PORT=$1
51 ;;
52 -k|--key) shift
53 API_KEY=$1
54 ;;
55 -s|--secret) shift
56 API_SECRET=$1
57 ;;
58 -t|--topic) shift
59 TOPIC=$1
60 ;;
61 -P|--partition-count) shift
62 PARTITION_COUNT=$1
63 ;;
64 -R|--replication-count) shift
65 REPLICATION_COUNT=$1
66 ;;
67 *) usage
68 exit 1
69 ;;
70 esac
71 shift
Pamela Dragosh0e16acf2017-02-14 19:45:48 -050072done
73
Taka Cho8583b512020-11-12 17:48:30 -050074if [ -z "${BUS_HOST}" ]; then
adheli.tavarescc1d3d32024-01-26 15:28:56 +000075 echo "An UEB/KAFKA server must be provided."
Taka Cho8583b512020-11-12 17:48:30 -050076 echo
77 usage
78 exit 1
Pamela Dragosh0e16acf2017-02-14 19:45:48 -050079fi
80
Taka Cho8583b512020-11-12 17:48:30 -050081if [ -z "${API_KEY}" ]; then
82 echo "The API Key must be provided."
83 usage
84 exit 2
Pamela Dragosh0e16acf2017-02-14 19:45:48 -050085fi
86
Taka Cho8583b512020-11-12 17:48:30 -050087if [ -z "${API_SECRET}" ]; then
88 echo "The API Secret must be provided."
89 usage
90 exit 3
Pamela Dragosh0e16acf2017-02-14 19:45:48 -050091fi
92
Taka Cho8583b512020-11-12 17:48:30 -050093if [ -z "${TOPIC}" ]; then
94 echo "The Topic Name must be provided."
95 usage
96 exit 3
Pamela Dragosh0e16acf2017-02-14 19:45:48 -050097fi
98
Taka Cho8583b512020-11-12 17:48:30 -050099if [ -z "${PARTITION_COUNT}" ]; then
100 echo "The Partition Count must be provided."
101 usage
102 exit 4
Pamela Dragosh0e16acf2017-02-14 19:45:48 -0500103fi
104
Taka Cho8583b512020-11-12 17:48:30 -0500105if [ -z "${REPLICATION_COUNT}" ]; then
106 echo "The Replication Count must be provided."
107 usage
108 exit 5
Pamela Dragosh0e16acf2017-02-14 19:45:48 -0500109fi
110
111REQUEST_API_KEY_BODY=$(< <(cat <<EOF
112{
Taka Cho8583b512020-11-12 17:48:30 -0500113 "topicName": "${TOPIC}",
114 "topicDescription": "Generated by PDP-D $(hostname -f)",
115 "partitionCount": ${PARTITION_COUNT},
116 "replicationCount": ${REPLICATION_COUNT}
Pamela Dragosh0e16acf2017-02-14 19:45:48 -0500117}
118EOF
119))
120
121DATE=$(date)
122DATE_HASH=$(echo -n "${DATE}" | openssl sha1 -hmac "${API_SECRET}" -binary | openssl base64)
123
124unset http_proxy
125curl --silent -X POST \
Taka Cho8583b512020-11-12 17:48:30 -0500126 --header "Accept:" \
127 --header "X-CambriaDate: ${DATE}" \
128 --header "X-CambriaAuth: ${API_KEY}:${DATE_HASH}" \
129 --header "Content-Type: application/json" \
130 --data "${REQUEST_API_KEY_BODY}" \
131 http://${BUS_HOST}:${BUS_PORT}/topics/create