VAULT-18160: Audit - options and defaults (#22295)

* options for syslog

* fix bug in default value for HMACAccessor

* backend device cleanup

* socket backend options update

* options: prefix removed check, added default file mode

* fix option setting for elision

* fix test for prefix and whitespace
This commit is contained in:
Peter Wilson
2023-09-11 09:41:29 +01:00
committed by GitHub
parent 1d72ac5278
commit ae774b93d3
8 changed files with 120 additions and 129 deletions

View File

@@ -32,12 +32,15 @@ type options struct {
// getDefaultOptions returns Options with their default values.
func getDefaultOptions() options {
fileMode := os.FileMode(0o600)
return options{
withNow: time.Now(),
withFacility: "AUTH",
withTag: "vault",
withSocketType: "tcp",
withMaxDuration: 2 * time.Second,
withFileMode: &fileMode,
}
}
@@ -110,11 +113,7 @@ func WithNow(now time.Time) Option {
// WithFacility provides an Option to represent a 'facility' for a syslog sink.
func WithFacility(facility string) Option {
return func(o *options) error {
facility = strings.TrimSpace(facility)
if facility != "" {
o.withFacility = facility
}
o.withFacility = facility
return nil
}
@@ -123,11 +122,7 @@ func WithFacility(facility string) Option {
// WithTag provides an Option to represent a 'tag' for a syslog sink.
func WithTag(tag string) Option {
return func(o *options) error {
tag = strings.TrimSpace(tag)
if tag != "" {
o.withTag = tag
}
o.withTag = tag
return nil
}

View File

@@ -205,7 +205,7 @@ func TestOptions_WithFacility(t *testing.T) {
},
"whitespace": {
Value: " ",
ExpectedValue: "",
ExpectedValue: " ",
},
"value": {
Value: "juan",
@@ -213,7 +213,7 @@ func TestOptions_WithFacility(t *testing.T) {
},
"spacey-value": {
Value: " juan ",
ExpectedValue: "juan",
ExpectedValue: " juan ",
},
}
@@ -243,7 +243,7 @@ func TestOptions_WithTag(t *testing.T) {
},
"whitespace": {
Value: " ",
ExpectedValue: "",
ExpectedValue: " ",
},
"value": {
Value: "juan",
@@ -251,7 +251,7 @@ func TestOptions_WithTag(t *testing.T) {
},
"spacey-value": {
Value: " juan ",
ExpectedValue: "juan",
ExpectedValue: " juan ",
},
}