blob: b0d4d6f263f70f94bad18b36b7d557e75da244da [file] [log] [blame]
Pamela Dragosh0e16acf2017-02-14 19:45:48 -05001#! /bin/bash
2
3###
4# ============LICENSE_START=======================================================
5# policy-management
6# ================================================================================
7# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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
23function usage() {
24 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 ""
34}
35
36BUS_PORT=3904
37PARTITION_COUNT=1
38REPLICATION_COUNT=1
39
40# command line options parsing
41until [[ -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
71done
72
73if [[ -z ${BUS_HOST} ]]; then
74 echo "An UEB/DMAAP server must be provided."
75 echo
76 usage
77 exit 1
78fi
79
80if [[ -z ${API_KEY} ]]; then
81 echo "The API Key must be provided."
82 usage
83 exit 2
84fi
85
86if [[ -z ${API_SECRET} ]]; then
87 echo "The API Secret must be provided."
88 usage
89 exit 3
90fi
91
92if [[ -z ${TOPIC} ]]; then
93 echo "The Topic Name must be provided."
94 usage
95 exit 3
96fi
97
98if [[ -z ${PARTITION_COUNT} ]]; then
99 echo "The Partition Count must be provided."
100 usage
101 exit 4
102fi
103
104if [[ -z ${REPLICATION_COUNT} ]]; then
105 echo "The Replication Count must be provided."
106 usage
107 exit 5
108fi
109
110REQUEST_API_KEY_BODY=$(< <(cat <<EOF
111{
112 "topicName": "${TOPIC}",
113 "topicDescription": "Generated by PDP-D $(hostname -f)",
114 "partitionCount": ${PARTITION_COUNT},
115 "replicationCount": ${REPLICATION_COUNT}
116}
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 \
125 --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