Skip to content
Merged
Show file tree
Hide file tree
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
fixed integration test, reduced complexity
  • Loading branch information
Akshay2191 committed Oct 3, 2025
commit 555223025c500a7b421b282e8f1247894af30aab
6 changes: 3 additions & 3 deletions api/grpc/mpi/v1/command.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions api/grpc/mpi/v1/command.proto
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ message NGINXPlusRuntimeInfo {
repeated string dynamic_modules = 5;
// the plus API details
APIDetails plus_api = 6;
// to store all the endpoints details
// to parse all the plus API
repeated APIDetails plus_apis = 7;
}

Expand All @@ -356,7 +356,7 @@ message APIDetails {
string listen = 2;
// the API CA file path
string Ca = 3;
// flag to know if this API location was configured with 'api write=on;'
// flag to know API is configured with 'write=on;'
bool write_enabled = 4;
}

Expand Down
2 changes: 1 addition & 1 deletion api/grpc/mpi/v1/common.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/grpc/mpi/v1/files.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docs/proto/protos.md
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ Perform an associated API action on an instance
| location | [string](#string) | | the API location directive |
| listen | [string](#string) | | the API listen directive |
| Ca | [string](#string) | | the API CA file path |
| write_enabled | [bool](#bool) | | flag to know if this API location was configured with 'api write=on;' |
| write_enabled | [bool](#bool) | | flag to know API is configured with 'write=on;' |



Expand Down Expand Up @@ -1132,7 +1132,7 @@ A set of runtime NGINX Plus settings
| loadable_modules | [string](#string) | repeated | List of NGINX potentially loadable modules (installed but not loaded). |
| dynamic_modules | [string](#string) | repeated | List of NGINX dynamic modules. |
| plus_api | [APIDetails](#mpi-v1-APIDetails) | | the plus API details |
| plus_apis | [APIDetails](#mpi-v1-APIDetails) | repeated | to store all the endpoints details |
| plus_apis | [APIDetails](#mpi-v1-APIDetails) | repeated | to parse all the plus API |



Expand Down
71 changes: 51 additions & 20 deletions internal/datasource/config/nginx_config_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ type (
current *crossplane.Directive, apiType string) []*model.APIDetails
)

type apiCreationParams struct {
locationDirectiveName string
path string
caCertLocation string
isSSL bool
isWriteEnabled bool
}

func NewNginxConfigParser(agentConfig *config.Config) *NginxConfigParser {
return &NginxConfigParser{
agentConfig: agentConfig,
Expand Down Expand Up @@ -148,7 +156,6 @@ func (ncp *NginxConfigParser) FindPlusAPI(
func (ncp *NginxConfigParser) FindAllPlusAPIs(
ctx context.Context, nginxConfigContext *model.NginxConfigContext,
) []*model.APIDetails {
// This function returns the list populated by createNginxConfigContext/Parse
if nginxConfigContext.PlusAPIs == nil {
return []*model.APIDetails{}
}
Expand Down Expand Up @@ -714,47 +721,55 @@ func (ncp *NginxConfigParser) apiDetailsFromLocationDirective(
addresses := ncp.parseAddressFromServerDirective(parent)
path := ncp.parsePathFromLocationDirective(current)

params := apiCreationParams{
locationDirectiveName: locationDirectiveName,
path: path,
caCertLocation: caCertLocation,
isSSL: isSSL,
isWriteEnabled: isWriteEnabled,
}

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

if locChild.Directive == locationDirectiveName {
for _, address := range addresses {
details = append(
details,
ncp.createAPIDetails(locationDirectiveName, address, path, caCertLocation, isSSL, isWriteEnabled),
)
}
details = append(details, ncp.createAPIDetailsForAddresses(
params,
addresses,
)...)
}
}

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,
params apiCreationParams, address string,
) (details *model.APIDetails) {
if strings.HasPrefix(address, "unix:") {
format := unixStubStatusFormat

if locationDirectiveName == plusAPIDirective {
if params.locationDirectiveName == plusAPIDirective {
format = unixPlusAPIFormat
}

details = &model.APIDetails{
URL: fmt.Sprintf(format, path),
URL: fmt.Sprintf(format, params.path),
Listen: address,
Location: path,
Ca: caCertLocation,
WriteEnabled: isWriteEnabled,
Location: params.path,
Ca: params.caCertLocation,
WriteEnabled: params.isWriteEnabled,
}
} else {
details = &model.APIDetails{
URL: fmt.Sprintf("%s://%s%s", map[bool]string{true: "https", false: "http"}[isSSL],
address, path),
URL: fmt.Sprintf("%s://%s%s", map[bool]string{true: "https", false: "http"}[params.isSSL],
address, params.path),
Listen: address,
Location: path,
Ca: caCertLocation,
WriteEnabled: isWriteEnabled,
Location: params.path,
Ca: params.caCertLocation,
WriteEnabled: params.isWriteEnabled,
}
}

Expand Down Expand Up @@ -909,6 +924,22 @@ func (ncp *NginxConfigParser) isDuplicateFile(nginxConfigContextFiles []*mpi.Fil
return false
}

func (ncp *NginxConfigParser) createAPIDetailsForAddresses(
params apiCreationParams,
addresses []string,
) (details []*model.APIDetails) {
for _, address := range addresses {
details = append(details,
ncp.createAPIDetails(
params,
address,
),
)
}

return details
}

func (ncp *NginxConfigParser) isPlusAPIWriteEnabled(ctx context.Context,
directive *crossplane.Directive,
locationPath string,
Expand Down
Loading