Skip to content

Commit 14977b6

Browse files
committed
reducing Cognitive Complexity
1 parent 99d0db9 commit 14977b6

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

internal/datasource/config/nginx_config_parser.go

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -703,25 +703,18 @@ func (ncp *NginxConfigParser) apiDetailsFromLocationDirective(
703703
return nil
704704
}
705705

706+
isWriteEnabled := false
706707
for _, locChild := range current.Block {
707-
if locChild.Directive != plusAPIDirective && locChild.Directive != stubStatusAPIDirective {
708-
continue
709-
}
710-
711-
isWriteEnabled := false
712-
if locChild.Directive == plusAPIDirective {
713-
for _, arg := range locChild.Args {
714-
if arg == "write=on" {
715-
isWriteEnabled = true
716-
slog.DebugContext(ctx, "Found NGINX Plus API with write=on", "location", current.Args[0])
717-
break
718-
}
719-
}
708+
if ncp.isPlusAPIWriteEnabled(ctx, locChild, current.Args[0]) {
709+
isWriteEnabled = true
710+
break
720711
}
712+
}
721713

722-
addresses := ncp.parseAddressFromServerDirective(parent)
723-
path := ncp.parsePathFromLocationDirective(current)
714+
addresses := ncp.parseAddressFromServerDirective(parent)
715+
path := ncp.parsePathFromLocationDirective(current)
724716

717+
for _, locChild := range current.Block {
725718
if locChild.Directive == locationDirectiveName {
726719
for _, address := range addresses {
727720
details = append(
@@ -735,6 +728,7 @@ func (ncp *NginxConfigParser) apiDetailsFromLocationDirective(
735728
return details
736729
}
737730

731+
//nolint:revive // isWriteEnabled flag is required for selecting Plus API
738732
func (ncp *NginxConfigParser) createAPIDetails(
739733
locationDirectiveName, address, path, caCertLocation string, isSSL bool,
740734
isWriteEnabled bool,
@@ -914,3 +908,22 @@ func (ncp *NginxConfigParser) isDuplicateFile(nginxConfigContextFiles []*mpi.Fil
914908

915909
return false
916910
}
911+
912+
func (ncp *NginxConfigParser) isPlusAPIWriteEnabled(ctx context.Context,
913+
directive *crossplane.Directive,
914+
locationPath string,
915+
) bool {
916+
// Only check plus_api directives
917+
if directive.Directive != plusAPIDirective {
918+
return false
919+
}
920+
921+
for _, arg := range directive.Args {
922+
if arg == "write=on" {
923+
slog.DebugContext(ctx, "Found NGINX Plus API with write=on", "location", locationPath)
924+
return true
925+
}
926+
}
927+
928+
return false
929+
}

0 commit comments

Comments
 (0)