Skip to content

Commit

Permalink
get profiles from credentilas path
Browse files Browse the repository at this point in the history
  • Loading branch information
kenzo0107 committed Dec 3, 2019
1 parent a87eb3b commit d4ce53b
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions pkg/utility/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,30 @@ import (
"fmt"
"log"
"os"
"os/user"
"strings"

fuzzyfinder "github.com/ktr0731/go-fuzzyfinder"
)

// GetProfile : return profile selected in .aws/credentials
func GetProfile(defCredentialsPath string) (profile string, err error) {
usr, _ := user.Current()
filePath := strings.Replace(defCredentialsPath, "~", usr.HomeDir, 1)
f, err := os.Open(filePath)
// GetProfiles : return profiles selected in .aws/credentials
func GetProfiles(credentialsPath string) (profiles []string, err error) {
home, err := os.UserHomeDir()
if err != nil {
fmt.Println("error")
return profile, err
log.Println(err)
return profiles, err
}

fpath := strings.Replace(credentialsPath, "~", home, 1)

f, err := os.Open(fpath)
if err != nil {
log.Println(err)
return profiles, err
}
defer f.Close()

reader := bufio.NewReaderSize(f, 4096)

profiles := []string{}
var p string
var t []string
var profileWithAssumeRole string
Expand Down Expand Up @@ -66,16 +70,11 @@ func GetProfile(defCredentialsPath string) (profile string, err error) {
break
}
}

profile, err = finderProfile(profiles)
if err != nil {
log.Fatal(err)
return profile, err
}
return
}

func finderProfile(profiles []string) (profile string, err error) {
// FinderProfile : return profile selected in .aws/credentials
func FinderProfile(profiles []string) (profile string, err error) {
idx, err := fuzzyfinder.FindMulti(
profiles,
func(i int) string {
Expand Down

0 comments on commit d4ce53b

Please sign in to comment.