Skip to content

Commit

Permalink
fixed a bug in reading certs from local file system
Browse files Browse the repository at this point in the history
  • Loading branch information
Sami Alajrami committed Nov 26, 2017
1 parent eb59aab commit 6695bf8
Showing 1 changed file with 29 additions and 17 deletions.
46 changes: 29 additions & 17 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"log"
"strings"
)

var s state
Expand Down Expand Up @@ -163,31 +164,42 @@ func createContext() (bool, string) {
return false, "ERROR: aws is not installed/configured correctly. It is needed for downloading certs. Aborting!"
}

cmd := command{
Cmd: "bash",
Args: []string{"-c", "aws s3 cp " + s.Certificates["caCrt"] + " ca.crt"},
Description: "downloading ca.crt from S3.",
}
caCrt := s.Certificates["caCrt"]
caKey := s.Certificates["caKey"]

if exitCode, _ := cmd.exec(debug); exitCode != 0 {
return false, "ERROR: failed to download caCrt."
}
if strings.HasPrefix(s.Certificates["caCrt"], "s3") {
cmd := command{
Cmd: "bash",
Args: []string{"-c", "aws s3 cp " + s.Certificates["caCrt"] + " ca.crt"},
Description: "downloading ca.crt from S3.",
}

cmd = command{
Cmd: "bash",
Args: []string{"-c", "aws s3 cp " + s.Certificates["caKey"] + " ca.key"},
Description: "downloading ca.key from S3.",
if exitCode, _ := cmd.exec(debug); exitCode != 0 {
return false, "ERROR: failed to download caCrt."
}

caCrt = "ca.crt"
}

if exitCode, _ := cmd.exec(debug); exitCode != 0 {
return false, "ERROR: failed to download caKey."
if strings.HasPrefix(s.Certificates["caKey"], "s3") {
cmd := command{
Cmd: "bash",
Args: []string{"-c", "aws s3 cp " + s.Certificates["caKey"] + " ca.key"},
Description: "downloading ca.key from S3.",
}

if exitCode, _ := cmd.exec(debug); exitCode != 0 {
return false, "ERROR: failed to download caKey."
}

caKey = "ca.key"
}

// connecting to the cluster
cmd = command{
cmd := command{
Cmd: "bash",
Args: []string{"-c", "kubectl config set-credentials " + s.Settings["username"] + " --username=" + s.Settings["username"] +
" --password=" + password + " --client-key=ca.key"},
" --password=" + password + " --client-key=" + caKey},
Description: "creating kubectl context - setting credentials.",
}

Expand All @@ -198,7 +210,7 @@ func createContext() (bool, string) {
cmd = command{
Cmd: "bash",
Args: []string{"-c", "kubectl config set-cluster " + s.Settings["kubeContext"] + " --server=" + s.Settings["clusterURI"] +
" --certificate-authority=ca.crt"},
" --certificate-authority=" + caCrt},
Description: "creating kubectl context - setting cluster.",
}

Expand Down

0 comments on commit 6695bf8

Please sign in to comment.