From 9088529a34d07585791105e8f40ab344c8b2c2ac Mon Sep 17 00:00:00 2001 From: Jerome Touffe-Blin Date: Thu, 23 Feb 2017 22:40:49 +1100 Subject: [PATCH] Fix error check --- cmd/iam.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/cmd/iam.go b/cmd/iam.go index ee831387..a357856a 100644 --- a/cmd/iam.go +++ b/cmd/iam.go @@ -40,10 +40,19 @@ func (iam *iam) roleARN(role string) string { func getHash(text string) string { h := fnv.New32a() - h.Write([]byte(text)) + _, err := h.Write([]byte(text)) + if err != nil { + return text + } return fmt.Sprintf("%x", h.Sum32()) } +func sessionName(roleARN, remoteIP string) string { + idx := strings.LastIndex(roleARN, "/") + name := fmt.Sprintf("%s-%s", getHash(remoteIP), roleARN[idx+1:]) + return fmt.Sprintf("%.[2]*[1]s", name, maxSessNameLength) +} + func (iam *iam) assumeRole(roleARN, remoteIP string) (*credentials, error) { item, err := cache.Fetch(roleARN, ttl, func() (interface{}, error) { svc := sts.New(session.New(), &aws.Config{LogLevel: aws.LogLevel(2)}) @@ -72,12 +81,6 @@ func (iam *iam) assumeRole(roleARN, remoteIP string) (*credentials, error) { return item.Value().(*credentials), nil } -func sessionName(roleARN, remoteIP string) string { - idx := strings.LastIndex(roleARN, "/") - name := fmt.Sprintf("%s-%s", getHash(remoteIP), roleARN[idx+1:]) - return fmt.Sprintf("%.[2]*[1]s", name, maxSessNameLength) -} - func newIAM(baseARN string) *iam { return &iam{baseARN: baseARN} }