Skip to content

Commit b37f578

Browse files
author
Kate Osborn
committed
Make Includes a list of strings
1 parent 4ca2334 commit b37f578

File tree

4 files changed

+23
-48
lines changed

4 files changed

+23
-48
lines changed

internal/mode/static/nginx/config/http/config.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ type Server struct {
55
SSL *SSL
66
ServerName string
77
Locations []Location
8-
Includes []Include
8+
Includes []string
99
Port int32
1010
IsDefaultHTTP bool
1111
IsDefaultSSL bool
@@ -23,7 +23,7 @@ type Location struct {
2323
Return *Return
2424
ResponseHeaders ResponseHeaders
2525
Rewrites []string
26-
Includes []Include
26+
Includes []string
2727
GRPC bool
2828
}
2929

@@ -106,8 +106,3 @@ type ProxySSLVerify struct {
106106
TrustedCertificate string
107107
Name string
108108
}
109-
110-
// Include holds all the files to include using the include directive.
111-
type Include struct {
112-
Filename string
113-
}

internal/mode/static/nginx/config/servers.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,15 @@ func createAdditionFileName(addition *dataplane.Addition) string {
131131
return fmt.Sprintf("%s/%s.conf", includesFolder, addition.Identifier)
132132
}
133133

134-
func createIncludes(additions []*dataplane.Addition) []http.Include {
134+
func createIncludes(additions []*dataplane.Addition) []string {
135135
if len(additions) == 0 {
136136
return nil
137137
}
138138

139-
includes := make([]http.Include, 0, len(additions))
139+
includes := make([]string, 0, len(additions))
140140

141141
for _, addition := range additions {
142-
includes = append(includes, http.Include{
143-
Filename: createAdditionFileName(addition),
144-
})
142+
includes = append(includes, createAdditionFileName(addition))
145143
}
146144

147145
return includes
@@ -281,7 +279,7 @@ func createLocations(server *dataplane.VirtualServer, serverID int) ([]http.Loca
281279
return locs, matchPairs, grpc
282280
}
283281

284-
func updateLocationsForIncludes(locations []http.Location, includes []http.Include) []http.Location {
282+
func updateLocationsForIncludes(locations []http.Location, includes []string) []http.Location {
285283
for i := range locations {
286284
locations[i].Includes = includes
287285
}

internal/mode/static/nginx/config/servers_template.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ server {
3333
server_name {{ $s.ServerName }};
3434
3535
{{- range $i := $s.Includes }}
36-
include {{ $i.Filename }};
36+
include {{ $i }};
3737
{{ end -}}
3838
3939
{{ range $l := $s.Locations }}
4040
location {{ $l.Path }} {
4141
{{- range $i := $l.Includes }}
42-
include {{ $i.Filename }};
42+
include {{ $i }};
4343
{{- end -}}
4444
4545
{{ range $r := $l.Rewrites }}

internal/mode/static/nginx/config/servers_test.go

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,20 +1000,16 @@ func TestCreateServers(t *testing.T) {
10001000
Path: "= /addition-path-only-match",
10011001
ProxyPass: "http://test_foo_80$request_uri",
10021002
ProxySetHeaders: httpBaseHeaders,
1003-
Includes: []http.Include{
1004-
{
1005-
Filename: includesFolder + "/path-only-match-addition.conf",
1006-
},
1003+
Includes: []string{
1004+
includesFolder + "/path-only-match-addition.conf",
10071005
},
10081006
},
10091007
{
10101008
Path: "@rule17-route0",
10111009
ProxyPass: "http://test_foo_80$request_uri",
10121010
ProxySetHeaders: httpBaseHeaders,
1013-
Includes: []http.Include{
1014-
{
1015-
Filename: includesFolder + "/match-addition.conf",
1016-
},
1011+
Includes: []string{
1012+
includesFolder + "/match-addition.conf",
10171013
},
10181014
},
10191015
{
@@ -1035,13 +1031,9 @@ func TestCreateServers(t *testing.T) {
10351031
Locations: getExpectedLocations(false),
10361032
Port: 8080,
10371033
GRPC: true,
1038-
Includes: []http.Include{
1039-
{
1040-
Filename: includesFolder + "/server-addition-1.conf",
1041-
},
1042-
{
1043-
Filename: includesFolder + "/server-addition-2.conf",
1044-
},
1034+
Includes: []string{
1035+
includesFolder + "/server-addition-1.conf",
1036+
includesFolder + "/server-addition-2.conf",
10451037
},
10461038
},
10471039
{
@@ -1057,13 +1049,9 @@ func TestCreateServers(t *testing.T) {
10571049
Locations: getExpectedLocations(true),
10581050
Port: 8443,
10591051
GRPC: true,
1060-
Includes: []http.Include{
1061-
{
1062-
Filename: includesFolder + "/server-addition-1.conf",
1063-
},
1064-
{
1065-
Filename: includesFolder + "/server-addition-3.conf",
1066-
},
1052+
Includes: []string{
1053+
includesFolder + "/server-addition-1.conf",
1054+
includesFolder + "/server-addition-3.conf",
10671055
},
10681056
},
10691057
}
@@ -2362,7 +2350,7 @@ func TestCreateIncludes(t *testing.T) {
23622350
tests := []struct {
23632351
name string
23642352
additions []*dataplane.Addition
2365-
includes []http.Include
2353+
includes []string
23662354
}{
23672355
{
23682356
name: "no additions",
@@ -2385,16 +2373,10 @@ func TestCreateIncludes(t *testing.T) {
23852373
Identifier: "three",
23862374
},
23872375
},
2388-
includes: []http.Include{
2389-
{
2390-
Filename: includesFolder + "/one.conf",
2391-
},
2392-
{
2393-
Filename: includesFolder + "/two.conf",
2394-
},
2395-
{
2396-
Filename: includesFolder + "/three.conf",
2397-
},
2376+
includes: []string{
2377+
includesFolder + "/one.conf",
2378+
includesFolder + "/two.conf",
2379+
includesFolder + "/three.conf",
23982380
},
23992381
},
24002382
}

0 commit comments

Comments
 (0)