@@ -57,6 +57,7 @@ type ConfigParser interface {
5757 Parse (ctx context.Context , instance * mpi.Instance ) (* model.NginxConfigContext , error )
5858 FindStubStatusAPI (ctx context.Context , nginxConfigContext * model.NginxConfigContext ) * model.APIDetails
5959 FindPlusAPI (ctx context.Context , nginxConfigContext * model.NginxConfigContext ) * model.APIDetails
60+ FindAllPlusAPIs (ctx context.Context , nginxConfigContext * model.NginxConfigContext ) []* model.APIDetails
6061}
6162
6263var _ ConfigParser = (* NginxConfigParser )(nil )
@@ -144,6 +145,17 @@ func (ncp *NginxConfigParser) FindPlusAPI(
144145 }
145146}
146147
148+ func (ncp * NginxConfigParser ) FindAllPlusAPIs (
149+ ctx context.Context , nginxConfigContext * model.NginxConfigContext ,
150+ ) []* model.APIDetails {
151+ // This function returns the list populated by createNginxConfigContext/Parse
152+ if nginxConfigContext .PlusAPIs == nil {
153+ return []* model.APIDetails {}
154+ }
155+
156+ return nginxConfigContext .PlusAPIs
157+ }
158+
147159//nolint:gocognit,gocyclo,revive,cyclop // cognitive complexity is 51, cyclomatic complexity is 24
148160func (ncp * NginxConfigParser ) createNginxConfigContext (
149161 ctx context.Context ,
@@ -695,6 +707,17 @@ func (ncp *NginxConfigParser) apiDetailsFromLocationDirective(
695707 if locChild .Directive != plusAPIDirective && locChild .Directive != stubStatusAPIDirective {
696708 continue
697709 }
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+ }
720+ }
698721
699722 addresses := ncp .parseAddressFromServerDirective (parent )
700723 path := ncp .parsePathFromLocationDirective (current )
@@ -703,7 +726,7 @@ func (ncp *NginxConfigParser) apiDetailsFromLocationDirective(
703726 for _ , address := range addresses {
704727 details = append (
705728 details ,
706- ncp .createAPIDetails (locationDirectiveName , address , path , caCertLocation , isSSL ),
729+ ncp .createAPIDetails (locationDirectiveName , address , path , caCertLocation , isSSL , isWriteEnabled ),
707730 )
708731 }
709732 }
@@ -714,6 +737,7 @@ func (ncp *NginxConfigParser) apiDetailsFromLocationDirective(
714737
715738func (ncp * NginxConfigParser ) createAPIDetails (
716739 locationDirectiveName , address , path , caCertLocation string , isSSL bool ,
740+ isWriteEnabled bool ,
717741) (details * model.APIDetails ) {
718742 if strings .HasPrefix (address , "unix:" ) {
719743 format := unixStubStatusFormat
@@ -723,18 +747,20 @@ func (ncp *NginxConfigParser) createAPIDetails(
723747 }
724748
725749 details = & model.APIDetails {
726- URL : fmt .Sprintf (format , path ),
727- Listen : address ,
728- Location : path ,
729- Ca : caCertLocation ,
750+ URL : fmt .Sprintf (format , path ),
751+ Listen : address ,
752+ Location : path ,
753+ Ca : caCertLocation ,
754+ WriteEnabled : isWriteEnabled ,
730755 }
731756 } else {
732757 details = & model.APIDetails {
733758 URL : fmt .Sprintf ("%s://%s%s" , map [bool ]string {true : "https" , false : "http" }[isSSL ],
734759 address , path ),
735- Listen : address ,
736- Location : path ,
737- Ca : caCertLocation ,
760+ Listen : address ,
761+ Location : path ,
762+ Ca : caCertLocation ,
763+ WriteEnabled : isWriteEnabled ,
738764 }
739765 }
740766
0 commit comments