ci(runner): refactor newman command to address commands directly (#1499)

Co-authored-by: Likhin Bopanna <likhin.bopanna@juspay.in>
Co-authored-by: Sanchith Hegde <sanchith.hegde@juspay.in>
This commit is contained in:
Pa1NarK
2023-06-26 17:05:49 +05:30
committed by GitHub
parent 3e284b04b1
commit eec8236de1
8 changed files with 35051 additions and 65 deletions

View File

@ -19,16 +19,23 @@ get_api_keys() {
# [<connector_name>]
# api_key = "HeadKey of <connector_name>"
API_KEY=$(echo "${result}" | awk -F ' = ' '$1 == "api_key" { print $2 }')
KEY1=$(echo "${result}" | awk -F ' = ' '$1 == "key1" { print $2 }')
API_SECRET=$(echo "${result}" | awk -F ' = ' '$1 == "api_secret" { print $2 }')
# Keys are set as variables since some API Keys for connectors such as ACI
# are Base64 encoded and require "Bearer" to be prefixed such as "Bearer Skst45645gey5r#&$==".
# This effectively stops the shell from interpreting the value of the variable as a command.
API_KEY=$(echo "${result}" | awk -F ' = ' '$1 == "api_key" { gsub(/"/, "", $2); print $2 }')
KEY1=$(echo "${result}" | awk -F ' = ' '$1 == "key1" { gsub(/"/, "", $2); print $2 }')
KEY2=$(echo "${result}" | awk -F ' = ' '$1 == "key2" { gsub(/"/, "", $2); print $2 }')
API_SECRET=$(echo "${result}" | awk -F ' = ' '$1 == "api_secret" { gsub(/"/, "", $2); print $2 }')
# Determine the type of key
if [[ -n "${API_KEY}" && -z "${KEY1}" && -z "${API_SECRET}" ]]; then
KEY_TYPE="HeaderKey"
elif [[ -n "${API_KEY}" && -n "{$KEY1}" && -z "${API_SECRET}" ]]; then
elif [[ -n "${API_KEY}" && -n "${KEY1}" && -z "${API_SECRET}" ]]; then
KEY_TYPE="BodyKey"
elif [[ -n "${API_KEY}" && -n "${KEY1}" && -n "${API_SECRET}" ]]; then
KEY_TYPE="SignatureKey"
elif [[ -n "${API_KEY}" && -n "${KEY1}" && -n "${KEY2}" && -n "${API_SECRET}" ]]; then
KEY_TYPE="MultiAuthKey"
else
KEY_TYPE="Invalid"
fi
@ -38,50 +45,22 @@ get_api_keys() {
CONNECTOR_NAME="${1}"
KEY_TYPE=""
API_KEY=""
API_SECRET=""
KEY1=""
# Function call
get_api_keys "${CONNECTOR_NAME}"
COLLECTION_PATH=$(path_generation "${CONNECTOR_NAME}")
get_api_keys "${CONNECTOR_NAME}"
# Run Newman collection
case "$KEY_TYPE" in
"HeaderKey" )
args=(
--env-var "admin_api_key=${ADMIN_API_KEY}"
--env-var "baseUrl=${BASE_URL}"
--env-var "connector_api_key=${API_KEY}"
)
[[ -n "$GATEWAY_MERCHANT_ID" ]] && args+=("--env-var" "gateway_merchant_id=${GATEWAY_MERCHANT_ID}")
[[ -n "$GPAY_CERTIFICATE" ]] && args+=("--env-var" "certificate=${GPAY_CERTIFICATE}")
[[ -n "$GPAY_CERTIFICATE_KEYS" ]] && args+=("--env-var" "certificate_keys=${GPAY_CERTIFICATE_KEYS}")
newman run "${COLLECTION_PATH}" "${args[@]}"
;;
"BodyKey" )
args=(
--env-var "admin_api_key=${ADMIN_API_KEY}"
--env-var "baseUrl=${BASE_URL}"
--env-var "connector_api_key=${API_KEY}"
--env-var "connector_key1=${KEY1}"
)
[[ -n "$GATEWAY_MERCHANT_ID" ]] && args+=("--env-var" "gateway_merchant_id=${GATEWAY_MERCHANT_ID}")
[[ -n "$GPAY_CERTIFICATE" ]] && args+=("--env-var" "certificate=${GPAY_CERTIFICATE}")
[[ -n "$GPAY_CERTIFICATE_KEYS" ]] && args+=("--env-var" "certificate_keys=${GPAY_CERTIFICATE_KEYS}")
newman run "${COLLECTION_PATH}" "${args[@]}"
;;
"SignatureKey" )
args=(
--env-var "admin_api_key=${ADMIN_API_KEY}"
--env-var "baseUrl=${BASE_URL}"
--env-var "connector_api_key=${API_KEY}"
--env-var "connector_api_secret=${API_SECRET}"
--env-var "connector_key1=${KEY1}"
)
[[ -n "$GATEWAY_MERCHANT_ID" ]] && args+=("--env-var" "gateway_merchant_id=${GATEWAY_MERCHANT_ID}")
[[ -n "$GPAY_CERTIFICATE" ]] && args+=("--env-var" "certificate=${GPAY_CERTIFICATE}")
[[ -n "$GPAY_CERTIFICATE_KEYS" ]] && args+=("--env-var" "certificate_keys=${GPAY_CERTIFICATE_KEYS}")
newman run "${COLLECTION_PATH}" "${args[@]}"
;;
esac
# Newman runner
# Depending on the conditions satisfied, variables are added. Since certificates of stripe have already
# been added to the postman collection, those conditions are set to true and collections that have
# variables set up for certificate, will consider those variables and will fail.
newman run "${COLLECTION_PATH}" \
--env-var "admin_api_key=${ADMIN_API_KEY}" \
--env-var "baseUrl=${BASE_URL}" \
--env-var "connector_api_key=${API_KEY}" \
$(if [[ "${KEY_TYPE}" == BodyKey ]]; then echo --env-var "connector_key1=${KEY1}"; fi) \
$(if [[ "${KEY_TYPE}" == SignatureKey ]]; then echo --env-var "connector_key1=${KEY1}" --env-var "connector_api_secret=${API_SECRET}"; fi) \
$(if [[ "${KEY_TYPE}" == MultiAuthKey ]]; then echo --env-var "connector_key1=${KEY1}" --env-var "connector_key2=${KEY2}" --env-var "connector_api_secret=${API_SECRET}"; fi) \
$(if [[ -n "${GATEWAY_MERCHANT_ID}" ]]; then echo --env-var "gateway_merchant_id=${GATEWAY_MERCHANT_ID}"; fi) \
$(if [[ -n "${GPAY_CERTIFICATE}" ]]; then echo --env-var "certificate=${GPAY_CERTIFICATE}"; fi) \
$(if [[ -n "${GPAY_CERTIFICATE_KEYS}" ]]; then echo --env-var "certificate_keys=${GPAY_CERTIFICATE_KEYS}"; fi) \
--delay-request 5