Jim Hahn | 8f8a6d8 | 2021-04-07 09:32:31 -0400 | [diff] [blame^] | 1 | #!/usr/bin/env sh |
Pamela Dragosh | 0e16acf | 2017-02-14 19:45:48 -0500 | [diff] [blame] | 2 | |
| 3 | ### |
| 4 | # ============LICENSE_START======================================================= |
| 5 | # policy-management |
| 6 | # ================================================================================ |
Jim Hahn | 8f8a6d8 | 2021-04-07 09:32:31 -0400 | [diff] [blame^] | 7 | # Copyright (C) 2017-2021 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|--partition) <partition-count>] " |
| 31 | echo -n "[(-R|--replication) <replication-count>] " |
| 32 | echo "(-t|--topic) <topic> " |
| 33 | echo "" |
Pamela Dragosh | 0e16acf | 2017-02-14 19:45:48 -0500 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | BUS_PORT=3904 |
| 37 | PARTITION_COUNT=1 |
| 38 | REPLICATION_COUNT=1 |
| 39 | |
| 40 | # command line options parsing |
Taka Cho | 8583b51 | 2020-11-12 17:48:30 -0500 | [diff] [blame] | 41 | until [ -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 Dragosh | 0e16acf | 2017-02-14 19:45:48 -0500 | [diff] [blame] | 71 | done |
| 72 | |
Taka Cho | 8583b51 | 2020-11-12 17:48:30 -0500 | [diff] [blame] | 73 | if [ -z "${BUS_HOST}" ]; then |
| 74 | echo "An UEB/DMAAP server must be provided." |
| 75 | echo |
| 76 | usage |
| 77 | exit 1 |
Pamela Dragosh | 0e16acf | 2017-02-14 19:45:48 -0500 | [diff] [blame] | 78 | fi |
| 79 | |
Taka Cho | 8583b51 | 2020-11-12 17:48:30 -0500 | [diff] [blame] | 80 | if [ -z "${API_KEY}" ]; then |
| 81 | echo "The API Key must be provided." |
| 82 | usage |
| 83 | exit 2 |
Pamela Dragosh | 0e16acf | 2017-02-14 19:45:48 -0500 | [diff] [blame] | 84 | fi |
| 85 | |
Taka Cho | 8583b51 | 2020-11-12 17:48:30 -0500 | [diff] [blame] | 86 | if [ -z "${API_SECRET}" ]; then |
| 87 | echo "The API Secret must be provided." |
| 88 | usage |
| 89 | exit 3 |
Pamela Dragosh | 0e16acf | 2017-02-14 19:45:48 -0500 | [diff] [blame] | 90 | fi |
| 91 | |
Taka Cho | 8583b51 | 2020-11-12 17:48:30 -0500 | [diff] [blame] | 92 | if [ -z "${TOPIC}" ]; then |
| 93 | echo "The Topic Name must be provided." |
| 94 | usage |
| 95 | exit 3 |
Pamela Dragosh | 0e16acf | 2017-02-14 19:45:48 -0500 | [diff] [blame] | 96 | fi |
| 97 | |
Taka Cho | 8583b51 | 2020-11-12 17:48:30 -0500 | [diff] [blame] | 98 | if [ -z "${PARTITION_COUNT}" ]; then |
| 99 | echo "The Partition Count must be provided." |
| 100 | usage |
| 101 | exit 4 |
Pamela Dragosh | 0e16acf | 2017-02-14 19:45:48 -0500 | [diff] [blame] | 102 | fi |
| 103 | |
Taka Cho | 8583b51 | 2020-11-12 17:48:30 -0500 | [diff] [blame] | 104 | if [ -z "${REPLICATION_COUNT}" ]; then |
| 105 | echo "The Replication Count must be provided." |
| 106 | usage |
| 107 | exit 5 |
Pamela Dragosh | 0e16acf | 2017-02-14 19:45:48 -0500 | [diff] [blame] | 108 | fi |
| 109 | |
| 110 | REQUEST_API_KEY_BODY=$(< <(cat <<EOF |
| 111 | { |
Taka Cho | 8583b51 | 2020-11-12 17:48:30 -0500 | [diff] [blame] | 112 | "topicName": "${TOPIC}", |
| 113 | "topicDescription": "Generated by PDP-D $(hostname -f)", |
| 114 | "partitionCount": ${PARTITION_COUNT}, |
| 115 | "replicationCount": ${REPLICATION_COUNT} |
Pamela Dragosh | 0e16acf | 2017-02-14 19:45:48 -0500 | [diff] [blame] | 116 | } |
| 117 | EOF |
| 118 | )) |
| 119 | |
| 120 | DATE=$(date) |
| 121 | DATE_HASH=$(echo -n "${DATE}" | openssl sha1 -hmac "${API_SECRET}" -binary | openssl base64) |
| 122 | |
| 123 | unset http_proxy |
| 124 | curl --silent -X POST \ |
Taka Cho | 8583b51 | 2020-11-12 17:48:30 -0500 | [diff] [blame] | 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 |