Created
April 24, 2020 11:58
-
-
Save camilb/f689e90c47ddb1926e1ffcc0a0c4f94d to your computer and use it in GitHub Desktop.
Send curl POST requests containing TLS certificates from a list of Kubernetes secrets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
while read DOMAIN; do | |
echo "getting certificate for $DOMAIN" | |
CERT=$(kubectl get secret $DOMAIN -o "jsonpath={.data['tls\.crt']}" | base64 --decode | awk 'NF {sub(/\r/, ""); printf "%s\\n",$0;}') | |
KEY=$(kubectl get secret $DOMAIN -o "jsonpath={.data['tls\.key']}" | base64 --decode | awk 'NF {sub(/\r/, ""); printf "%s\\n",$0;}') | |
echo "Uploading certificate for $DOMAIN" | |
curl -X POST -u 'user:pass' --header "Content-Type: application/json" --header "Accept: application/json" "https://some-api.example.com/api/v1/host/$DOMAIN" -d "{ | |
\"type\": \"string\", | |
\"public_certificates\": \"$CERT\", | |
\"private_key\": \"$KEY\" | |
}" | |
done < secrets.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment