blob: b48084f10efc7dcfeaf7c56fb2a82039318f3955 [file] [log] [blame]
sg481naaf2df82017-08-03 17:56:38 -04001#!/bin/bash
Fiachra Corcoranfa1da982018-07-26 07:23:34 +01002# ============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
sg481naaf2df82017-08-03 17:56:38 -040010#
Fiachra Corcoranfa1da982018-07-26 07:23:34 +010011# http://www.apache.org/licenses/LICENSE-2.0
sg481naaf2df82017-08-03 17:56:38 -040012#
Fiachra Corcoranfa1da982018-07-26 07:23:34 +010013# 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=========================================================
sg481naaf2df82017-08-03 17:56:38 -040019#
Fiachra Corcoranfa1da982018-07-26 07:23:34 +010020# ECOMP is a trademark and service mark of AT&T Intellectual Property.
21
sg481naaf2df82017-08-03 17:56:38 -040022
23PATH=/opt/app/datartr/bin:/bin:/usr/bin:$PATH
24PROVCMD="$0"
25export PATH PROVSRVR PROVCMD NOPROXY
26
27if [ ! -x /usr/bin/curl ]
28then
29 echo provcmd: curl is required for this tool.
30 exit 1
31fi
32optloop=
33while [ -z "$optloop" ]
34do
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
51done
52if [ -z "$PROVSRVR" ]
53then
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
57fi
58
59CMD="$1"
60shift
61if [ "$CMD" == 'delete' ]
62then
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
72elif [ "$CMD" == 'create' ]
73then
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
82elif [ "$CMD" == 'get' ]
83then
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
91elif [ "$CMD" == 'set' ]
92then
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
106elif [ "$CMD" == 'append' ]
107then
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
116elif [ "$CMD" == 'remove' ]
117then
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
128fi
129
130# Some error somewhere - display usage
131cat <<'EOF'
132usage: 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
139delete - remove the parameters named name1, name2 ...
140get - displays the parameters' value
141create - creates a new parameter
142set - sets the value of an existing parameter
143append - appends the value to a list-based parameter
144remove - removes a value from a list based parameter
145
146server - the provisioning server FQDN (feeds-drtr.web.att.com for production)
147
148Standard Parameters Names:
149------------------------------
150ACTIVE_POD
151DELIVERY_INIT_RETRY_INTERVAL
152DELIVERY_MAX_AGE
153DELIVERY_MAX_RETRY_INTERVAL
154DELIVERY_RETRY_RATIO
155LOGROLL_INTERVAL
156NODES
157PROV_ACTIVE_NAME
158PROV_AUTH_ADDRESSES
159PROV_AUTH_SUBJECTS
160PROV_DOMAIN
161PROV_MAXFEED_COUNT
162PROV_MAXSUB_COUNT
163PROV_NAME
164PROV_REQUIRE_CERT
165PROV_REQUIRE_SECURE
166STANDBY_POD
167EOF
168exit 1