set -e
BASE64_PATTERN="([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)"
base64_1=`echo 'foo' | base64` # Zm9vCg==
base64_2=`echo 'fooo' | base64` # Zm9vbwo=
base64_3=`echo 'foooo' | base64` # Zm9vb28K
if [[ $base64_1 =~ $BASE64_PATTERN ]]; then
echo "matched base64_1"
fi
if [[ $base64_2 =~ $BASE64_PATTERN ]]; then
echo "matched base64_2"
fi
if [[ $base64_3 =~ $BASE64_PATTERN ]]; then
echo "matched base64_3"
fi
❯ sh test.sh
matched base64_1
matched base64_2
current BASE64_PATTERN doesn't match when = is missing.
How about validating if given string is json or not?
❯ GCP_SA_KEY=`cat gcp_sa_key.json` sh a.sh
Storing GCP_SA_KEY in /opt/gcp_key.json
❯ GCP_SA_KEY=`cat gcp_sa_key.json | base64` sh a.sh
Storing the decoded GCP_SA_KEY in /opt/gcp_key.json
Ref: https://github.com/w9jds/firebase-action/issues/119
current
BASE64_PATTERN
doesn't match when=
is missing. How about validating if given string is json or not?