blob: 6e058142f3a9e3d4b4c15d408be7163101b6716b [file] [log] [blame]
Taka Cho8583b512020-11-12 17:48:30 -05001#!/usr/bin/env ash
Pamela Dragosh0e16acf2017-02-14 19:45:48 -05002
3###
4# ============LICENSE_START=======================================================
5# policy-management
6# ================================================================================
Taka Cho8583b512020-11-12 17:48:30 -05007# Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
Pamela Dragosh0e16acf2017-02-14 19:45:48 -05008# ================================================================================
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
Taka Cho8583b512020-11-12 17:48:30 -050012#
Pamela Dragosh0e16acf2017-02-14 19:45:48 -050013# http://www.apache.org/licenses/LICENSE-2.0
Taka Cho8583b512020-11-12 17:48:30 -050014#
Pamela Dragosh0e16acf2017-02-14 19:45:48 -050015# 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
23function usage() {
Taka Cho8583b512020-11-12 17:48:30 -050024 echo -n "Usage: $(basename $0) "
25 echo -n "[(-d|--debug)] "
26 echo -n "(-h|--host) <bus-host> "
27 echo -n "[(-p|--port) <bus-port>] "
28 echo -n "(-k|--key) <api-key> "
29 echo -n "(-s|--secret) <api-secret> "
30 echo -n "[(-P|--partition) <partition-count>] "
31 echo -n "[(-R|--replication) <replication-count>] "
32 echo "(-t|--topic) <topic> "
33 echo ""
Pamela Dragosh0e16acf2017-02-14 19:45:48 -050034}
35
36BUS_PORT=3904
37PARTITION_COUNT=1
38REPLICATION_COUNT=1
39
40# command line options parsing
Taka Cho8583b512020-11-12 17:48:30 -050041until [ -z "$1" ]; do
42 case $1 in
43 -d|--debug) set -x
44 ;;
45 -h|--host) shift
46 BUS_HOST=$1
47 ;;
48 -p|--port) shift
49 BUS_PORT=$1
50 ;;
51 -k|--key) shift
52 API_KEY=$1
53 ;;
54 -s|--secret) shift
55 API_SECRET=$1
56 ;;
57 -t|--topic) shift
58 TOPIC=$1
59 ;;
60 -P|--partition-count) shift
61 PARTITION_COUNT=$1
62 ;;
63 -R|--replication-count) shift
64 REPLICATION_COUNT=$1
65 ;;
66 *) usage
67 exit 1
68 ;;
69 esac
70 shift
Pamela Dragosh0e16acf2017-02-14 19:45:48 -050071done
72
Taka Cho8583b512020-11-12 17:48:30 -050073if [ -z "${BUS_HOST}" ]; then
74 echo "An UEB/DMAAP server must be provided."
75 echo
76 usage
77 exit 1
Pamela Dragosh0e16acf2017-02-14 19:45:48 -050078fi
79
Taka Cho8583b512020-11-12 17:48:30 -050080if [ -z "${API_KEY}" ]; then
81 echo "The API Key must be provided."
82 usage
83 exit 2
Pamela Dragosh0e16acf2017-02-14 19:45:48 -050084fi
85
Taka Cho8583b512020-11-12 17:48:30 -050086if [ -z "${API_SECRET}" ]; then
87 echo "The API Secret must be provided."
88 usage
89 exit 3
Pamela Dragosh0e16acf2017-02-14 19:45:48 -050090fi
91
Taka Cho8583b512020-11-12 17:48:30 -050092if [ -z "${TOPIC}" ]; then
93 echo "The Topic Name must be provided."
94 usage
95 exit 3
Pamela Dragosh0e16acf2017-02-14 19:45:48 -050096fi
97
Taka Cho8583b512020-11-12 17:48:30 -050098if [ -z "${PARTITION_COUNT}" ]; then
99 echo "The Partition Count must be provided."
100 usage
101 exit 4
Pamela Dragosh0e16acf2017-02-14 19:45:48 -0500102fi
103
Taka Cho8583b512020-11-12 17:48:30 -0500104if [ -z "${REPLICATION_COUNT}" ]; then
105 echo "The Replication Count must be provided."
106 usage
107 exit 5
Pamela Dragosh0e16acf2017-02-14 19:45:48 -0500108fi
109
110REQUEST_API_KEY_BODY=$(< <(cat <<EOF
111{
Taka Cho8583b512020-11-12 17:48:30 -0500112 "topicName": "${TOPIC}",
113 "topicDescription": "Generated by PDP-D $(hostname -f)",
114 "partitionCount": ${PARTITION_COUNT},
115 "replicationCount": ${REPLICATION_COUNT}
Pamela Dragosh0e16acf2017-02-14 19:45:48 -0500116}
117EOF
118))
119
120DATE=$(date)
121DATE_HASH=$(echo -n "${DATE}" | openssl sha1 -hmac "${API_SECRET}" -binary | openssl base64)
122
123unset http_proxy
124curl --silent -X POST \
Taka Cho8583b512020-11-12 17:48:30 -0500125 --header "Accept:" \
126 --header "X-CambriaDate: ${DATE}" \
127 --header "X-CambriaAuth: ${API_KEY}:${DATE_HASH}" \
128 --header "Content-Type: application/json" \
129 --data "${REQUEST_API_KEY_BODY}" \
130 http://${BUS_HOST}:${BUS_PORT}/topics/create