| | |
| | | import lombok.Data; |
| | | import org.springframework.boot.context.properties.ConfigurationProperties; |
| | | |
| | | import java.time.Duration; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | public class HttpAuditProperties { |
| | | |
| | | private boolean enabled = true; |
| | | |
| | | /** 1 数据库 2 OpenSearch 3 双写;未填或其它值同 1 */ |
| | | private int logStorageMode = 1; |
| | | |
| | | /** 仅 2、3 使用 */ |
| | | private OpenSearch openSearch = new OpenSearch(); |
| | | |
| | | /** 仅 1、3;无多数据源可省略 */ |
| | | private String datasource = "primary"; |
| | | |
| | | /** 是否注册 /httpAuditRule、/httpAuditLog、/httpAuditSysConfig 等管理接口 */ |
| | | private boolean adminApiEnabled = true; |
| | |
| | | return HttpAuditDbConfigHolder.getPathDescriptions(pathDescriptions); |
| | | } |
| | | |
| | | public int resolveLogStorageMode() { |
| | | if (logStorageMode == 2 || logStorageMode == 3) { |
| | | return logStorageMode; |
| | | } |
| | | return 1; |
| | | } |
| | | |
| | | public boolean usesMysqlLogStorage() { |
| | | int m = resolveLogStorageMode(); |
| | | return m == 1 || m == 3; |
| | | } |
| | | |
| | | public boolean usesOpenSearchLogStorage() { |
| | | int m = resolveLogStorageMode(); |
| | | return m == 2 || m == 3; |
| | | } |
| | | |
| | | @Data |
| | | public static class OpenSearch { |
| | | private List<String> uris = new ArrayList<>(Collections.singletonList("localhost:9200")); |
| | | private String scheme = "http"; |
| | | private String username = ""; |
| | | private String password = ""; |
| | | private String indexName = "http_audit_log"; |
| | | private Duration connectTimeout = Duration.ofSeconds(5); |
| | | private Duration socketTimeout = Duration.ofSeconds(30); |
| | | } |
| | | |
| | | private static List<String> defaultExcludes() { |
| | | List<String> list = new ArrayList<>(); |
| | | list.add("/actuator"); |