Skip to content

Commit 5552230

Browse files
committed
fixed integration test, reduced complexity
1 parent 14977b6 commit 5552230

File tree

6 files changed

+60
-29
lines changed

6 files changed

+60
-29
lines changed

api/grpc/mpi/v1/command.pb.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/grpc/mpi/v1/command.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ message NGINXPlusRuntimeInfo {
345345
repeated string dynamic_modules = 5;
346346
// the plus API details
347347
APIDetails plus_api = 6;
348-
// to store all the endpoints details
348+
// to parse all the plus API
349349
repeated APIDetails plus_apis = 7;
350350
}
351351

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

api/grpc/mpi/v1/common.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/grpc/mpi/v1/files.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/proto/protos.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ Perform an associated API action on an instance
697697
| location | [string](#string) | | the API location directive |
698698
| listen | [string](#string) | | the API listen directive |
699699
| Ca | [string](#string) | | the API CA file path |
700-
| write_enabled | [bool](#bool) | | flag to know if this API location was configured with 'api write=on;' |
700+
| write_enabled | [bool](#bool) | | flag to know API is configured with 'write=on;' |
701701

702702

703703

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

11371137

11381138

internal/datasource/config/nginx_config_parser.go

Lines changed: 51 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ type (
6868
current *crossplane.Directive, apiType string) []*model.APIDetails
6969
)
7070

71+
type apiCreationParams struct {
72+
locationDirectiveName string
73+
path string
74+
caCertLocation string
75+
isSSL bool
76+
isWriteEnabled bool
77+
}
78+
7179
func NewNginxConfigParser(agentConfig *config.Config) *NginxConfigParser {
7280
return &NginxConfigParser{
7381
agentConfig: agentConfig,
@@ -148,7 +156,6 @@ func (ncp *NginxConfigParser) FindPlusAPI(
148156
func (ncp *NginxConfigParser) FindAllPlusAPIs(
149157
ctx context.Context, nginxConfigContext *model.NginxConfigContext,
150158
) []*model.APIDetails {
151-
// This function returns the list populated by createNginxConfigContext/Parse
152159
if nginxConfigContext.PlusAPIs == nil {
153160
return []*model.APIDetails{}
154161
}
@@ -714,47 +721,55 @@ func (ncp *NginxConfigParser) apiDetailsFromLocationDirective(
714721
addresses := ncp.parseAddressFromServerDirective(parent)
715722
path := ncp.parsePathFromLocationDirective(current)
716723

724+
params := apiCreationParams{
725+
locationDirectiveName: locationDirectiveName,
726+
path: path,
727+
caCertLocation: caCertLocation,
728+
isSSL: isSSL,
729+
isWriteEnabled: isWriteEnabled,
730+
}
731+
717732
for _, locChild := range current.Block {
733+
if locChild.Directive != plusAPIDirective && locChild.Directive != stubStatusAPIDirective {
734+
continue
735+
}
736+
718737
if locChild.Directive == locationDirectiveName {
719-
for _, address := range addresses {
720-
details = append(
721-
details,
722-
ncp.createAPIDetails(locationDirectiveName, address, path, caCertLocation, isSSL, isWriteEnabled),
723-
)
724-
}
738+
details = append(details, ncp.createAPIDetailsForAddresses(
739+
params,
740+
addresses,
741+
)...)
725742
}
726743
}
727744

728745
return details
729746
}
730747

731-
//nolint:revive // isWriteEnabled flag is required for selecting Plus API
732748
func (ncp *NginxConfigParser) createAPIDetails(
733-
locationDirectiveName, address, path, caCertLocation string, isSSL bool,
734-
isWriteEnabled bool,
749+
params apiCreationParams, address string,
735750
) (details *model.APIDetails) {
736751
if strings.HasPrefix(address, "unix:") {
737752
format := unixStubStatusFormat
738753

739-
if locationDirectiveName == plusAPIDirective {
754+
if params.locationDirectiveName == plusAPIDirective {
740755
format = unixPlusAPIFormat
741756
}
742757

743758
details = &model.APIDetails{
744-
URL: fmt.Sprintf(format, path),
759+
URL: fmt.Sprintf(format, params.path),
745760
Listen: address,
746-
Location: path,
747-
Ca: caCertLocation,
748-
WriteEnabled: isWriteEnabled,
761+
Location: params.path,
762+
Ca: params.caCertLocation,
763+
WriteEnabled: params.isWriteEnabled,
749764
}
750765
} else {
751766
details = &model.APIDetails{
752-
URL: fmt.Sprintf("%s://%s%s", map[bool]string{true: "https", false: "http"}[isSSL],
753-
address, path),
767+
URL: fmt.Sprintf("%s://%s%s", map[bool]string{true: "https", false: "http"}[params.isSSL],
768+
address, params.path),
754769
Listen: address,
755-
Location: path,
756-
Ca: caCertLocation,
757-
WriteEnabled: isWriteEnabled,
770+
Location: params.path,
771+
Ca: params.caCertLocation,
772+
WriteEnabled: params.isWriteEnabled,
758773
}
759774
}
760775

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

927+
func (ncp *NginxConfigParser) createAPIDetailsForAddresses(
928+
params apiCreationParams,
929+
addresses []string,
930+
) (details []*model.APIDetails) {
931+
for _, address := range addresses {
932+
details = append(details,
933+
ncp.createAPIDetails(
934+
params,
935+
address,
936+
),
937+
)
938+
}
939+
940+
return details
941+
}
942+
912943
func (ncp *NginxConfigParser) isPlusAPIWriteEnabled(ctx context.Context,
913944
directive *crossplane.Directive,
914945
locationPath string,

0 commit comments

Comments
 (0)