Created
May 19, 2018 11:48
-
-
Save kiloreux/57977bbdacd3b3a853b29a9ea2d61856 to your computer and use it in GitHub Desktop.
This file contains 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 | |
set -o pipefail | |
set -o errexit | |
set -o nounset | |
# set -o xtrace | |
IFS=$'\n\t' | |
if [[ "$#" -ne 2 || "${1}" == '-h' || "${1}" == '--help' ]]; then | |
cat >&2 <<"EOF" | |
ktravi8s.sh extracts user credentials for you based on username and namespace. | |
USAGE: | |
ktravi8s.sh USER NAMESPACE | |
EXAMPLE | |
ktravi8s.sh travis-echo echo | |
EOF | |
exit 1 | |
fi | |
main(){ | |
USERNAME="${1}" | |
NAMESPACE="${2}" | |
SECRET_NAME=$(kubectl get sa ${USERNAME} --namespace ${NAMESPACE} -o json | jq -r .secrets[].name) | |
CA_CRT=$(kubectl get secret $SECRET_NAME --namespace ${NAMESPACE} -o json | jq -r '.data["ca.crt"]') | |
USER_TOKEN=$(kubectl get secret $SECRET_NAME --namespace ${NAMESPACE} -o json | jq -r '.data["token"]') | |
CONTEXT=`kubectl config current-context` | |
CLUSTER_NAME=`kubectl config get-contexts $CONTEXT | awk '{print $3}' | tail -n 1` | |
CLUSTER_ENDPOINT=`kubectl config view -o jsonpath="{.clusters[?(@.name == \"$CLUSTER_NAME\")].cluster.server}"` | |
echo "The cluster endpoint is: ${CLUSTER_ENDPOINT}" | |
echo "The CA_CRT is: ${CA_CRT}" | |
echo "The USER_TOKEN is: ${USER_TOKEN}" | |
} | |
main "${1}" "${2}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment