3 # ============LICENSE_START===============================================
5 # ========================================================================
6 # Copyright © 2019 AT&T Intellectual Property. All rights reserved.
7 # Copyright (C) 2021 Nordix Foundation.
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
13 # http://www.apache.org/licenses/LICENSE-2.0
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 # ECOMP is a trademark and service mark of AT&T Intellectual Property.
25 export PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin
27 # RESP_CACHE is (/opt/app/config/cache) empty-dir volume mount for K8s env
28 RESP_CACHE=${RESP_CACHE:-''}
29 RESP=${RESP:-'/dev/null'}
30 APP_ROOT=${APP_ROOT:-/opt/app/dbc-client}
31 CONFIGMAP_ROOT=${CONFIGMAP_ROOT:-/opt/app/config}
36 PARAM=${PARAM:-'useExisting=true'}
37 REQUESTID=${REQUESTID:-dbc-client}
38 URL=${URL:-"${PROTO}"://"${DBC}":"${PORT}"/webapi/}
40 CA_PEM=${CA_PEM:-ca.pem}
41 KEY_PEM=${KEY_PEM:-key.pem}
42 CLIENT_PEM=${CLIENT_PEM:-client.pem}
43 PEM_DIR=${PEM_DIR:-/opt/app/osaaf/local}
44 CERT_PWD=${CERT_PWD:-'2U[iOZzMHI:.#tdCwlBqc;}S'}
46 BA_PWD=${BA_PWD:-'demo123456!'}
47 AUTH_METHOD=${AUTH_METHOD:-basicAuth}
48 BA_IDENTITY=${BA_IDENTITY:-dmaap-bc@dmaap-bc.onap.org}
54 -H "X-ECOMP-RequestID: $REQUESTID" \
55 -H "Content-Type: application/json" "$@"
58 function init_config() {
59 if [ ! -d "$APP_ROOT" -a ! -d "$CONFIGMAP_ROOT" ]; then
60 echo "Expected either App root directory $APP_ROOT Or ConfigMap directory $CONFIGMAP_ROOT does not exist."
64 if [ "$AUTH_METHOD" = "basicAuth" ]; then
65 echo "-u ${BA_IDENTITY}:${BA_PWD}" >"$PEM_DIR"/curl.cred
66 CURL_CRED="-K $PEM_DIR/curl.cred"
67 elif [ -f "$CA_PEM" -a -f "$CLIENT_PEM" -a -f "$KEY_PEM" ]; then
68 printf "key \"$PEM_DIR/$KEY_PEM\"\n cacert \"$PEM_DIR/$CA_PEM\"\n cert \"$PEM_DIR/${CLIENT_PEM}:${CERT_PWD}\"" >$PEM_DIR/curl.cred
69 CURL_CRED="-K $PEM_DIR/curl.cred"
71 echo "PEM files for authorization not found..!"
75 function init_dbc_provisioning() {
77 for dir in dmaap dcaeLocations mr_clusters topics mr_clients dr_nodes feeds dr_pubs dr_subs; do
78 if [ -d ${dir} ]; then
79 for file in $(ls ${dir}/*.json); do
80 do_http_post "$file" "$dir"
86 function do_http_post() {
88 if [ -n "$RESP_CACHE" ]; then
89 RESP="$RESP_CACHE"/"$(echo "${1##*/}" | cut -d "." -f1)"-resp.json
92 if [ "$2" != "feeds" -a "$2" != "topics" ]; then
93 req_body=$(cat "${1}" | envsubst)
94 rc=$(xcurl -o "$RESP" -d "$req_body" "${URL}${2}")
95 if [ "$rc" = "200" -o "$rc" = "201" -o "$rc" = "409" ]; then
96 echo "Http Post request is successful with response code=$rc"
100 rc=$(xcurl -o "$RESP" -d @"${1}" "${URL}${2}"/?"${PARAM}")
101 if [ "$rc" = "200" -o "$rc" = "201" -o "$rc" = "409" ]; then
102 echo "Http Post request for feed creation is successful with response code=$rc"
106 echo "$(date): Http Response code=$rc. Will retry after $RETRY_TIME seconds.."
112 init_dbc_provisioning