Skip to content
Merged
Show file tree
Hide file tree
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
27 changes: 14 additions & 13 deletions fn.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/microsoftgraph/msgraph-sdk-go/users"
"github.com/upbound/function-msgraph/input/v1beta1"
"google.golang.org/protobuf/types/known/structpb"
"k8s.io/utils/ptr"

"github.com/crossplane/crossplane-runtime/pkg/errors"
"github.com/crossplane/crossplane-runtime/pkg/logging"
Expand Down Expand Up @@ -349,10 +350,10 @@ func (g *GraphQuery) validateUsers(ctx context.Context, client *msgraphsdk.Graph
if result.GetValue() != nil {
for _, user := range result.GetValue() {
userMap := map[string]interface{}{
"id": user.GetId(),
"displayName": user.GetDisplayName(),
"userPrincipalName": user.GetUserPrincipalName(),
"mail": user.GetMail(),
"id": ptr.Deref(user.GetId(), ""),
"displayName": ptr.Deref(user.GetDisplayName(), ""),
"userPrincipalName": ptr.Deref(user.GetUserPrincipalName(), ""),
"mail": ptr.Deref(user.GetMail(), ""),
}
results = append(results, userMap)
}
Expand Down Expand Up @@ -488,7 +489,7 @@ func (g *GraphQuery) processMember(member models.DirectoryObjectable) map[string
unknownType = "unknown"
)

memberID := member.GetId()
memberID := ptr.Deref(member.GetId(), "")
additionalData := member.GetAdditionalData()

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

// Extract display name
memberMap["displayName"] = g.extractDisplayName(member, *memberID)
memberMap["displayName"] = g.extractDisplayName(member, memberID)

// Extract type-specific properties
switch memberType {
Expand Down Expand Up @@ -604,9 +605,9 @@ func (g *GraphQuery) getGroupObjectIDs(ctx context.Context, client *msgraphsdk.G
if groupResult.GetValue() != nil && len(groupResult.GetValue()) > 0 {
for _, group := range groupResult.GetValue() {
groupMap := map[string]interface{}{
"id": group.GetId(),
"displayName": group.GetDisplayName(),
"description": group.GetDescription(),
"id": ptr.Deref(group.GetId(), ""),
"displayName": ptr.Deref(group.GetDisplayName(), ""),
"description": ptr.Deref(group.GetDescription(), ""),
}
results = append(results, groupMap)
}
Expand Down Expand Up @@ -649,10 +650,10 @@ func (g *GraphQuery) getServicePrincipalDetails(ctx context.Context, client *msg
if spResult.GetValue() != nil && len(spResult.GetValue()) > 0 {
for _, sp := range spResult.GetValue() {
spMap := map[string]interface{}{
"id": sp.GetId(),
"appId": sp.GetAppId(),
"displayName": sp.GetDisplayName(),
"description": sp.GetDescription(),
"id": ptr.Deref(sp.GetId(), ""),
"appId": ptr.Deref(sp.GetAppId(), ""),
"displayName": ptr.Deref(sp.GetDisplayName(), ""),
"description": ptr.Deref(sp.GetDescription(), ""),
}
results = append(results, spMap)
}
Expand Down
7 changes: 2 additions & 5 deletions fn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/upbound/function-msgraph/input/v1beta1"
"google.golang.org/protobuf/testing/protocmp"
"google.golang.org/protobuf/types/known/durationpb"
"k8s.io/utils/ptr"

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

func strPtr(s string) *string {
return &s
}

// TestResolveGroupsRef tests the functionality of resolving groupsRef from context, status, or spec
func TestResolveGroupsRef(t *testing.T) {
var (
Expand Down Expand Up @@ -2312,7 +2309,7 @@ func TestRunFunction(t *testing.T) {
Conditions: []*fnv1.Condition{
{
Type: "FunctionSkip",
Message: strPtr("Target already has data, skipped query to avoid throttling"),
Message: ptr.To("Target already has data, skipped query to avoid throttling"),
Status: fnv1.Status_STATUS_CONDITION_TRUE,
Reason: "SkippedQuery",
Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(),
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/microsoftgraph/msgraph-sdk-go v1.84.0
google.golang.org/protobuf v1.36.8
k8s.io/apimachinery v0.33.4
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738
sigs.k8s.io/controller-tools v0.18.0
)

Expand Down Expand Up @@ -93,7 +94,6 @@ require (
k8s.io/gengo/v2 v2.0.0-20250207200755-1244d31929d7 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff // indirect
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect
sigs.k8s.io/controller-runtime v0.19.0 // indirect
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
sigs.k8s.io/randfill v1.0.0 // indirect
Expand Down
Loading