Skip to content
Open
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
12 changes: 5 additions & 7 deletions fn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down Expand Up @@ -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")
}

Expand Down Expand Up @@ -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")
}

Expand Down Expand Up @@ -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)
}
6 changes: 6 additions & 0 deletions input/v1beta1/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down