Skip to content

Commit

Permalink
Replaced calling aws CLI with using the already imported AWS Go SDK. …
Browse files Browse the repository at this point in the history
…Note: Go uses pointers.
  • Loading branch information
Andrew Magana committed May 13, 2020
1 parent a0a6fef commit b413c55
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"log"
"os"
"os/exec"
"strings"
"time"

Expand Down Expand Up @@ -140,15 +139,15 @@ providing credentials for the ALKS Provider`)
}

// make a basic api call to test creds are valid
_, serr := stsconn.GetCallerIdentity(&sts.GetCallerIdentityInput{})
cident, serr := stsconn.GetCallerIdentity(&sts.GetCallerIdentityInput{})

// check for valid creds
if serr != nil {
return nil, serr
}

// check if the user is using a assume-role IAM admin session
if isValidIAM() != true {
if isValidIAM(cident.Arn) != true {
return nil, errors.New("Looks like you are not using ALKS IAM credentials. This will result in errors when creating roles. \n " +
"Note: If using ALKS CLI to get credentials, be sure to use the '-i' flag. \n Please see https://coxautoinc.sharepoint.com/sites/service-internal-tools-team/SitePages/ALKS-Terraform-Provider---Troubleshooting.aspx for more information.")
}
Expand All @@ -175,19 +174,9 @@ func getPluginVersion() string {
return "unknown"
}

func isValidIAM() bool {
arg0 := "aws"
arg1 := "sts"
arg2 := "get-caller-identity"
arg3 := "--query"
arg4 := "[Arn]"
arg5 := "--output"
arg6 := "text"
func isValidIAM(cident *string) bool {

cmd := exec.Command(arg0, arg1, arg2, arg3, arg4, arg5, arg6)
role, _ := cmd.Output()

if strings.Contains(string(role), "assumed-role/Admin/") || strings.Contains(string(role), "assumed-role/IAMAdmin/") {
if strings.Contains(*cident, "assumed-role/Admin/") || strings.Contains(*cident, "assumed-role/IAMAdmin/") {
return true
}

Expand Down

0 comments on commit b413c55

Please sign in to comment.