Skip to content

Commit e1083b8

Browse files
authored
Merge pull request #46 from jonasz-lasut/fix/#34-pointer-to-string-structpb-value
Fix #34: Data returned by graphQuery should return map[string]<non-pointer>type to be able to be serialized into structpb.Value
2 parents 79767d2 + 43d9888 commit e1083b8

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
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
}

fn_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/upbound/function-msgraph/input/v1beta1"
1111
"google.golang.org/protobuf/testing/protocmp"
1212
"google.golang.org/protobuf/types/known/durationpb"
13+
"k8s.io/utils/ptr"
1314

1415
"github.com/crossplane/crossplane-runtime/pkg/errors"
1516
"github.com/crossplane/crossplane-runtime/pkg/logging"
@@ -26,10 +27,6 @@ func (m *MockGraphQuery) graphQuery(ctx context.Context, azureCreds map[string]s
2627
return m.GraphQueryFunc(ctx, azureCreds, in)
2728
}
2829

29-
func strPtr(s string) *string {
30-
return &s
31-
}
32-
3330
// TestResolveGroupsRef tests the functionality of resolving groupsRef from context, status, or spec
3431
func TestResolveGroupsRef(t *testing.T) {
3532
var (
@@ -2312,7 +2309,7 @@ func TestRunFunction(t *testing.T) {
23122309
Conditions: []*fnv1.Condition{
23132310
{
23142311
Type: "FunctionSkip",
2315-
Message: strPtr("Target already has data, skipped query to avoid throttling"),
2312+
Message: ptr.To("Target already has data, skipped query to avoid throttling"),
23162313
Status: fnv1.Status_STATUS_CONDITION_TRUE,
23172314
Reason: "SkippedQuery",
23182315
Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(),

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ require (
1414
github.com/microsoftgraph/msgraph-sdk-go v1.84.0
1515
google.golang.org/protobuf v1.36.8
1616
k8s.io/apimachinery v0.33.4
17+
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738
1718
sigs.k8s.io/controller-tools v0.18.0
1819
)
1920

@@ -93,7 +94,6 @@ require (
9394
k8s.io/gengo/v2 v2.0.0-20250207200755-1244d31929d7 // indirect
9495
k8s.io/klog/v2 v2.130.1 // indirect
9596
k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff // indirect
96-
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect
9797
sigs.k8s.io/controller-runtime v0.19.0 // indirect
9898
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
9999
sigs.k8s.io/randfill v1.0.0 // indirect

0 commit comments

Comments
 (0)