(isReplace bool, existingAuditConfig *DbAuditLoggingConfig, requestAuditConfig *HandleDbAuditConfigBody, eventsToChange map[base.AuditID]bool)
| 1011 | } |
| 1012 | |
| 1013 | func mutateConfigFromDbAuditConfigBody(isReplace bool, existingAuditConfig *DbAuditLoggingConfig, requestAuditConfig *HandleDbAuditConfigBody, eventsToChange map[base.AuditID]bool) { |
| 1014 | if isReplace { |
| 1015 | existingAuditConfig.Enabled = requestAuditConfig.Enabled |
| 1016 | existingAuditConfig.DisabledUsers = requestAuditConfig.DisabledUsers |
| 1017 | existingAuditConfig.DisabledRoles = requestAuditConfig.DisabledRoles |
| 1018 | |
| 1019 | // we don't need to do anything to "disable" events, other than not enable them |
| 1020 | existingAuditConfig.EnabledEvents = func() *[]uint { |
| 1021 | enabledEvents := make([]uint, 0) |
| 1022 | for event, shouldEnable := range eventsToChange { |
| 1023 | if shouldEnable { |
| 1024 | enabledEvents = append(enabledEvents, uint(event)) |
| 1025 | } |
| 1026 | } |
| 1027 | return &enabledEvents |
| 1028 | }() |
| 1029 | } else { |
| 1030 | if requestAuditConfig.Enabled != nil { |
| 1031 | existingAuditConfig.Enabled = requestAuditConfig.Enabled |
| 1032 | } |
| 1033 | if requestAuditConfig.DisabledUsers != nil { |
| 1034 | existingAuditConfig.DisabledUsers = requestAuditConfig.DisabledUsers |
| 1035 | } |
| 1036 | if requestAuditConfig.DisabledRoles != nil { |
| 1037 | existingAuditConfig.DisabledRoles = requestAuditConfig.DisabledRoles |
| 1038 | } |
| 1039 | if len(eventsToChange) > 0 { |
| 1040 | if existingAuditConfig.EnabledEvents == nil { |
| 1041 | // initialize to non-nil set of defaults before modifying from request |
| 1042 | existingAuditConfig.EnabledEvents = &base.DefaultDbAuditEventIDs |
| 1043 | } |
| 1044 | // build EnabledEvents back up in temp based on request - avoids mutating slice in-place during iteration |
| 1045 | // slice[:0] reuses underlying array to avoid alloc of a new slice |
| 1046 | newEnabledEvents := (*existingAuditConfig.EnabledEvents)[:0] |
| 1047 | for _, event := range *existingAuditConfig.EnabledEvents { |
| 1048 | if _, ok := eventsToChange[base.AuditID(event)]; !ok { |
| 1049 | // existing enabled event and not in request - don't change |
| 1050 | newEnabledEvents = append(newEnabledEvents, event) |
| 1051 | } |
| 1052 | } |
| 1053 | for id, enabled := range eventsToChange { |
| 1054 | if enabled { |
| 1055 | newEnabledEvents = append(newEnabledEvents, uint(id)) |
| 1056 | } |
| 1057 | } |
| 1058 | *existingAuditConfig.EnabledEvents = newEnabledEvents |
| 1059 | } |
| 1060 | } |
| 1061 | } |
| 1062 | |
| 1063 | // GET collection config sync function |
| 1064 | func (h *handler) handleGetCollectionConfigSync() error { |
no test coverage detected