Alex | f7c7863 | 2021-02-12 16:44:02 -0600 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # files |
Ievgeniia Zadorozhna | c6582cb | 2021-05-13 17:14:31 +0300 | [diff] [blame] | 3 | cd /artifacts |
Alex | f7c7863 | 2021-02-12 16:44:02 -0600 | [diff] [blame] | 4 | ca_crt=$(pwd)/ca.crt |
| 5 | client_crt=$(pwd)/client.crt |
| 6 | client_key=$(pwd)/client.key |
| 7 | |
| 8 | function show_help() { |
| 9 | printf "\ngen_kubespec.sh <kubeconfig.yaml>\n" |
| 10 | exit 1 |
| 11 | } |
| 12 | |
| 13 | # Check for a config file |
| 14 | if [[ -z ${1+x} ]]; then |
| 15 | show_help |
| 16 | printf "\nERROR: No kubeconfig.yaml specified\n" |
| 17 | exit 1 |
| 18 | fi |
| 19 | |
| 20 | # Check if file exists |
| 21 | if [[ ! -f $1 ]]; then |
| 22 | show_help |
| 23 | printf "\nERROR: Supplied kubeconfig file not exists at '$1'\n" |
| 24 | exit 1 |
| 25 | fi |
| 26 | |
| 27 | # extract data as variables |
Alex | 18fc381 | 2021-03-22 09:41:37 -0500 | [diff] [blame] | 28 | declare $(sed -e 's/:[^:\/\/,:443,:6443]/=/g;s/ *=/=/g;s/-/_/g' $1 | grep 'certificate\|key\|server' | tr -d ' ') |
| 29 | echo "# Declared variable: server=$server" |
Alex | f7c7863 | 2021-02-12 16:44:02 -0600 | [diff] [blame] | 30 | |
| 31 | ### Uncomment if separate files needed |
Alex | 18fc381 | 2021-03-22 09:41:37 -0500 | [diff] [blame] | 32 | printf "# Creating 'ca.crt', 'client.crt' and 'client.key'\n" |
Alex | f7c7863 | 2021-02-12 16:44:02 -0600 | [diff] [blame] | 33 | echo "# '${ca_crt}'" |
| 34 | echo $certificate_authority_data | base64 -d >${ca_crt} |
| 35 | echo "# '${client_crt}'" |
| 36 | echo $client_certificate_data | base64 -d >${client_crt} |
| 37 | echo "# '${client_key}'" |
| 38 | echo $client_key_data | base64 -d >${client_key} |
| 39 | |
| 40 | printf "Generating 'kubespec.yaml'\n" |
| 41 | cat << EOF >kubespec_generated.yaml |
| 42 | --- |
| 43 | existing@kubernetes: |
| 44 | server: $server |
| 45 | certificate-authority: ${ca_crt} |
| 46 | client-certificate: ${client_crt} |
| 47 | client-key: ${client_key} |
| 48 | tls_insecure: True |
| 49 | EOF |