Skip to content

Commit 75ea9bf

Browse files
committed
Data returned by graphQuery should return map[string]non-pointer-value to be able to be serialized into structpb.Value
1 parent 79767d2 commit 75ea9bf

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

fn.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/microsoftgraph/msgraph-sdk-go/users"
1818
"github.com/upbound/function-msgraph/input/v1beta1"
1919
"google.golang.org/protobuf/types/known/structpb"
20+
"k8s.io/utils/ptr"
2021

2122
"github.com/crossplane/crossplane-runtime/pkg/errors"
2223
"github.com/crossplane/crossplane-runtime/pkg/logging"
@@ -349,10 +350,10 @@ func (g *GraphQuery) validateUsers(ctx context.Context, client *msgraphsdk.Graph
349350
if result.GetValue() != nil {
350351
for _, user := range result.GetValue() {
351352
userMap := map[string]interface{}{
352-
"id": user.GetId(),
353-
"displayName": user.GetDisplayName(),
354-
"userPrincipalName": user.GetUserPrincipalName(),
355-
"mail": user.GetMail(),
353+
"id": ptr.Deref(user.GetId(), ""),
354+
"displayName": ptr.Deref(user.GetDisplayName(), ""),
355+
"userPrincipalName": ptr.Deref(user.GetUserPrincipalName(), ""),
356+
"mail": ptr.Deref(user.GetMail(), ""),
356357
}
357358
results = append(results, userMap)
358359
}
@@ -488,7 +489,7 @@ func (g *GraphQuery) processMember(member models.DirectoryObjectable) map[string
488489
unknownType = "unknown"
489490
)
490491

491-
memberID := member.GetId()
492+
memberID := ptr.Deref(member.GetId(), "")
492493
additionalData := member.GetAdditionalData()
493494

494495
// Create basic member info
@@ -524,7 +525,7 @@ func (g *GraphQuery) processMember(member models.DirectoryObjectable) map[string
524525
memberMap["type"] = memberType
525526

526527
// Extract display name
527-
memberMap["displayName"] = g.extractDisplayName(member, *memberID)
528+
memberMap["displayName"] = g.extractDisplayName(member, memberID)
528529

529530
// Extract type-specific properties
530531
switch memberType {
@@ -604,9 +605,9 @@ func (g *GraphQuery) getGroupObjectIDs(ctx context.Context, client *msgraphsdk.G
604605
if groupResult.GetValue() != nil && len(groupResult.GetValue()) > 0 {
605606
for _, group := range groupResult.GetValue() {
606607
groupMap := map[string]interface{}{
607-
"id": group.GetId(),
608-
"displayName": group.GetDisplayName(),
609-
"description": group.GetDescription(),
608+
"id": ptr.Deref(group.GetId(), ""),
609+
"displayName": ptr.Deref(group.GetDisplayName(), ""),
610+
"description": ptr.Deref(group.GetDescription(), ""),
610611
}
611612
results = append(results, groupMap)
612613
}
@@ -649,10 +650,10 @@ func (g *GraphQuery) getServicePrincipalDetails(ctx context.Context, client *msg
649650
if spResult.GetValue() != nil && len(spResult.GetValue()) > 0 {
650651
for _, sp := range spResult.GetValue() {
651652
spMap := map[string]interface{}{
652-
"id": sp.GetId(),
653-
"appId": sp.GetAppId(),
654-
"displayName": sp.GetDisplayName(),
655-
"description": sp.GetDescription(),
653+
"id": ptr.Deref(sp.GetId(), ""),
654+
"appId": ptr.Deref(sp.GetAppId(), ""),
655+
"displayName": ptr.Deref(sp.GetDisplayName(), ""),
656+
"description": ptr.Deref(sp.GetDescription(), ""),
656657
}
657658
results = append(results, spMap)
658659
}

0 commit comments

Comments
 (0)