Skip to content

Commit

Permalink
Updating to use existing msgraph client
Browse files Browse the repository at this point in the history
  • Loading branch information
mvbrock committed Dec 20, 2024
1 parent 7c8c247 commit 672ae8d
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 277 deletions.
10 changes: 8 additions & 2 deletions lib/msgraph/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ type GroupMember interface {
isGroupMember()
}

type Membership struct {
Type string `json:"@odata.type"`
ID string `json:"id"`
}

type DirectoryObject struct {
ID *string `json:"id,omitempty"`
DisplayName *string `json:"displayName,omitempty"`
ID *string `json:"id,omitempty"`
DisplayName *string `json:"displayName,omitempty"`
MemberOf []Membership `json:"memberOf,omitempty"`
}

type Group struct {
Expand Down
17 changes: 16 additions & 1 deletion lib/msgraph/paginated.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,14 @@ func iterateSimple[T any](c *Client, ctx context.Context, endpoint string, f fun
func (c *Client) iterate(ctx context.Context, endpoint string, f func(json.RawMessage) bool) error {
uri := *c.baseURL
uri.Path = path.Join(uri.Path, endpoint)
uri.RawQuery = url.Values{"$top": {strconv.Itoa(c.pageSize)}}.Encode()
uri.RawQuery = url.Values{
"$top": {
strconv.Itoa(c.pageSize),
},
"$expand": {
"memberOf",
},
}.Encode()
uriString := uri.String()
for uriString != "" {
resp, err := c.request(ctx, http.MethodGet, uriString, nil)
Expand Down Expand Up @@ -101,6 +108,14 @@ func (c *Client) IterateUsers(ctx context.Context, f func(*User) bool) error {
return iterateSimple(c, ctx, "users", f)
}

// IterateServicePrincipals lists all service principals in the Entra ID directory using pagination.
// `f` will be called for each object in the result set.
// if `f` returns `false`, the iteration is stopped (equivalent to `break` in a normal loop).
// Ref: [https://learn.microsoft.com/en-us/graph/api/user-list].
func (c *Client) IterateServicePrincipals(ctx context.Context, f func(principal *ServicePrincipal) bool) error {
return iterateSimple(c, ctx, "servicePrincipals", f)
}

// IterateGroupMembers lists all members for the given Entra ID group using pagination.
// `f` will be called for each object in the result set.
// if `f` returns `false`, the iteration is stopped (equivalent to `break` in a normal loop).
Expand Down
240 changes: 0 additions & 240 deletions lib/srv/discovery/fetchers/azure-sync/msggraphclient.go

This file was deleted.

Loading

0 comments on commit 672ae8d

Please sign in to comment.