Skip to content

Commit b8510c4

Browse files
committed
Add fail on empty option to error condition
1 parent 4982709 commit b8510c4

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

fn.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ func (g *GraphQuery) graphQuery(ctx context.Context, azureCreds map[string]strin
497497

498498
// validateUsers validates if the provided user principal names (emails) exist
499499
func (g *GraphQuery) validateUsers(ctx context.Context, client *msgraphsdk.GraphServiceClient, in *v1beta1.Input) (interface{}, error) {
500-
if len(in.Users) == 0 {
500+
if in.FailOnEmpty != nil && *in.FailOnEmpty && len(in.Users) == 0 {
501501
return nil, errors.New("no users provided for validation")
502502
}
503503

@@ -754,7 +754,7 @@ func (g *GraphQuery) getGroupMembers(ctx context.Context, client *msgraphsdk.Gra
754754

755755
// getGroupObjectIDs retrieves object IDs for the specified group names
756756
func (g *GraphQuery) getGroupObjectIDs(ctx context.Context, client *msgraphsdk.GraphServiceClient, in *v1beta1.Input) (interface{}, error) {
757-
if len(in.Groups) == 0 {
757+
if in.FailOnEmpty != nil && *in.FailOnEmpty && len(in.Groups) == 0 {
758758
return nil, errors.New("no group names provided")
759759
}
760760

@@ -799,7 +799,7 @@ func (g *GraphQuery) getGroupObjectIDs(ctx context.Context, client *msgraphsdk.G
799799

800800
// getServicePrincipalDetails retrieves details about service principals by name
801801
func (g *GraphQuery) getServicePrincipalDetails(ctx context.Context, client *msgraphsdk.GraphServiceClient, in *v1beta1.Input) (interface{}, error) {
802-
if len(in.ServicePrincipals) == 0 {
802+
if in.FailOnEmpty != nil && *in.FailOnEmpty && len(in.ServicePrincipals) == 0 {
803803
return nil, errors.New("no service principal names provided")
804804
}
805805

@@ -1515,10 +1515,8 @@ func (f *Function) extractStringArrayFromMap(dataMap map[string]interface{}, fie
15151515
result = append(result, &strCopy)
15161516
}
15171517
}
1518-
if len(result) > 0 {
1519-
return result, nil
1520-
}
1518+
return result, nil
15211519
}
15221520

1523-
return nil, errors.Errorf("cannot resolve groupsRef: %s not a string array or empty", refKey)
1521+
return nil, errors.Errorf("cannot resolve groupsRef: %s not a string array", refKey)
15241522
}

0 commit comments

Comments
 (0)