Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
reducing Cognitive Complexity
  • Loading branch information
Akshay2191 committed Oct 1, 2025
commit 14977b6dcd9319b1584f5f91f5624d0483039009
43 changes: 28 additions & 15 deletions internal/datasource/config/nginx_config_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -703,25 +703,18 @@ func (ncp *NginxConfigParser) apiDetailsFromLocationDirective(
return nil
}

isWriteEnabled := false
for _, locChild := range current.Block {
if locChild.Directive != plusAPIDirective && locChild.Directive != stubStatusAPIDirective {
continue
}

isWriteEnabled := false
if locChild.Directive == plusAPIDirective {
for _, arg := range locChild.Args {
if arg == "write=on" {
isWriteEnabled = true
slog.DebugContext(ctx, "Found NGINX Plus API with write=on", "location", current.Args[0])
break
}
}
if ncp.isPlusAPIWriteEnabled(ctx, locChild, current.Args[0]) {
isWriteEnabled = true
break
}
}

addresses := ncp.parseAddressFromServerDirective(parent)
path := ncp.parsePathFromLocationDirective(current)
addresses := ncp.parseAddressFromServerDirective(parent)
path := ncp.parsePathFromLocationDirective(current)

for _, locChild := range current.Block {
if locChild.Directive == locationDirectiveName {
for _, address := range addresses {
details = append(
Expand All @@ -735,6 +728,7 @@ func (ncp *NginxConfigParser) apiDetailsFromLocationDirective(
return details
}

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

return false
}

func (ncp *NginxConfigParser) isPlusAPIWriteEnabled(ctx context.Context,
directive *crossplane.Directive,
locationPath string,
) bool {
// Only check plus_api directives
if directive.Directive != plusAPIDirective {
return false
}

for _, arg := range directive.Args {
if arg == "write=on" {
slog.DebugContext(ctx, "Found NGINX Plus API with write=on", "location", locationPath)
return true
}
}

return false
}
Loading