Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix improve connection test #174

Merged
merged 2 commits into from
Mar 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions internal/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@
log.Info("creating user")
_, err := s.aws.CreateUser(awsUser)
if err != nil {
errHttp := new(aws.ErrHttpNotOK)

Check failure on line 407 in internal/sync.go

View workflow job for this annotation

GitHub Actions / test

var errHttp should be errHTTP
if errors.As(err, &errHttp) && errHttp.StatusCode == 409 {
log.WithField("user", awsUser.Username).Warn("user already exists")
continue
Expand Down Expand Up @@ -721,6 +721,7 @@

googleClient, err := google.NewClient(ctx, cfg.GoogleAdmin, creds)
if err != nil {
log.WithField("error", err).Warn("Problem establising a connection to Google directory")
return err
}

Expand All @@ -731,6 +732,7 @@
Token: cfg.SCIMAccessToken,
})
if err != nil {
log.WithField("error", err).Warn("Problem establising a SCIM connection to AWS IAM Identity Center")
return err
}

Expand All @@ -741,12 +743,24 @@
})

if err != nil {
log.WithField("error", err).Warn("Problem establising a session for Identity Store")
return err
}

// Initialize AWS Identity Store Public API Client with session
identityStoreClient := identitystore.New(sess)

response, err := identityStoreClient.ListGroups(
&identitystore.ListGroupsInput{IdentityStoreId: &cfg.IdentityStoreID})

if err != nil {
log.WithField("error", err).Warn("Problem performing test query against Identity Store")
return err
} else {

Check failure on line 759 in internal/sync.go

View workflow job for this annotation

GitHub Actions / test

if block ends with a return statement, so drop this else and outdent its block
log.WithField("Groups", response).Info("Test call for groups successful")

}

// Initialize sync client with
// 1. SCIM API client
// 2. Google Directory API client
Expand Down Expand Up @@ -821,7 +835,7 @@
return awsGroups, nil
}

func ListGroupsPagesCallbackFn(page *identitystore.ListGroupsOutput, lastPage bool) bool {

Check failure on line 838 in internal/sync.go

View workflow job for this annotation

GitHub Actions / test

exported function ListGroupsPagesCallbackFn should have comment or be unexported
// Loop through each Group returned
for _, group := range page.Groups {
// Convert to native Group object
Expand Down Expand Up @@ -853,7 +867,7 @@
return awsUsers, nil
}

func ListUsersPagesCallbackFn(page *identitystore.ListUsersOutput, lastPage bool) bool {

Check failure on line 870 in internal/sync.go

View workflow job for this annotation

GitHub Actions / test

exported function ListUsersPagesCallbackFn should have comment or be unexported
// Loop through each User in ListUsersOutput and convert to native User object
for _, user := range page.Users {
awsUsers = append(awsUsers, ConvertSdkUserObjToNative(user))
Expand All @@ -861,7 +875,7 @@
return !lastPage
}

func ConvertSdkUserObjToNative(user *identitystore.User) *aws.User {

Check failure on line 878 in internal/sync.go

View workflow job for this annotation

GitHub Actions / test

exported function ConvertSdkUserObjToNative should have comment or be unexported
// Convert emails into native Email object
userEmails := make([]aws.UserEmail, 0)

Expand Down Expand Up @@ -905,7 +919,7 @@
}
}

func CreateUserIDtoUserObjMap(awsUsers []*aws.User) map[string]*aws.User {

Check failure on line 922 in internal/sync.go

View workflow job for this annotation

GitHub Actions / test

exported function CreateUserIDtoUserObjMap should have comment or be unexported
awsUsersMap := make(map[string]*aws.User)

for _, awsUser := range awsUsers {
Expand All @@ -915,7 +929,7 @@
return awsUsersMap
}

var ListGroupMembershipPagesCallbackFn func(page *identitystore.ListGroupMembershipsOutput, lastPage bool) bool

Check failure on line 932 in internal/sync.go

View workflow job for this annotation

GitHub Actions / test

exported var ListGroupMembershipPagesCallbackFn should have comment or be unexported

func (s *syncGSuite) GetGroupMembershipsLists(awsGroups []*aws.Group, awsUsersMap map[string]*aws.User) (map[string][]*aws.User, error) {
awsGroupsUsers := make(map[string][]*aws.User)
Expand Down
Loading