Pamela Dragosh | 0e16acf | 2017-02-14 19:45:48 -0500 | [diff] [blame] | 1 | #! /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 | |
| 23 | function 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|--producer-key) <producer-key> " |
| 31 | echo -n "(-C|--consumer-key) <consumer-key> " |
| 32 | echo "(-t|--topic) <topic> " |
| 33 | } |
| 34 | |
| 35 | BUS_PORT=3904 |
| 36 | |
| 37 | # command line options parsing |
| 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 |
| 72 | done |
| 73 | |
| 74 | if [[ -z ${BUS_HOST} ]]; then |
| 75 | echo "An UEB/DMAAP server must be provided." |
| 76 | echo |
| 77 | usage |
| 78 | exit 1 |
| 79 | fi |
| 80 | |
| 81 | if [[ -z ${API_KEY} ]]; then |
| 82 | echo "The API Key must be provided." |
| 83 | usage |
| 84 | exit 2 |
| 85 | fi |
| 86 | |
| 87 | if [[ -z ${API_SECRET} ]]; then |
| 88 | echo "The API Secret must be provided." |
| 89 | usage |
| 90 | exit 3 |
| 91 | fi |
| 92 | |
| 93 | if [[ -z ${TOPIC} ]]; then |
| 94 | echo "The Topic Name must be provided." |
| 95 | usage |
| 96 | exit 3 |
| 97 | fi |
| 98 | |
| 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 |
| 103 | fi |
| 104 | |
| 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 |
| 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 \ |
| 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} |