Skip to content

Instantly share code, notes, and snippets.

@camilb
Created April 24, 2020 11:58
Show Gist options
  • Save camilb/f689e90c47ddb1926e1ffcc0a0c4f94d to your computer and use it in GitHub Desktop.
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
#!/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