From ed6cb006ab0bb5bb94d61c18c3ae69642bae1fa1 Mon Sep 17 00:00:00 2001 From: JU4N98 Date: Fri, 13 Oct 2023 14:59:18 -0300 Subject: [PATCH] Adds jsonFilename config and its warning and error. Signed-off-by: JU4N98 --- pkg/sidecar/config.go | 13 +++++++++++-- pkg/sidecar/config_test.go | 29 ++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/pkg/sidecar/config.go b/pkg/sidecar/config.go index 9683a44e..9cf1732e 100644 --- a/pkg/sidecar/config.go +++ b/pkg/sidecar/config.go @@ -32,8 +32,9 @@ type Config struct { RenewSignalDeprecated string `hcl:"renewSignal"` // JWT configuration - JwtAudience string `hcl:"audience"` - JSONFilename string `hcl:"json_filename"` + JwtAudience string `hcl:"audience"` + JSONFilename string `hcl:"json_filename"` + JSONFilenameDeprecated string `hcl:"jsonFilename"` // TODO: is there a reason for this to be exposed? and inside of config? ReloadExternalProcess func() error @@ -119,6 +120,14 @@ func ValidateConfig(c *Config) error { c.RenewSignal = c.RenewSignalDeprecated } + if c.JSONFilenameDeprecated != "" { + if c.JSONFilename != "" { + return errors.New("use of json_filename and jsonFilename found, use only json_filename") + } + c.Log.Warn(getWarning("jsonFilename", "json_filename")) + c.JSONFilename = c.JSONFilenameDeprecated + } + switch { case c.SvidFileName == "": return errors.New("svid_file_name is required") diff --git a/pkg/sidecar/config_test.go b/pkg/sidecar/config_test.go index 4ded5581..5aa02585 100644 --- a/pkg/sidecar/config_test.go +++ b/pkg/sidecar/config_test.go @@ -159,7 +159,19 @@ func TestValidateConfig(t *testing.T) { }, expectError: "use of renew_signal and renewSignal found, use only renew_signal", }, - + { + name: "Using JSONFilenameDeprecated", + config: &Config{ + AgentAddress: "path", + SvidFileName: "cert.pem", + SvidKeyFileName: "key.pem", + SvidBundleFileName: "bundle.pem", + RenewSignal: "SIGHUP", + JSONFilename: "cert.json", + JSONFilenameDeprecated: "cert.json", + }, + expectError: "use of jsonFilename and json_filename found, use only json_filename", + }, // Deprecated field warning: { name: "Using AgentAddressDeprecated", @@ -267,6 +279,21 @@ func TestValidateConfig(t *testing.T) { Message: "renewSignal will be deprecated, should be used as renew_signal", }}, }, + { + name: "Using JSONFilenameDeprecated", + config: &Config{ + AgentAddress: "path", + SvidFileName: "cert.pem", + SvidKeyFileName: "key.pem", + SvidBundleFileName: "bundle.pem", + RenewSignal: "SIGHUP", + JSONFilenameDeprecated: "cert.json", + }, + expectLogs: []shortEntry{{ + Level: logrus.WarnLevel, + Message: "jsonFilename will be deprecated, should be used as json_filename", + }}, + }, } { t.Run(tt.name, func(t *testing.T) { log, hook := test.NewNullLogger()