+function check_pub_sub() {
+ #Parameters:
+ #${1} Param - String representing dir either dr_pubs or dr_subs
+ #${2} Param - Request details (Dr Publisher/Subscriber creation input details) containing feedName, dr-userName, dr-Password, dr-LocationName
+ #${3} Param - String representing RESP_CACHE Env to '/opt/app/config/cache' or '/dev/null'
+ feed_config_resp="$RESP_CACHE"/"feedConfig-$(echo "${3//[!0-9]/}")-resp.json"
+ if [ -f "${feed_config_resp}" ]; then
+ echo "Checking if pub or sub exist.."
+ val=${1#*_}
+ dr_usr=$(echo "${2}" | jq -r '.username')
+ dr_pwd=$(echo "${2}" | jq -r '.userpwd')
+ pub_sub_cnt=$(jq ".${val} | length" "${feed_config_resp}")
+ local i=0
+ while [ "$i" -lt "$pub_sub_cnt" ]; do
+ _dr_usr=$(jq -r ".${val}[$i].username" "${feed_config_resp}")
+ _dr_pwd=$(jq -r ".${val}[$i].userpwd" "${feed_config_resp}")
+ if [ "${dr_usr}" = "${_dr_usr}" -a "${dr_pwd}" = "${_dr_pwd}" ]; then
+ if [ "${1}" = "dr_pubs" ]; then
+ echo "Publisher exist with username: ${dr_usr}, password: ${dr_pwd}"
+ echo "$(jq -c ".${val}[$i]" "${feed_config_resp}")" >"${3}"
+ IF_PUB_SUB_EXIST=true
+ break
+ elif [ "${1}" = "dr_subs" ]; then
+ dr_loc=$(echo "${2}" | jq -r '.dcaeLocationName')
+ _dr_loc=$(jq -r ".${val}[$i].dcaeLocationName" "${feed_config_resp}")
+ dr_deliveryURL=$(echo "${2}" | jq -r '.deliveryURL')
+ _dr_deliveryURL=$(jq -r ".${val}[$i].deliveryURL" "${feed_config_resp}")
+ if [ "${dr_loc}" = "${_dr_loc}" -a "${dr_deliveryURL}" = "${_dr_deliveryURL}" ]; then
+ echo "Subscriber exist with username: ${dr_usr}, password: ${dr_pwd}, dcaeLocationName: ${dr_loc}, deliveryURL: ${dr_deliveryURL}"
+ echo "$(jq -c ".${val}[$i]" "${feed_config_resp}")" >"${3}"
+ IF_PUB_SUB_EXIST=true
+ break
+ fi
+ fi
+ fi
+ i=$((i + 1))
+ done
+ else
+ echo "Feed configuration doesn't exist."
+ fi
+}