Skip to content

Commit

Permalink
(fix) use custom errors
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie committed Jul 24, 2020
1 parent 9d461ec commit 5e10fee
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
23 changes: 13 additions & 10 deletions internal/aws/client.go
Expand Up @@ -27,6 +27,11 @@ import (
log "github.com/sirupsen/logrus"
)

var (
ErrUserNotFound = errors.New("user no found")
ErrGroupNotFound = errors.New("group not found")
)

// OperationType handle patch operations for add/remove
type OperationType string

Expand All @@ -41,14 +46,14 @@ const (
// IClient represents an interface of methods used
// to communicate with AWS SSO
type Client interface {
FindGroupByDisplayName(string) (*Group, error)
IsUserInGroup(*User, *Group) (bool, error)
FindUserByEmail(string) (*User, error)
CreateUser(*User) (*User, error)
DeleteUser(*User) error
AddUserToGroup(*User, *Group) error
CreateGroup(*Group) (*Group, error)
CreateUser(*User) (*User, error)
DeleteGroup(*Group) error
AddUserToGroup(*User, *Group) error
DeleteUser(*User) error
FindGroupByDisplayName(string) (*Group, error)
FindUserByEmail(string) (*User, error)
IsUserInGroup(*User, *Group) (bool, error)
RemoveUserFromGroup(*User, *Group) error
}

Expand Down Expand Up @@ -256,8 +261,7 @@ func (c *client) FindUserByEmail(email string) (*User, error) {
}

if r.TotalResults != 1 {
err = fmt.Errorf("%s not found in AWS SSO", email)
return nil, err
return nil, ErrUserNotFound
}

return &r.Resources[0], nil
Expand Down Expand Up @@ -290,8 +294,7 @@ func (c *client) FindGroupByDisplayName(name string) (*Group, error) {
}

if r.TotalResults != 1 {
err = fmt.Errorf("%s not found in AWS SSO", name)
return nil, err
return nil, ErrGroupNotFound
}

return &r.Resources[0], nil
Expand Down
10 changes: 7 additions & 3 deletions internal/sync.go
Expand Up @@ -59,8 +59,12 @@ func (s *syncGSuite) SyncUsers() error {
}

for _, u := range deletedUsers {
uu, _ := s.aws.FindUserByEmail(u.PrimaryEmail)
if uu == nil {
uu, err := s.aws.FindUserByEmail(u.PrimaryEmail)
if err != aws.ErrUserNotFound {
return err
}

if err == aws.ErrUserNotFound {
continue
}

Expand Down Expand Up @@ -127,7 +131,7 @@ func (s *syncGSuite) SyncGroups() error {
var group *aws.Group

gg, err := s.aws.FindGroupByDisplayName(g.Name)
if err != nil {
if err != aws.ErrGroupNotFound {
return err
}

Expand Down

0 comments on commit 5e10fee

Please sign in to comment.