GET audit config for database
()
| 846 | |
| 847 | // GET audit config for database |
| 848 | func (h *handler) handleGetDbAuditConfig() error { |
| 849 | h.assertAdminOnly() |
| 850 | |
| 851 | showOnlyFilterable := h.getBoolQuery("filterable") |
| 852 | verbose := h.getBoolQuery("verbose") |
| 853 | |
| 854 | var ( |
| 855 | etagVersion string |
| 856 | dbAuditEnabled bool |
| 857 | dbAuditDisabledUsers []base.AuditLoggingPrincipal |
| 858 | dbAuditDisabledRoles []base.AuditLoggingPrincipal |
| 859 | enabledEvents = make(map[base.AuditID]struct{}) |
| 860 | ) |
| 861 | |
| 862 | if h.server.BootstrapContext.Connection != nil { |
| 863 | found, dbConfig, err := h.server.fetchDatabase(h.ctx(), h.db.Name) |
| 864 | if err != nil { |
| 865 | return err |
| 866 | } |
| 867 | |
| 868 | if !found { |
| 869 | return base.HTTPErrorf(http.StatusNotFound, "database config not found") |
| 870 | } |
| 871 | |
| 872 | etagVersion = dbConfig.Version |
| 873 | |
| 874 | runtimeConfig, err := MergeDatabaseConfigWithDefaults(h.server.Config, &dbConfig.DbConfig) |
| 875 | if err != nil { |
| 876 | return err |
| 877 | } |
| 878 | |
| 879 | // grab runtime version of config, so that we can see what events would be enabled |
| 880 | if runtimeConfig.Logging != nil && runtimeConfig.Logging.Audit != nil { |
| 881 | dbAuditEnabled = base.ValDefault(runtimeConfig.Logging.Audit.Enabled, false) |
| 882 | if runtimeConfig.Logging.Audit.EnabledEvents != nil { |
| 883 | for _, event := range *runtimeConfig.Logging.Audit.EnabledEvents { |
| 884 | enabledEvents[base.AuditID(event)] = struct{}{} |
| 885 | } |
| 886 | } |
| 887 | dbAuditDisabledUsers = runtimeConfig.Logging.Audit.DisabledUsers |
| 888 | dbAuditDisabledRoles = runtimeConfig.Logging.Audit.DisabledRoles |
| 889 | } |
| 890 | } else { |
| 891 | return base.HTTPErrorf(http.StatusServiceUnavailable, "audit config not available in non-persistent mode") |
| 892 | } |
| 893 | |
| 894 | events := make(map[string]any, len(base.AuditEvents)) |
| 895 | for id, descriptor := range base.AuditEvents { |
| 896 | // skip global and non-filterable events |
| 897 | if descriptor.IsGlobalEvent || (showOnlyFilterable && !descriptor.FilteringPermitted) { |
| 898 | continue |
| 899 | } |
| 900 | |
| 901 | idStr := id.String() |
| 902 | _, eventEnabled := enabledEvents[id] |
| 903 | |
| 904 | if verbose { |
| 905 | events[idStr] = HandleDbAuditConfigBodyVerboseEvent{ |
nothing calls this directly
no test coverage detected