Taka Cho | 8583b51 | 2020-11-12 17:48:30 -0500 | [diff] [blame^] | 1 | #!/usr/bin/env ash |
Pamela Dragosh | 0e16acf | 2017-02-14 19:45:48 -0500 | [diff] [blame] | 2 | |
| 3 | ### |
| 4 | # ============LICENSE_START======================================================= |
| 5 | # policy-management |
| 6 | # ================================================================================ |
Taka Cho | 8583b51 | 2020-11-12 17:48:30 -0500 | [diff] [blame^] | 7 | # Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. |
Pamela Dragosh | 0e16acf | 2017-02-14 19:45:48 -0500 | [diff] [blame] | 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 |
Taka Cho | 8583b51 | 2020-11-12 17:48:30 -0500 | [diff] [blame^] | 12 | # |
Pamela Dragosh | 0e16acf | 2017-02-14 19:45:48 -0500 | [diff] [blame] | 13 | # http://www.apache.org/licenses/LICENSE-2.0 |
Taka Cho | 8583b51 | 2020-11-12 17:48:30 -0500 | [diff] [blame^] | 14 | # |
Pamela Dragosh | 0e16acf | 2017-02-14 19:45:48 -0500 | [diff] [blame] | 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 | |
| 23 | function usage() { |
Taka Cho | 8583b51 | 2020-11-12 17:48:30 -0500 | [diff] [blame^] | 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|--producer-key) <producer-key> " |
| 31 | echo -n "(-C|--consumer-key) <consumer-key> " |
| 32 | echo "(-t|--topic) <topic> " |
Pamela Dragosh | 0e16acf | 2017-02-14 19:45:48 -0500 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | BUS_PORT=3904 |
| 36 | |
| 37 | # command line options parsing |
Taka Cho | 8583b51 | 2020-11-12 17:48:30 -0500 | [diff] [blame^] | 38 | until [ -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 Dragosh | 0e16acf | 2017-02-14 19:45:48 -0500 | [diff] [blame] | 72 | done |
| 73 | |
Taka Cho | 8583b51 | 2020-11-12 17:48:30 -0500 | [diff] [blame^] | 74 | if [ -z "${BUS_HOST}" ]; then |
| 75 | echo "An UEB/DMAAP server must be provided." |
| 76 | echo |
| 77 | usage |
| 78 | exit 1 |
Pamela Dragosh | 0e16acf | 2017-02-14 19:45:48 -0500 | [diff] [blame] | 79 | fi |
| 80 | |
Taka Cho | 8583b51 | 2020-11-12 17:48:30 -0500 | [diff] [blame^] | 81 | if [ -z "${API_KEY}" ]; then |
| 82 | echo "The API Key must be provided." |
| 83 | usage |
| 84 | exit 2 |
Pamela Dragosh | 0e16acf | 2017-02-14 19:45:48 -0500 | [diff] [blame] | 85 | fi |
| 86 | |
Taka Cho | 8583b51 | 2020-11-12 17:48:30 -0500 | [diff] [blame^] | 87 | if [ -z "${API_SECRET}" ]; then |
| 88 | echo "The API Secret must be provided." |
| 89 | usage |
| 90 | exit 3 |
Pamela Dragosh | 0e16acf | 2017-02-14 19:45:48 -0500 | [diff] [blame] | 91 | fi |
| 92 | |
Taka Cho | 8583b51 | 2020-11-12 17:48:30 -0500 | [diff] [blame^] | 93 | if [ -z "${TOPIC}" ]; then |
| 94 | echo "The Topic Name must be provided." |
| 95 | usage |
| 96 | exit 3 |
Pamela Dragosh | 0e16acf | 2017-02-14 19:45:48 -0500 | [diff] [blame] | 97 | fi |
| 98 | |
Taka Cho | 8583b51 | 2020-11-12 17:48:30 -0500 | [diff] [blame^] | 99 | if [ -z "${PRODUCER_KEY}" ] && [ -z "${CONSUMER_KEY}" ]; then |
| 100 | echo "Either the Producer or Consumer options must be provided." |
| 101 | usage |
| 102 | exit 4 |
Pamela Dragosh | 0e16acf | 2017-02-14 19:45:48 -0500 | [diff] [blame] | 103 | fi |
| 104 | |
Taka Cho | 8583b51 | 2020-11-12 17:48:30 -0500 | [diff] [blame^] | 105 | if [ -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 Dragosh | 0e16acf | 2017-02-14 19:45:48 -0500 | [diff] [blame] | 109 | fi |
| 110 | |
| 111 | |
| 112 | DATE=$(date) |
| 113 | DATE_HASH=$(echo -n "${DATE}" | openssl sha1 -hmac "${API_SECRET}" -binary | openssl base64) |
| 114 | |
| 115 | unset http_proxy |
| 116 | curl --silent -X PUT \ |
Taka Cho | 8583b51 | 2020-11-12 17:48:30 -0500 | [diff] [blame^] | 117 | --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} |