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. |
adheli.tavares | cc1d3d3 | 2024-01-26 15:28:56 +0000 | [diff] [blame^] | 8 | # Modifications Copyright (C) 2024 Nordix Foundation. |
Pamela Dragosh | 0e16acf | 2017-02-14 19:45:48 -0500 | [diff] [blame] | 9 | # ================================================================================ |
| 10 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 11 | # you may not use this file except in compliance with the License. |
| 12 | # You may obtain a copy of the License at |
Taka Cho | 8583b51 | 2020-11-12 17:48:30 -0500 | [diff] [blame] | 13 | # |
Pamela Dragosh | 0e16acf | 2017-02-14 19:45:48 -0500 | [diff] [blame] | 14 | # http://www.apache.org/licenses/LICENSE-2.0 |
Taka Cho | 8583b51 | 2020-11-12 17:48:30 -0500 | [diff] [blame] | 15 | # |
Pamela Dragosh | 0e16acf | 2017-02-14 19:45:48 -0500 | [diff] [blame] | 16 | # Unless required by applicable law or agreed to in writing, software |
| 17 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 18 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 19 | # See the License for the specific language governing permissions and |
| 20 | # limitations under the License. |
| 21 | # ============LICENSE_END========================================================= |
| 22 | ### |
| 23 | |
| 24 | function usage() { |
Taka Cho | 8583b51 | 2020-11-12 17:48:30 -0500 | [diff] [blame] | 25 | echo -n "Usage: $(basename $0) " |
| 26 | echo -n "[(-d|--debug)] " |
| 27 | echo -n "(-h|--host) <bus-host> " |
| 28 | echo -n "[(-p|--port) <bus-port>] " |
| 29 | echo -n "(-k|--key) <api-key> " |
| 30 | echo -n "(-s|--secret) <api-secret> " |
| 31 | echo -n "(-P|--producer-key) <producer-key> " |
| 32 | echo -n "(-C|--consumer-key) <consumer-key> " |
| 33 | echo "(-t|--topic) <topic> " |
Pamela Dragosh | 0e16acf | 2017-02-14 19:45:48 -0500 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | BUS_PORT=3904 |
| 37 | |
| 38 | # command line options parsing |
Taka Cho | 8583b51 | 2020-11-12 17:48:30 -0500 | [diff] [blame] | 39 | until [ -z "$1" ]; do |
| 40 | case $1 in |
| 41 | -d|--debug) set -x |
| 42 | ;; |
| 43 | -h|--host) shift |
| 44 | BUS_HOST=$1 |
| 45 | ;; |
| 46 | -p|--port) shift |
| 47 | BUS_PORT=$1 |
| 48 | ;; |
| 49 | -k|--key) shift |
| 50 | API_KEY=$1 |
| 51 | ;; |
| 52 | -s|--secret) shift |
| 53 | API_SECRET=$1 |
| 54 | ;; |
| 55 | -t|--topic) shift |
| 56 | TOPIC=$1 |
| 57 | ;; |
| 58 | -P|--producer-key) shift |
| 59 | URL_CONTEXT="producers" |
| 60 | PRODUCER_KEY=$1 |
| 61 | KEY=$1 |
| 62 | ;; |
| 63 | -C|--consumer-key) shift |
| 64 | URL_CONTEXT="consumers" |
| 65 | CONSUMER_KEY=$1 |
| 66 | KEY=$1 |
| 67 | ;; |
| 68 | *) usage |
| 69 | exit 1 |
| 70 | ;; |
| 71 | esac |
| 72 | shift |
Pamela Dragosh | 0e16acf | 2017-02-14 19:45:48 -0500 | [diff] [blame] | 73 | done |
| 74 | |
Taka Cho | 8583b51 | 2020-11-12 17:48:30 -0500 | [diff] [blame] | 75 | if [ -z "${BUS_HOST}" ]; then |
adheli.tavares | cc1d3d3 | 2024-01-26 15:28:56 +0000 | [diff] [blame^] | 76 | echo "An UEB/KAFKA server must be provided." |
Taka Cho | 8583b51 | 2020-11-12 17:48:30 -0500 | [diff] [blame] | 77 | echo |
| 78 | usage |
| 79 | exit 1 |
Pamela Dragosh | 0e16acf | 2017-02-14 19:45:48 -0500 | [diff] [blame] | 80 | fi |
| 81 | |
Taka Cho | 8583b51 | 2020-11-12 17:48:30 -0500 | [diff] [blame] | 82 | if [ -z "${API_KEY}" ]; then |
| 83 | echo "The API Key must be provided." |
| 84 | usage |
| 85 | exit 2 |
Pamela Dragosh | 0e16acf | 2017-02-14 19:45:48 -0500 | [diff] [blame] | 86 | fi |
| 87 | |
Taka Cho | 8583b51 | 2020-11-12 17:48:30 -0500 | [diff] [blame] | 88 | if [ -z "${API_SECRET}" ]; then |
| 89 | echo "The API Secret must be provided." |
| 90 | usage |
| 91 | exit 3 |
Pamela Dragosh | 0e16acf | 2017-02-14 19:45:48 -0500 | [diff] [blame] | 92 | fi |
| 93 | |
Taka Cho | 8583b51 | 2020-11-12 17:48:30 -0500 | [diff] [blame] | 94 | if [ -z "${TOPIC}" ]; then |
| 95 | echo "The Topic Name must be provided." |
| 96 | usage |
| 97 | exit 3 |
Pamela Dragosh | 0e16acf | 2017-02-14 19:45:48 -0500 | [diff] [blame] | 98 | fi |
| 99 | |
Taka Cho | 8583b51 | 2020-11-12 17:48:30 -0500 | [diff] [blame] | 100 | if [ -z "${PRODUCER_KEY}" ] && [ -z "${CONSUMER_KEY}" ]; then |
| 101 | echo "Either the Producer or Consumer options must be provided." |
| 102 | usage |
| 103 | exit 4 |
Pamela Dragosh | 0e16acf | 2017-02-14 19:45:48 -0500 | [diff] [blame] | 104 | fi |
| 105 | |
Taka Cho | 8583b51 | 2020-11-12 17:48:30 -0500 | [diff] [blame] | 106 | if [ -n "${PRODUCER_KEY}" ] && [ -n "${CONSUMER_KEY}" ]; then |
| 107 | echo "Only and only one of the Producer or Consumer options must be provided." |
| 108 | usage |
| 109 | exit 5 |
Pamela Dragosh | 0e16acf | 2017-02-14 19:45:48 -0500 | [diff] [blame] | 110 | fi |
| 111 | |
| 112 | |
| 113 | DATE=$(date) |
| 114 | DATE_HASH=$(echo -n "${DATE}" | openssl sha1 -hmac "${API_SECRET}" -binary | openssl base64) |
| 115 | |
| 116 | unset http_proxy |
| 117 | curl --silent -X PUT \ |
Taka Cho | 8583b51 | 2020-11-12 17:48:30 -0500 | [diff] [blame] | 118 | --header "Accept:" \ |
| 119 | --header "X-CambriaDate: ${DATE}" \ |
| 120 | --header "X-CambriaAuth: ${API_KEY}:${DATE_HASH}" \ |
| 121 | --header "Content-Type: application/json" \ |
| 122 | --data "{}" \ |
| 123 | http://${BUS_HOST}:${BUS_PORT}/topics/${TOPIC}/${URL_CONTEXT}/${KEY} |