update link to upper-constraints.txt
[dmaap/datarouter.git] / datarouter-prov / src / main / resources / misc / provcmd
1 #!/bin/bash
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
10 #
11 #      http://www.apache.org/licenses/LICENSE-2.0
12 #
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=========================================================
19 #
20 # ECOMP is a trademark and service mark of AT&T Intellectual Property.
21
22 urlencode() {
23     local data
24     if [[ $# != 1 ]]; then
25         echo "Usage: $0 string-to-urlencode"
26         return 1
27     fi
28     data="$(curl -s -o /dev/null -w %url_effective --get --data-urlencode "$1" "")"
29     if [[ $? != 3 ]]; then
30         echo "Unexpected error" 1>&2
31         return 2
32     fi
33     echo "${data##/?}"
34     return 0
35 }
36 export urlencode
37
38 PATH=/opt/app/datartr/bin:/bin:/usr/bin:$PATH
39 PROVCMD="$0"
40 export PATH PROVSRVR PROVCMD NOPROXY
41
42 if [ ! -x /usr/bin/curl ]
43 then
44     echo provcmd: curl is required for this tool.
45     exit 1
46 fi
47 optloop=
48 while [ -z "$optloop" ]
49 do
50     if [ "$1" == '-s' ]
51     then
52         shift
53         PROVSRVR="$1"
54         shift
55     elif [ "$1" == '-v' ]
56     then
57         shift
58         VERBOSE=x
59     elif [ "$1" == '-N' ]
60     then
61         shift
62         NOPROXY='?noproxy=1'
63     else
64         optloop=1
65     fi
66 done
67 if [ -z "$PROVSRVR" ]
68 then
69     echo "provcmd: you need to specify the server, either via the -s option"
70     echo "         or by setting and exporting PROVSRVR"
71     exit 1
72 fi
73
74 CMD="$1"
75 shift
76 if [ "$CMD" == 'delete' ]
77 then
78     if [ $# -gt 0 ]
79     then
80         for i
81         do
82             [ -n "$VERBOSE" ] && echo curl -4 -k -X DELETE "https://$PROVSRVR/internal/api/$1$NOPROXY"
83             curl -4 -k -X DELETE "https://$PROVSRVR/internal/api/$1$NOPROXY"
84         done
85         exit 0
86     fi
87 elif [ "$CMD" == 'create' ]
88 then
89     if [ $# -eq 2 ]
90     then
91         # create (with POST), then set the value
92         [ -n "$VERBOSE" ] && echo curl -4 -k -X POST --data '' "https://$PROVSRVR/internal/api/$1$NOPROXY"
93         curl -4 -k -X POST --data '' "https://$PROVSRVR/internal/api/$1$NOPROXY"
94         $PROVCMD set "$1" "$2"
95         exit 0
96     fi
97 elif [ "$CMD" == 'get' ]
98 then
99     if [ $# -eq 1 ]
100     then
101         # get
102         [ -n "$VERBOSE" ] && echo curl -4 -k "https://$PROVSRVR/internal/api/$1$NOPROXY"
103         curl -4 -k "https://$PROVSRVR/internal/api/$1$NOPROXY" 2>/dev/null | tr '|' '\012' | sort
104         exit 0
105     fi
106 elif [ "$CMD" == 'set' ]
107 then
108     if [ $# -ge 2 ]
109     then
110         p="$1"
111         shift
112         v=""
113         for i; do [ -n "$v" ] && v="$v|"; v="$v$i"; done
114         # set (with PUT)
115         ue=`urlencode "$v"`
116         NOPROXY=`echo $NOPROXY | tr '?' '&'`
117         [ -n "$VERBOSE" ] && echo curl -4 -k -X PUT "https://$PROVSRVR/internal/api/$p?val=$ue$NOPROXY"
118         curl -4 -k -X PUT "https://$PROVSRVR/internal/api/$p?val=$ue$NOPROXY"
119         exit 0
120     fi
121 elif [ "$CMD" == 'append' ]
122 then
123     if [ $# -ge 2 ]
124     then
125         p="$1"
126         shift
127         tmp=`curl -4 -k "https://$PROVSRVR/internal/api/$p$NOPROXY" 2>/dev/null`
128         $PROVCMD set "$p" "$tmp" "$@"
129         exit 0
130     fi
131 elif [ "$CMD" == 'remove' ]
132 then
133     if [ $# -eq 2 ]
134     then
135         p="$1"
136         rm="$2"
137         $PROVCMD get "$p" | grep -v "^$rm\$" > /tmp/pc$$
138         IFS=$'\r\n'
139         $PROVCMD set "$p" `cat /tmp/pc$$`
140         rm /tmp/pc$$
141         exit 0
142     fi
143 fi
144
145 # Some error somewhere - display usage
146 cat <<'EOF'
147 usage: provcmd [ -s server ] delete name1 [ name2 ... ]
148        provcmd [ -s server ] get name
149        provcmd [ -s server ] create name value
150        provcmd [ -s server ] set name value1 [ value2 ... ]
151        provcmd [ -s server ] append name value1 [ value2 ... ]
152        provcmd [ -s server ] remove name value
153
154 delete - remove the parameters named name1, name2 ...
155 get    - displays the parameters' value
156 create - creates a new parameter
157 set    - sets the value of an existing parameter
158 append - appends the value to a list-based parameter
159 remove - removes a value from a list based parameter
160
161 server - the provisioning server FQDN (feeds-drtr.web.att.com for production)
162
163 Standard Parameters Names:
164 ------------------------------
165 ACTIVE_POD
166 DELIVERY_INIT_RETRY_INTERVAL
167 DELIVERY_MAX_AGE
168 DELIVERY_MAX_RETRY_INTERVAL
169 DELIVERY_RETRY_RATIO
170 LOGROLL_INTERVAL
171 NODES
172 PROV_ACTIVE_NAME
173 PROV_AUTH_ADDRESSES
174 PROV_AUTH_SUBJECTS
175 PROV_DOMAIN
176 PROV_MAXFEED_COUNT
177 PROV_MAXSUB_COUNT
178 PROV_NAME
179 PROV_REQUIRE_CERT
180 PROV_REQUIRE_SECURE
181 STANDBY_POD
182 EOF
183 exit 1