blob: 4a776703605524f46c41d9ba58e95a0701491653 [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|--producer-key) <producer-key> "
31 echo -n "(-C|--consumer-key) <consumer-key> "
32 echo "(-t|--topic) <topic> "
Pamela Dragosh0e16acf2017-02-14 19:45:48 -050033}
34
35BUS_PORT=3904
36
37# command line options parsing
Taka Cho8583b512020-11-12 17:48:30 -050038until [ -z "$1" ]; do
39 case $1 in
40 -d|--debug) set -x
41 ;;
42 -h|--host) shift
43 BUS_HOST=$1
44 ;;
45 -p|--port) shift
46 BUS_PORT=$1
47 ;;
48 -k|--key) shift
49 API_KEY=$1
50 ;;
51 -s|--secret) shift
52 API_SECRET=$1
53 ;;
54 -t|--topic) shift
55 TOPIC=$1
56 ;;
57 -P|--producer-key) shift
58 URL_CONTEXT="producers"
59 PRODUCER_KEY=$1
60 KEY=$1
61 ;;
62 -C|--consumer-key) shift
63 URL_CONTEXT="consumers"
64 CONSUMER_KEY=$1
65 KEY=$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
75 echo "An UEB/DMAAP server must be provided."
76 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 "${PRODUCER_KEY}" ] && [ -z "${CONSUMER_KEY}" ]; then
100 echo "Either the Producer or Consumer options 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 [ -n "${PRODUCER_KEY}" ] && [ -n "${CONSUMER_KEY}" ]; then
106 echo "Only and only one of the Producer or Consumer options must be provided."
107 usage
108 exit 5
Pamela Dragosh0e16acf2017-02-14 19:45:48 -0500109fi
110
111
112DATE=$(date)
113DATE_HASH=$(echo -n "${DATE}" | openssl sha1 -hmac "${API_SECRET}" -binary | openssl base64)
114
115unset http_proxy
116curl --silent -X PUT \
Taka Cho8583b512020-11-12 17:48:30 -0500117 --header "Accept:" \
118 --header "X-CambriaDate: ${DATE}" \
119 --header "X-CambriaAuth: ${API_KEY}:${DATE_HASH}" \
120 --header "Content-Type: application/json" \
121 --data "{}" \
122 http://${BUS_HOST}:${BUS_PORT}/topics/${TOPIC}/${URL_CONTEXT}/${KEY}