From 498270949a40aafbb3a9b4d3434718e7e1dc0538 Mon Sep 17 00:00:00 2001 From: Tom van Dinther <39470469+tvandinther@users.noreply.github.com> Date: Mon, 13 Oct 2025 13:10:00 +0000 Subject: [PATCH 1/2] Add `FailOnEmpty` option to input --- input/v1beta1/input.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/input/v1beta1/input.go b/input/v1beta1/input.go index 41ccefc..4ed48fa 100644 --- a/input/v1beta1/input.go +++ b/input/v1beta1/input.go @@ -67,6 +67,12 @@ type Input struct { // +optional SkipQueryWhenTargetHasData *bool `json:"skipQueryWhenTargetHasData,omitempty"` + // FailOnEmpty controls whether the function should fail when input lists are empty. + // If true, the function will error on empty input lists. + // If false or unset, empty lists are valid and will result in a no-op. + // +optional + FailOnEmpty *bool `json:"failOnEmpty,omitempty"` + // Identity defines the type of identity used for authentication to the Microsoft Graph API. Identity *Identity `json:"identity,omitempty"` } From b8510c4a77854639560a2c91d9f1dd02f8ae5187 Mon Sep 17 00:00:00 2001 From: Tom van Dinther <39470469+tvandinther@users.noreply.github.com> Date: Mon, 13 Oct 2025 13:11:14 +0000 Subject: [PATCH 2/2] Add fail on empty option to error condition --- fn.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/fn.go b/fn.go index c34cfe6..a51113a 100644 --- a/fn.go +++ b/fn.go @@ -497,7 +497,7 @@ func (g *GraphQuery) graphQuery(ctx context.Context, azureCreds map[string]strin // validateUsers validates if the provided user principal names (emails) exist func (g *GraphQuery) validateUsers(ctx context.Context, client *msgraphsdk.GraphServiceClient, in *v1beta1.Input) (interface{}, error) { - if len(in.Users) == 0 { + if in.FailOnEmpty != nil && *in.FailOnEmpty && len(in.Users) == 0 { return nil, errors.New("no users provided for validation") } @@ -754,7 +754,7 @@ func (g *GraphQuery) getGroupMembers(ctx context.Context, client *msgraphsdk.Gra // getGroupObjectIDs retrieves object IDs for the specified group names func (g *GraphQuery) getGroupObjectIDs(ctx context.Context, client *msgraphsdk.GraphServiceClient, in *v1beta1.Input) (interface{}, error) { - if len(in.Groups) == 0 { + if in.FailOnEmpty != nil && *in.FailOnEmpty && len(in.Groups) == 0 { return nil, errors.New("no group names provided") } @@ -799,7 +799,7 @@ func (g *GraphQuery) getGroupObjectIDs(ctx context.Context, client *msgraphsdk.G // getServicePrincipalDetails retrieves details about service principals by name func (g *GraphQuery) getServicePrincipalDetails(ctx context.Context, client *msgraphsdk.GraphServiceClient, in *v1beta1.Input) (interface{}, error) { - if len(in.ServicePrincipals) == 0 { + if in.FailOnEmpty != nil && *in.FailOnEmpty && len(in.ServicePrincipals) == 0 { return nil, errors.New("no service principal names provided") } @@ -1515,10 +1515,8 @@ func (f *Function) extractStringArrayFromMap(dataMap map[string]interface{}, fie result = append(result, &strCopy) } } - if len(result) > 0 { - return result, nil - } + return result, nil } - return nil, errors.Errorf("cannot resolve groupsRef: %s not a string array or empty", refKey) + return nil, errors.Errorf("cannot resolve groupsRef: %s not a string array", refKey) }