Skip to content

Commit

Permalink
feat: get group members on $select (#205)
Browse files Browse the repository at this point in the history
Co-authored-by: Barahona José Luis (IT-PTR-BDE16) <[email protected]>
  • Loading branch information
jolbax and jolbax authored Jul 16, 2022
1 parent bc36630 commit 51c6034
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions pkg/syncer/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
msgraphcore "github.com/microsoftgraph/msgraph-sdk-go-core"
msgroups "github.com/microsoftgraph/msgraph-sdk-go/groups"
msmembers "github.com/microsoftgraph/msgraph-sdk-go/groups/item/members"
"github.com/microsoftgraph/msgraph-sdk-go/groups/item/transitivemembers"
graph "github.com/microsoftgraph/msgraph-sdk-go/models/microsoft/graph"
)

Expand Down Expand Up @@ -303,8 +304,22 @@ func (a *AzureSyncer) GetProviderName() string {
}

func (a *AzureSyncer) listGroupMembers(groupID *string) ([]string, error) {
groupMembers := []string{}
memberRequest, err := a.Client.GroupsById(*groupID).TransitiveMembers().Get(nil)
var groupMembers []string
var selectParameter []string

if a.Provider.UserNameAttributes != nil {
selectParameter = *a.Provider.UserNameAttributes
} else {
selectParameter = []string{GraphUserNameAttribute}
}

queryParameters := transitivemembers.TransitiveMembersRequestBuilderGetQueryParameters{
Select: selectParameter,
}
getOptions := transitivemembers.TransitiveMembersRequestBuilderGetOptions{
Q: &queryParameters,
}
memberRequest, err := a.Client.GroupsById(*groupID).TransitiveMembers().Get(&getOptions)

if err != nil {
return nil, err
Expand All @@ -325,7 +340,6 @@ func (a *AzureSyncer) listGroupMembers(groupID *string) ([]string, error) {
if username, found := a.getUsernameForUser(member); found {
groupMembers = append(groupMembers, fmt.Sprintf("%v", username))
} else {
azureLogger.Info(fmt.Sprintf("Warning: Username for user cannot be found in Group ID '%v'", *groupID))
}
}

Expand Down

0 comments on commit 51c6034

Please sign in to comment.