-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dynamic reload of SSL certificates for NGINX Plus (#4764)
ssl certificate lazy loading for nginx plus
- Loading branch information
Showing
41 changed files
with
1,077 additions
and
354 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Package commonhelpers contains template helpers used in v1 and v2 | ||
package commonhelpers | ||
|
||
import ( | ||
"strings" | ||
) | ||
|
||
// MakeSecretPath will return the path to the secret with the base secrets | ||
// path replaced with the given variable | ||
func MakeSecretPath(path, defaultPath, variable string, useVariable bool) string { | ||
if useVariable { | ||
return strings.Replace(path, defaultPath, variable, 1) | ||
} | ||
return path | ||
} |
63 changes: 63 additions & 0 deletions
63
internal/configs/commonhelpers/common_template_helpers_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package commonhelpers | ||
|
||
import ( | ||
"bytes" | ||
"html/template" | ||
"testing" | ||
) | ||
|
||
var helperFunctions = template.FuncMap{ | ||
"makeSecretPath": MakeSecretPath, | ||
} | ||
|
||
func TestMakeSecretPath(t *testing.T) { | ||
t.Parallel() | ||
|
||
tmpl := newMakeSecretPathTemplate(t) | ||
testCases := []struct { | ||
Secret string | ||
Path string | ||
Variable string | ||
Enabled bool | ||
expected string | ||
}{ | ||
{ | ||
Secret: "/etc/nginx/secret/thing.crt", | ||
Path: "/etc/nginx/secret", | ||
Variable: "$secrets_path", | ||
Enabled: true, | ||
expected: "$secrets_path/thing.crt", | ||
}, | ||
{ | ||
Secret: "/etc/nginx/secret/thing.crt", | ||
Path: "/etc/nginx/secret", | ||
Variable: "$secrets_path", | ||
Enabled: false, | ||
expected: "/etc/nginx/secret/thing.crt", | ||
}, | ||
{ | ||
Secret: "/etc/nginx/secret/thing.crt", | ||
expected: "/etc/nginx/secret/thing.crt", | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
var buf bytes.Buffer | ||
err := tmpl.Execute(&buf, tc) | ||
if err != nil { | ||
t.Fatalf("Failed to execute the template %v", err) | ||
} | ||
if buf.String() != tc.expected { | ||
t.Errorf("Template generated wrong config, got '%v' but expected '%v'.", buf.String(), tc.expected) | ||
} | ||
} | ||
} | ||
|
||
func newMakeSecretPathTemplate(t *testing.T) *template.Template { | ||
t.Helper() | ||
tmpl, err := template.New("testTemplate").Funcs(helperFunctions).Parse(`{{makeSecretPath .Secret .Path .Variable .Enabled}}`) | ||
if err != nil { | ||
t.Fatalf("Failed to parse template: %v", err) | ||
} | ||
return tmpl | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.