@@ -23,6 +23,9 @@ const (
23
23
24
24
// configVersionFile is the path to the config version configuration file.
25
25
configVersionFile = httpFolder + "/config-version.conf"
26
+
27
+ // httpMatchVarsFile is the path to the http_match pairs configuration file.
28
+ httpMatchVarsFile = httpFolder + "/matches.json"
26
29
)
27
30
28
31
// ConfigFolders is a list of folders where NGINX configuration files are stored.
@@ -52,8 +55,13 @@ func NewGeneratorImpl(plus bool) GeneratorImpl {
52
55
return GeneratorImpl {plus : plus }
53
56
}
54
57
58
+ type executeResult struct {
59
+ dest string
60
+ data []byte
61
+ }
62
+
55
63
// executeFunc is a function that generates NGINX configuration from internal representation.
56
- type executeFunc func (configuration dataplane.Configuration ) []byte
64
+ type executeFunc func (configuration dataplane.Configuration ) []executeResult
57
65
58
66
// Generate generates NGINX configuration files from internal representation.
59
67
// It is the responsibility of the caller to validate the configuration before calling this function.
@@ -66,7 +74,7 @@ func (g GeneratorImpl) Generate(conf dataplane.Configuration) []file.File {
66
74
files = append (files , generatePEM (id , pair .Cert , pair .Key ))
67
75
}
68
76
69
- files = append (files , g .generateHTTPConfig (conf ))
77
+ files = append (files , g .generateHTTPConfig (conf )... )
70
78
71
79
files = append (files , generateConfigVersion (conf .Version ))
72
80
@@ -106,24 +114,33 @@ func generateCertBundleFileName(id dataplane.CertBundleID) string {
106
114
return filepath .Join (secretsFolder , string (id )+ ".crt" )
107
115
}
108
116
109
- func (g GeneratorImpl ) generateHTTPConfig (conf dataplane.Configuration ) file.File {
110
- var c []byte
117
+ func (g GeneratorImpl ) generateHTTPConfig (conf dataplane.Configuration ) []file.File {
118
+ fileBytes := make (map [string ][]byte )
119
+
111
120
for _ , execute := range g .getExecuteFuncs () {
112
- c = append (c , execute (conf )... )
121
+ results := execute (conf )
122
+ for _ , res := range results {
123
+ fileBytes [res .dest ] = append (fileBytes [res .dest ], res .data ... )
124
+ }
113
125
}
114
126
115
- return file.File {
116
- Content : c ,
117
- Path : httpConfigFile ,
118
- Type : file .TypeRegular ,
127
+ files := make ([]file.File , 0 , len (fileBytes ))
128
+ for filepath , bytes := range fileBytes {
129
+ files = append (files , file.File {
130
+ Path : filepath ,
131
+ Content : bytes ,
132
+ Type : file .TypeRegular ,
133
+ })
119
134
}
135
+
136
+ return files
120
137
}
121
138
122
139
func (g GeneratorImpl ) getExecuteFuncs () []executeFunc {
123
140
return []executeFunc {
141
+ executeServers ,
124
142
g .executeUpstreams ,
125
143
executeSplitClients ,
126
- executeServers ,
127
144
executeMaps ,
128
145
}
129
146
}
0 commit comments