Skip to content

Commit

Permalink
Merge pull request #96 from WadeBarnes/fix/webhook-encoding
Browse files Browse the repository at this point in the history
Fix url encoding issue causing webhook message delivery to fail
  • Loading branch information
WadeBarnes authored Dec 28, 2022
2 parents 242a1c3 + 0750013 commit de2889e
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 38 deletions.
2 changes: 0 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ WORKDIR /
# Load the backup scripts into the container (must be executable).
COPY backup.* /

COPY webhook-template.json /

# ========================================================================================================
# Install go-crond (from https://github.com/BCDevOps/go-crond)
# - Adds some additional logging enhancements on top of the upstream project;
Expand Down
2 changes: 0 additions & 2 deletions docker/Dockerfile_MSSQL
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ WORKDIR /
# Load the backup scripts into the container (must be executable).
COPY backup.* /

COPY webhook-template.json /

# ========================================================================================================
# Install go-crond (from https://github.com/BCDevOps/go-crond)
# - Adds some additional logging enhancements on top of the upstream project;
Expand Down
2 changes: 0 additions & 2 deletions docker/Dockerfile_MariaDB
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ WORKDIR /
# Load the backup scripts into the container (must be executable).
COPY backup.* /

COPY webhook-template.json /

# ========================================================================================================
# Install go-crond (from https://github.com/BCDevOps/go-crond)
# - Adds some additional logging enhancements on top of the upstream project;
Expand Down
2 changes: 0 additions & 2 deletions docker/Dockerfile_Mongo
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ WORKDIR /
# Load the backup scripts into the container (must be executable).
COPY backup.* /

COPY webhook-template.json /

# ========================================================================================================
# Install go-crond (from https://github.com/BCDevOps/go-crond)
# - Adds some additional logging enhancements on top of the upstream project;
Expand Down
32 changes: 11 additions & 21 deletions docker/backup.logging
Original file line number Diff line number Diff line change
Expand Up @@ -77,35 +77,25 @@ function logError(){
)
}

function getWebhookPayload(){
_payload=$(eval "cat <<-EOF
$(<${WEBHOOK_TEMPLATE})
EOF
")
echo "${_payload}"
}

function formatWebhookMsg(){
(
# Escape all double quotes
# Escape all newlines
filters='s~"~\\"~g;:a;N;$!ba;s~\n~\\n~g;'
_value=$(echo "${1}" | sed "${filters}")
echo "${_value}"
)
}

function postMsgToWebhook(){
(
if [ -z "${WEBHOOK_URL}" ] && [ -f ${WEBHOOK_TEMPLATE} ]; then
if [ -z "${WEBHOOK_URL}" ]; then
return 0
fi

projectFriendlyName=${1}
projectName=${2}
statusCode=${3}
message=$(formatWebhookMsg "${4}")
curl -s -X POST -H 'Content-Type: application/json' --data "$(getWebhookPayload)" "${WEBHOOK_URL}" > /dev/null
message=$(echo -e "${4}")

curl -s \
-X POST \
-H "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "projectFriendlyName=${projectFriendlyName}" \
--data-urlencode "projectName=${projectName}" \
--data-urlencode "statusCode=${statusCode}" \
--data-urlencode "message=${message}" \
"${WEBHOOK_URL}" > /dev/null
)
}
# =================================================================================================================
3 changes: 0 additions & 3 deletions docker/backup.settings
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ export DAILY_BACKUPS=${DAILY_BACKUPS:-6}
export WEEKLY_BACKUPS=${WEEKLY_BACKUPS:-4}
export MONTHLY_BACKUPS=${MONTHLY_BACKUPS:-1}

# Webhook defaults
WEBHOOK_TEMPLATE=${WEBHOOK_TEMPLATE:-webhook-template.json}

# Modes:
export ONCE="once"
export SCHEDULED="scheduled"
Expand Down
6 changes: 0 additions & 6 deletions docker/webhook-template.json

This file was deleted.

0 comments on commit de2889e

Please sign in to comment.