@@ -37,8 +37,6 @@ const (
37
37
" \" $request\" $status $body_bytes_sent \" $http_referer\" \" $http_user_agent\" "
38
38
ltsvArg = "ltsv"
39
39
defaultNumberOfDirectiveArguments = 2
40
- plusAPIName = "plus"
41
- stubStatusAPIName = "stub status"
42
40
plusAPIDirective = "api"
43
41
stubStatusAPIDirective = "stub_status"
44
42
unixStubStatusFormat = "http://config-status%s"
@@ -66,7 +64,7 @@ var _ ConfigParser = (*NginxConfigParser)(nil)
66
64
type (
67
65
crossplaneTraverseCallback = func (ctx context.Context , parent , current * crossplane.Directive ) error
68
66
crossplaneTraverseCallbackAPIDetails = func (ctx context.Context , parent ,
69
- current * crossplane.Directive , apiType string ) * model.APIDetails
67
+ current * crossplane.Directive , apiType string ) [] * model.APIDetails
70
68
)
71
69
72
70
func NewNginxConfigParser (agentConfig * config.Config ) * NginxConfigParser {
@@ -111,7 +109,7 @@ func (ncp *NginxConfigParser) FindStubStatusAPI(
111
109
) * model.APIDetails {
112
110
for _ , stubStatus := range nginxConfigContext .StubStatuses {
113
111
if stubStatus != nil && stubStatus .URL != "" {
114
- if ncp .pingAPIEndpoint (ctx , stubStatus , stubStatusAPIName ) {
112
+ if ncp .pingAPIEndpoint (ctx , stubStatus , stubStatusAPIDirective ) {
115
113
slog .InfoContext (ctx , "Found NGINX stub status API" , "url" , stubStatus .URL )
116
114
return stubStatus
117
115
}
@@ -131,7 +129,7 @@ func (ncp *NginxConfigParser) FindPlusAPI(
131
129
) * model.APIDetails {
132
130
for _ , plusAPI := range nginxConfigContext .PlusAPIs {
133
131
if plusAPI != nil && plusAPI .URL != "" {
134
- if ncp .pingAPIEndpoint (ctx , plusAPI , plusAPIName ) {
132
+ if ncp .pingAPIEndpoint (ctx , plusAPI , plusAPIDirective ) {
135
133
slog .InfoContext (ctx , "Found NGINX Plus API" , "url" , plusAPI .URL )
136
134
return plusAPI
137
135
}
@@ -385,12 +383,12 @@ func (ncp *NginxConfigParser) crossplaneConfigTraverseAPIDetails(
385
383
for _ , dir := range root .Parsed {
386
384
response := callback (ctx , nil , dir , apiType )
387
385
if response != nil {
388
- responses = append (responses , response )
386
+ responses = append (responses , response ... )
389
387
continue
390
388
}
391
389
response = traverseAPIDetails (ctx , dir , callback , & stop , apiType )
392
390
if response != nil {
393
- responses = append (responses , response )
391
+ responses = append (responses , response ... )
394
392
}
395
393
}
396
394
@@ -403,14 +401,14 @@ func traverseAPIDetails(
403
401
callback crossplaneTraverseCallbackAPIDetails ,
404
402
stop * bool ,
405
403
apiType string ,
406
- ) (response * model.APIDetails ) {
404
+ ) (response [] * model.APIDetails ) {
407
405
if * stop {
408
406
return nil
409
407
}
410
408
411
409
for _ , child := range root .Block {
412
410
response = callback (ctx , root , child , apiType )
413
- if response != nil && response . URL != "" {
411
+ if len ( response ) > 0 {
414
412
* stop = true
415
413
return response
416
414
}
@@ -573,9 +571,9 @@ func (ncp *NginxConfigParser) sslCert(ctx context.Context, file, rootDir string)
573
571
574
572
func (ncp * NginxConfigParser ) apiCallback (
575
573
ctx context.Context , parent , current * crossplane.Directive , apiType string ,
576
- ) * model.APIDetails {
577
- details := ncp .apiDetailsFromLocationDirective (ctx , parent , current , apiType )
578
- if details != nil {
574
+ ) ( details [] * model.APIDetails ) {
575
+ details = append ( details , ncp .apiDetailsFromLocationDirective (ctx , parent , current , apiType ) ... )
576
+ if len ( details ) > 0 {
579
577
slog .DebugContext (ctx , "Found " + apiType , "api_details" , details )
580
578
}
581
579
@@ -679,7 +677,7 @@ func validateAPIResponse(apiType string, bodyBytes []byte) error {
679
677
func (ncp * NginxConfigParser ) apiDetailsFromLocationDirective (
680
678
ctx context.Context , parent , current * crossplane.Directive ,
681
679
locationDirectiveName string ,
682
- ) (details * model.APIDetails ) {
680
+ ) (details [] * model.APIDetails ) {
683
681
// Check if SSL is enabled in the server block
684
682
isSSL := ncp .isSSLEnabled (parent )
685
683
@@ -698,11 +696,16 @@ func (ncp *NginxConfigParser) apiDetailsFromLocationDirective(
698
696
continue
699
697
}
700
698
701
- address := ncp .parseAddressFromServerDirective (parent )
699
+ addresses := ncp .parseAddressFromServerDirective (parent )
702
700
path := ncp .parsePathFromLocationDirective (current )
703
701
704
702
if locChild .Directive == locationDirectiveName {
705
- details = ncp .createAPIDetails (locationDirectiveName , address , path , caCertLocation , isSSL )
703
+ for _ , address := range addresses {
704
+ details = append (
705
+ details ,
706
+ ncp .createAPIDetails (locationDirectiveName , address , path , caCertLocation , isSSL ),
707
+ )
708
+ }
706
709
}
707
710
}
708
711
@@ -738,21 +741,24 @@ func (ncp *NginxConfigParser) createAPIDetails(
738
741
return details
739
742
}
740
743
741
- func (ncp * NginxConfigParser ) parseAddressFromServerDirective (parent * crossplane.Directive ) string {
744
+ func (ncp * NginxConfigParser ) parseAddressFromServerDirective (parent * crossplane.Directive ) ( addresses [] string ) {
742
745
port := "80"
743
- host := "localhost"
746
+ hosts := [] string { "localhost" , "127.0.0.1" }
744
747
745
748
if parent == nil {
746
- return ""
749
+ return addresses
747
750
}
748
751
749
752
for _ , dir := range parent .Block {
750
753
if dir .Directive == "listen" {
751
- port , host = ncp .parseListenDirectiveAddress (dir , port , host )
754
+ for _ , host := range hosts {
755
+ port , host = ncp .parseListenDirectiveAddress (dir , port , host )
756
+ addresses = append (addresses , host + ":" + port )
757
+ }
752
758
}
753
759
}
754
760
755
- return host + ":" + port
761
+ return addresses
756
762
}
757
763
758
764
func (ncp * NginxConfigParser ) parseListenDirectiveAddress (
0 commit comments