Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Commit

Permalink
make the check a bit more easy to read
Browse files Browse the repository at this point in the history
  • Loading branch information
fionera committed Aug 28, 2020
1 parent bab1b18 commit 039219b
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions cmd/assign/serviceaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"os"
"sync"
"time"
"strings"

"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"google.golang.org/api/googleapi"
gIAM "google.golang.org/api/iam/v1"
"gopkg.in/AlecAivazis/survey.v1"

Expand Down Expand Up @@ -187,14 +187,19 @@ listServiceAccountGroupMembers:
logrus.Debugf("Adding %s to Group", address)
_, err := api.AddMember(adminApi, serviceAccountGroupAddress, address)
if err != nil {
if strings.Contains(err.Error(),"409: Member already exists., duplicate") {
logrus.Info("Account already exists. Skipping.")
time.Sleep(100 * time.Millisecond)
} else {
logrus.Error("An error occurred when adding an account. Retrying...", err)
time.Sleep(100 * time.Millisecond)
goto addMemberToGroup
}
if gerr, ok := err.(*googleapi.Error); ok {
switch gerr.Code {
case 409:
logrus.Info("Account already exists. Skipping.")
time.Sleep(100 * time.Millisecond)
default:
logrus.Error("An error occurred when adding an account. Retrying...", err)
time.Sleep(100 * time.Millisecond)
goto addMemberToGroup
}
} else {
logrus.Fatal("An unknown error occurred: ", err)
}
}
}(address)

Expand Down

0 comments on commit 039219b

Please sign in to comment.