[MM-64347] Enable System Console UI for AuditSettings by default (#31118)
Co-authored-by: Doug Lauder <wiggin77@warpmail.net>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
f980a538c5
Коммит
b69412d23f
@@ -9296,6 +9296,30 @@
|
||||
"id": "model.config.is_valid.encrypt_sql.app_error",
|
||||
"translation": "Invalid at rest encrypt key for SQL settings. Must be 32 chars or more."
|
||||
},
|
||||
{
|
||||
"id": "model.config.is_valid.experimental_audit_settings.file_max_age_invalid",
|
||||
"translation": "Max File Age of audit logs config must not be negative."
|
||||
},
|
||||
{
|
||||
"id": "model.config.is_valid.experimental_audit_settings.file_max_backups_invalid",
|
||||
"translation": "Maximum File Backups of audit logs config must not be negative."
|
||||
},
|
||||
{
|
||||
"id": "model.config.is_valid.experimental_audit_settings.file_max_queue_size_invalid",
|
||||
"translation": "Maximum File Queue of audit logs config must be greater than zero."
|
||||
},
|
||||
{
|
||||
"id": "model.config.is_valid.experimental_audit_settings.file_max_size_invalid",
|
||||
"translation": "Maximum File Size of audit logs config must be greater than zero."
|
||||
},
|
||||
{
|
||||
"id": "model.config.is_valid.experimental_audit_settings.file_name_empty",
|
||||
"translation": "When audit file logging is enabled, a file name must be specified."
|
||||
},
|
||||
{
|
||||
"id": "model.config.is_valid.experimental_audit_settings.file_name_is_directory",
|
||||
"translation": "The file name must not be a directory."
|
||||
},
|
||||
{
|
||||
"id": "model.config.is_valid.export.directory.app_error",
|
||||
"translation": "Value for Directory should not be empty."
|
||||
|
||||
@@ -1568,6 +1568,47 @@ type ExperimentalAuditSettings struct {
|
||||
Certificate *string `access:"experimental_features"` // telemetry: none
|
||||
}
|
||||
|
||||
func (s *ExperimentalAuditSettings) isValid() *AppError {
|
||||
if *s.FileEnabled {
|
||||
if *s.FileName == "" {
|
||||
return NewAppError("ExperimentalAuditSettings.isValid", "model.config.is_valid.experimental_audit_settings.file_name_empty", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if strings.HasSuffix(*s.FileName, `\`) {
|
||||
return NewAppError("ExperimentalAuditSettings.isValid", "model.config.is_valid.experimental_audit_settings.file_name_is_directory", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if *s.FileMaxSizeMB <= 0 {
|
||||
return NewAppError("ExperimentalAuditSettings.isValid", "model.config.is_valid.experimental_audit_settings.file_max_size_invalid", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if *s.FileMaxAgeDays < 0 {
|
||||
return NewAppError("ExperimentalAuditSettings.isValid", "model.config.is_valid.experimental_audit_settings.file_max_age_invalid", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if *s.FileMaxBackups < 0 {
|
||||
return NewAppError("ExperimentalAuditSettings.isValid", "model.config.is_valid.experimental_audit_settings.file_max_backups_invalid", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if *s.FileMaxQueueSize <= 0 {
|
||||
return NewAppError("ExperimentalAuditSettings.isValid", "model.config.is_valid.experimental_audit_settings.file_max_queue_size_invalid", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
||||
cfg := make(mlog.LoggerConfiguration)
|
||||
err := json.Unmarshal(s.AdvancedLoggingJSON, &cfg)
|
||||
if err != nil {
|
||||
return NewAppError("ExperimentalAuditSettings.isValid", "model.config.is_valid.log.advanced_logging.json", map[string]any{"Error": err}, "", http.StatusBadRequest).Wrap(err)
|
||||
}
|
||||
|
||||
err = cfg.IsValid()
|
||||
if err != nil {
|
||||
return NewAppError("ExperimentalAuditSettings.isValid", "model.config.is_valid.log.advanced_logging.parse", map[string]any{"Error": err}, "", http.StatusBadRequest).Wrap(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *ExperimentalAuditSettings) SetDefaults() {
|
||||
if s.FileEnabled == nil {
|
||||
s.FileEnabled = NewPointer(false)
|
||||
@@ -4040,6 +4081,10 @@ func (o *Config) IsValid() *AppError {
|
||||
return appErr
|
||||
}
|
||||
|
||||
if appErr := o.ExperimentalAuditSettings.isValid(); appErr != nil {
|
||||
return appErr
|
||||
}
|
||||
|
||||
if appErr := o.LocalizationSettings.isValid(); appErr != nil {
|
||||
return appErr
|
||||
}
|
||||
|
||||
@@ -1402,6 +1402,8 @@ func TestLdapSettingsIsValid(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLogSettingsIsValid(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
for name, test := range map[string]struct {
|
||||
LogSettings LogSettings
|
||||
ExpectError bool
|
||||
@@ -2163,6 +2165,115 @@ func TestConfigDefaultConnectedWorkspacesSettings(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestExperimentalAuditSettingsIsValid(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
for name, test := range map[string]struct {
|
||||
ExperimentalAuditSettings ExperimentalAuditSettings
|
||||
ExpectError bool
|
||||
}{
|
||||
"empty settings": {
|
||||
ExperimentalAuditSettings: ExperimentalAuditSettings{},
|
||||
ExpectError: false,
|
||||
},
|
||||
"file enabled with empty filename": {
|
||||
ExperimentalAuditSettings: ExperimentalAuditSettings{
|
||||
FileEnabled: NewPointer(true),
|
||||
FileName: NewPointer(""),
|
||||
},
|
||||
ExpectError: true,
|
||||
},
|
||||
"file enabled with valid filename": {
|
||||
ExperimentalAuditSettings: ExperimentalAuditSettings{
|
||||
FileEnabled: NewPointer(true),
|
||||
FileName: NewPointer("audit.log"),
|
||||
FileMaxSizeMB: NewPointer(100),
|
||||
FileMaxAgeDays: NewPointer(5),
|
||||
FileMaxBackups: NewPointer(10),
|
||||
FileMaxQueueSize: NewPointer(1000),
|
||||
},
|
||||
ExpectError: false,
|
||||
},
|
||||
"invalid file max size": {
|
||||
ExperimentalAuditSettings: ExperimentalAuditSettings{
|
||||
FileEnabled: NewPointer(true),
|
||||
FileName: NewPointer("audit.log"),
|
||||
FileMaxSizeMB: NewPointer(0),
|
||||
},
|
||||
ExpectError: true,
|
||||
},
|
||||
"negative file max size": {
|
||||
ExperimentalAuditSettings: ExperimentalAuditSettings{
|
||||
FileEnabled: NewPointer(true),
|
||||
FileName: NewPointer("audit.log"),
|
||||
FileMaxSizeMB: NewPointer(-10),
|
||||
},
|
||||
ExpectError: true,
|
||||
},
|
||||
"negative file max age": {
|
||||
ExperimentalAuditSettings: ExperimentalAuditSettings{
|
||||
FileEnabled: NewPointer(true),
|
||||
FileName: NewPointer("audit.log"),
|
||||
FileMaxSizeMB: NewPointer(100),
|
||||
FileMaxAgeDays: NewPointer(-5),
|
||||
},
|
||||
ExpectError: true,
|
||||
},
|
||||
"negative file max backups": {
|
||||
ExperimentalAuditSettings: ExperimentalAuditSettings{
|
||||
FileEnabled: NewPointer(true),
|
||||
FileName: NewPointer("audit.log"),
|
||||
FileMaxSizeMB: NewPointer(100),
|
||||
FileMaxAgeDays: NewPointer(5),
|
||||
FileMaxBackups: NewPointer(-10),
|
||||
},
|
||||
ExpectError: true,
|
||||
},
|
||||
"zero file max queue size": {
|
||||
ExperimentalAuditSettings: ExperimentalAuditSettings{
|
||||
FileEnabled: NewPointer(true),
|
||||
FileName: NewPointer("audit.log"),
|
||||
FileMaxSizeMB: NewPointer(100),
|
||||
FileMaxAgeDays: NewPointer(5),
|
||||
FileMaxBackups: NewPointer(10),
|
||||
FileMaxQueueSize: NewPointer(0),
|
||||
},
|
||||
ExpectError: true,
|
||||
},
|
||||
"negative file max queue size": {
|
||||
ExperimentalAuditSettings: ExperimentalAuditSettings{
|
||||
FileEnabled: NewPointer(true),
|
||||
FileName: NewPointer("audit.log"),
|
||||
FileMaxSizeMB: NewPointer(100),
|
||||
FileMaxAgeDays: NewPointer(5),
|
||||
FileMaxBackups: NewPointer(10),
|
||||
FileMaxQueueSize: NewPointer(-1000),
|
||||
},
|
||||
ExpectError: true,
|
||||
},
|
||||
"AdvancedLoggingJSON has JSON error ": {
|
||||
ExperimentalAuditSettings: ExperimentalAuditSettings{
|
||||
AdvancedLoggingJSON: json.RawMessage(`
|
||||
{
|
||||
"foo": "bar",
|
||||
`),
|
||||
},
|
||||
ExpectError: true,
|
||||
},
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
test.ExperimentalAuditSettings.SetDefaults()
|
||||
|
||||
appErr := test.ExperimentalAuditSettings.isValid()
|
||||
if test.ExpectError {
|
||||
require.NotNil(t, appErr)
|
||||
} else {
|
||||
require.Nil(t, appErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterConfig(t *testing.T) {
|
||||
t.Run("should clear default values", func(t *testing.T) {
|
||||
cfg := &Config{}
|
||||
|
||||
@@ -93,7 +93,7 @@ func (f *FeatureFlags) SetDefaults() {
|
||||
f.ChannelBookmarks = true
|
||||
f.WebSocketEventScope = true
|
||||
f.NotificationMonitoring = true
|
||||
f.ExperimentalAuditSettingsSystemConsoleUI = false
|
||||
f.ExperimentalAuditSettingsSystemConsoleUI = true
|
||||
f.CustomProfileAttributes = true
|
||||
f.AttributeBasedAccessControl = true
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user