Skip to content
This repository has been archived by the owner on Jul 25, 2022. It is now read-only.

aws.go az.go gcloud.go #391

Merged
merged 1 commit into from
Oct 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .ci/test
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,37 @@ fi

cd "${SOURCE_PATH}"



function check() {
if [ $? -eq 0 ]; then
echo "PASS"
else
echo "FAIL"
fi
}

if [ $1x == "local"x ]; then
echo "====aws cli===="
go run cmd/gardenctl/main.go aws -- --version > /dev/null
check
echo "====az cli===="
go run cmd/gardenctl/main.go az -- -h > /dev/null
check
echo "====gcloud cli===="
go run cmd/gardenctl/main.go gcloud -- -v > /dev/null
check

else
# Build the Ginkgo (test framework) binary to be able to execute the tests.
go install -mod=vendor ./vendor/github.com/onsi/ginkgo/ginkgo

###############################################################################

ginkgo -v -progress -cover -r -mod=vendor pkg/...
fi





4 changes: 2 additions & 2 deletions pkg/cmd/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func NewAwsCmd(targetReader TargetReader) *cobra.Command {
fmt.Println("Please go to https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html for how to install aws cli")
os.Exit(2)
}
arguments := "aws " + strings.Join(args[:], " ")
operate("aws", arguments)
arguments := strings.Join(args[:], " ")
fmt.Println(operate("aws", arguments))

return nil
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/az.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func NewAzCmd(targetReader TargetReader) *cobra.Command {
fmt.Println("Please go to https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest for how to install az cli")
os.Exit(2)
}
arguments := "az " + strings.Join(args[:], " ")
operate("az", arguments)
arguments := strings.Join(args[:], " ")
fmt.Println(operate("az", arguments))

return nil
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/gcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func NewGcloudCmd(targetReader TargetReader) *cobra.Command {
os.Exit(2)
}

arguments := "gcloud " + strings.Join(args[:], " ")
operate("gcp", arguments)
arguments := strings.Join(args[:], " ")
fmt.Println(operate("gcp", arguments))

return nil
},
Expand Down
7 changes: 1 addition & 6 deletions pkg/cmd/operate.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,13 @@ func operate(provider, arguments string) string {
accessKeyID := []byte(secret.Data["accessKeyID"])
secretAccessKey := []byte(secret.Data["secretAccessKey"])
args := strings.Fields(arguments)
args = args[1:]
cmd := exec.Command("aws", args...)
newEnv := append(os.Environ(), "AWS_ACCESS_KEY_ID="+string(accessKeyID[:]), "AWS_SECRET_ACCESS_KEY="+string(secretAccessKey[:]), "AWS_DEFAULT_REGION="+region, "AWS_DEFAULT_OUTPUT=text")
cmd.Env = newEnv
out, err = cmd.CombinedOutput()
if err != nil {
log.Fatalf("AWS CLI failed with %s\n%s\n", out, err)
}
fmt.Println(strings.TrimSpace(string(out[:])))

case "gcp":
serviceaccount := []byte(secret.Data["serviceaccount.json"])
Expand Down Expand Up @@ -142,7 +140,6 @@ func operate(provider, arguments string) string {

arguments := arguments + " --account=" + account + " --project=" + project
args := strings.Fields(arguments)
args = args[1:]
cmd := exec.Command("gcloud", args...)
out, err = cmd.CombinedOutput()
if err != nil {
Expand All @@ -153,7 +150,7 @@ func operate(provider, arguments string) string {
if err != nil {
os.Exit(2)
}
fmt.Println(strings.TrimSpace(string(out[:])))

case "az":
clientID := []byte(secret.Data["clientID"])
clientSecret := []byte(secret.Data["clientSecret"])
Expand All @@ -167,13 +164,11 @@ func operate(provider, arguments string) string {

arguments := arguments + " --subscription " + string(subscriptionID[:])
args := strings.Fields(arguments)
args = args[1:]
cmd := exec.Command("az", args...)
out, err = cmd.CombinedOutput()
if err != nil {
log.Fatalf("az CLI failed with %s\n%s\n", out, err)
}
fmt.Println(strings.TrimSpace(string(out[:])))

case "openstack":
authURL := ""
Expand Down