Skip to content

Commit

Permalink
Fix error check
Browse files Browse the repository at this point in the history
  • Loading branch information
jtblin committed Feb 23, 2017
1 parent 9a46fab commit 9088529
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions cmd/iam.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)})
Expand Down Expand Up @@ -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}
}

0 comments on commit 9088529

Please sign in to comment.