Skip to content

Commit

Permalink
Adds jsonFilename config and its warning and error.
Browse files Browse the repository at this point in the history
Signed-off-by: JU4N98 <[email protected]>
  • Loading branch information
JU4N98 committed Oct 13, 2023
1 parent bc2d054 commit ed6cb00
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
13 changes: 11 additions & 2 deletions pkg/sidecar/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
29 changes: 28 additions & 1 deletion pkg/sidecar/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit ed6cb00

Please sign in to comment.