Skip to content

Instantly share code, notes, and snippets.

@camilb
Created April 24, 2020 11:58
Show Gist options
  • Select an option

  • Save camilb/f689e90c47ddb1926e1ffcc0a0c4f94d to your computer and use it in GitHub Desktop.

Select an option

Save camilb/f689e90c47ddb1926e1ffcc0a0c4f94d to your computer and use it in GitHub Desktop.

Revisions

  1. camilb created this gist Apr 24, 2020.
    15 changes: 15 additions & 0 deletions upload-tls-from-k8s-secrets-list.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    #!/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