sg481n | aaf2df8 | 2017-08-03 17:56:38 -0400 | [diff] [blame] | 1 | #!/bin/bash |
Fiachra Corcoran | fa1da98 | 2018-07-26 07:23:34 +0100 | [diff] [blame^] | 2 | # ============LICENSE_START======================================================= |
| 3 | # org.onap.dmaap |
| 4 | # ================================================================================ |
| 5 | # Copyright © 2018 AT&T Intellectual Property. All rights reserved. |
| 6 | # ================================================================================ |
| 7 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | # you may not use this file except in compliance with the License. |
| 9 | # You may obtain a copy of the License at |
sg481n | aaf2df8 | 2017-08-03 17:56:38 -0400 | [diff] [blame] | 10 | # |
Fiachra Corcoran | fa1da98 | 2018-07-26 07:23:34 +0100 | [diff] [blame^] | 11 | # http://www.apache.org/licenses/LICENSE-2.0 |
sg481n | aaf2df8 | 2017-08-03 17:56:38 -0400 | [diff] [blame] | 12 | # |
Fiachra Corcoran | fa1da98 | 2018-07-26 07:23:34 +0100 | [diff] [blame^] | 13 | # Unless required by applicable law or agreed to in writing, software |
| 14 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | # See the License for the specific language governing permissions and |
| 17 | # limitations under the License. |
| 18 | # ============LICENSE_END========================================================= |
sg481n | aaf2df8 | 2017-08-03 17:56:38 -0400 | [diff] [blame] | 19 | # |
Fiachra Corcoran | fa1da98 | 2018-07-26 07:23:34 +0100 | [diff] [blame^] | 20 | # ECOMP is a trademark and service mark of AT&T Intellectual Property. |
| 21 | |
sg481n | aaf2df8 | 2017-08-03 17:56:38 -0400 | [diff] [blame] | 22 | |
| 23 | PATH=/opt/app/datartr/bin:/bin:/usr/bin:$PATH |
| 24 | PROVCMD="$0" |
| 25 | export PATH PROVSRVR PROVCMD NOPROXY |
| 26 | |
| 27 | if [ ! -x /usr/bin/curl ] |
| 28 | then |
| 29 | echo provcmd: curl is required for this tool. |
| 30 | exit 1 |
| 31 | fi |
| 32 | optloop= |
| 33 | while [ -z "$optloop" ] |
| 34 | do |
| 35 | if [ "$1" == '-s' ] |
| 36 | then |
| 37 | shift |
| 38 | PROVSRVR="$1" |
| 39 | shift |
| 40 | elif [ "$1" == '-v' ] |
| 41 | then |
| 42 | shift |
| 43 | VERBOSE=x |
| 44 | elif [ "$1" == '-N' ] |
| 45 | then |
| 46 | shift |
| 47 | NOPROXY='?noproxy=1' |
| 48 | else |
| 49 | optloop=1 |
| 50 | fi |
| 51 | done |
| 52 | if [ -z "$PROVSRVR" ] |
| 53 | then |
| 54 | echo "provcmd: you need to specify the server, either via the -s option" |
| 55 | echo " or by setting and exporting PROVSRVR" |
| 56 | exit 1 |
| 57 | fi |
| 58 | |
| 59 | CMD="$1" |
| 60 | shift |
| 61 | if [ "$CMD" == 'delete' ] |
| 62 | then |
| 63 | if [ $# -gt 0 ] |
| 64 | then |
| 65 | for i |
| 66 | do |
| 67 | [ -n "$VERBOSE" ] && echo curl -4 -k -X DELETE "https://$PROVSRVR/internal/api/$1$NOPROXY" |
| 68 | curl -4 -k -X DELETE "https://$PROVSRVR/internal/api/$1$NOPROXY" |
| 69 | done |
| 70 | exit 0 |
| 71 | fi |
| 72 | elif [ "$CMD" == 'create' ] |
| 73 | then |
| 74 | if [ $# -eq 2 ] |
| 75 | then |
| 76 | # create (with POST), then set the value |
| 77 | [ -n "$VERBOSE" ] && echo curl -4 -k -X POST --data '' "https://$PROVSRVR/internal/api/$1$NOPROXY" |
| 78 | curl -4 -k -X POST --data '' "https://$PROVSRVR/internal/api/$1$NOPROXY" |
| 79 | $PROVCMD set "$1" "$2" |
| 80 | exit 0 |
| 81 | fi |
| 82 | elif [ "$CMD" == 'get' ] |
| 83 | then |
| 84 | if [ $# -eq 1 ] |
| 85 | then |
| 86 | # get |
| 87 | [ -n "$VERBOSE" ] && echo curl -4 -k "https://$PROVSRVR/internal/api/$1$NOPROXY" |
| 88 | curl -4 -k "https://$PROVSRVR/internal/api/$1$NOPROXY" 2>/dev/null | tr '|' '\012' | sort |
| 89 | exit 0 |
| 90 | fi |
| 91 | elif [ "$CMD" == 'set' ] |
| 92 | then |
| 93 | if [ $# -ge 2 ] |
| 94 | then |
| 95 | p="$1" |
| 96 | shift |
| 97 | v="" |
| 98 | for i; do [ -n "$v" ] && v="$v|"; v="$v$i"; done |
| 99 | # set (with PUT) |
| 100 | ue=`urlencode "$v"` |
| 101 | NOPROXY=`echo $NOPROXY | tr '?' '&'` |
| 102 | [ -n "$VERBOSE" ] && echo curl -4 -k -X PUT "https://$PROVSRVR/internal/api/$p?val=$ue$NOPROXY" |
| 103 | curl -4 -k -X PUT "https://$PROVSRVR/internal/api/$p?val=$ue$NOPROXY" |
| 104 | exit 0 |
| 105 | fi |
| 106 | elif [ "$CMD" == 'append' ] |
| 107 | then |
| 108 | if [ $# -ge 2 ] |
| 109 | then |
| 110 | p="$1" |
| 111 | shift |
| 112 | tmp=`curl -4 -k "https://$PROVSRVR/internal/api/$p$NOPROXY" 2>/dev/null` |
| 113 | $PROVCMD set "$p" "$tmp" "$@" |
| 114 | exit 0 |
| 115 | fi |
| 116 | elif [ "$CMD" == 'remove' ] |
| 117 | then |
| 118 | if [ $# -eq 2 ] |
| 119 | then |
| 120 | p="$1" |
| 121 | rm="$2" |
| 122 | $PROVCMD get "$p" | grep -v "^$rm\$" > /tmp/pc$$ |
| 123 | IFS=$'\r\n' |
| 124 | $PROVCMD set "$p" `cat /tmp/pc$$` |
| 125 | rm /tmp/pc$$ |
| 126 | exit 0 |
| 127 | fi |
| 128 | fi |
| 129 | |
| 130 | # Some error somewhere - display usage |
| 131 | cat <<'EOF' |
| 132 | usage: provcmd [ -s server ] delete name1 [ name2 ... ] |
| 133 | provcmd [ -s server ] get name |
| 134 | provcmd [ -s server ] create name value |
| 135 | provcmd [ -s server ] set name value1 [ value2 ... ] |
| 136 | provcmd [ -s server ] append name value1 [ value2 ... ] |
| 137 | provcmd [ -s server ] remove name value |
| 138 | |
| 139 | delete - remove the parameters named name1, name2 ... |
| 140 | get - displays the parameters' value |
| 141 | create - creates a new parameter |
| 142 | set - sets the value of an existing parameter |
| 143 | append - appends the value to a list-based parameter |
| 144 | remove - removes a value from a list based parameter |
| 145 | |
| 146 | server - the provisioning server FQDN (feeds-drtr.web.att.com for production) |
| 147 | |
| 148 | Standard Parameters Names: |
| 149 | ------------------------------ |
| 150 | ACTIVE_POD |
| 151 | DELIVERY_INIT_RETRY_INTERVAL |
| 152 | DELIVERY_MAX_AGE |
| 153 | DELIVERY_MAX_RETRY_INTERVAL |
| 154 | DELIVERY_RETRY_RATIO |
| 155 | LOGROLL_INTERVAL |
| 156 | NODES |
| 157 | PROV_ACTIVE_NAME |
| 158 | PROV_AUTH_ADDRESSES |
| 159 | PROV_AUTH_SUBJECTS |
| 160 | PROV_DOMAIN |
| 161 | PROV_MAXFEED_COUNT |
| 162 | PROV_MAXSUB_COUNT |
| 163 | PROV_NAME |
| 164 | PROV_REQUIRE_CERT |
| 165 | PROV_REQUIRE_SECURE |
| 166 | STANDBY_POD |
| 167 | EOF |
| 168 | exit 1 |