| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- package audit
- import (
- "context"
- "strconv"
- "udeServer/internal/model"
- )
- // FileConfigManager holds the MinIO connection settings loaded from t_config.
- type FileConfigManager struct {
- endpoint string
- bucket string
- accessKey string
- secretKey string
- useSSL bool
- }
- // LogConfigManager holds the audit logging settings loaded from t_config.
- type LogConfigManager struct {
- LogRecordLevel string
- ArchiveThreshold int64
- HmacSecret string
- }
- // Reload reads the whole t_config table and extracts the audit-related
- // settings. It never fails hard: a missing table or empty rows simply
- // yields zero-valued managers (the callers degrade gracefully).
- func Reload(configModel model.TConfigModel) (fileConfig FileConfigManager, logConfig LogConfigManager) {
- configList, err := configModel.FindAll(context.Background())
- if err != nil {
- return
- }
- var useSSLStr string
- handlers := map[string]func(string){
- ItemFileEndpoint: func(v string) { fileConfig.endpoint = v },
- ItemFileBucket: func(v string) { fileConfig.bucket = v },
- ItemFileAccessKey: func(v string) { fileConfig.accessKey = v },
- ItemFileSecretKey: func(v string) { fileConfig.secretKey = v },
- ItemFileUseSsl: func(v string) { useSSLStr = v },
- ItemLogRecordLevel: func(v string) { logConfig.LogRecordLevel = v },
- ItemArchiveThresh: func(v string) {
- count, _ := strconv.ParseInt(v, 10, 64)
- logConfig.ArchiveThreshold = count
- },
- ItemLogHmacSecret: func(v string) { logConfig.HmacSecret = v },
- }
- for _, v := range configList {
- if handler, ok := handlers[v.ConfigItem]; ok {
- handler(v.ConfigValue)
- }
- }
- fileConfig.useSSL = useSSLStr == "1"
- return
- }
- // GetGlobalConfig reloads the dynamic configuration and (re)builds the
- // global MinIO client when needed. It returns the currently loaded client
- // (nil when configuration is incomplete/failed) and the log settings.
- func GetGlobalConfig(configModel model.TConfigModel) (*MinioClient, *LogConfigManager) {
- fileConfig, logConfig := Reload(configModel)
- ReloadMinioClient(fileConfig)
- return GetMinioClient(), &LogConfigManager{
- LogRecordLevel: logConfig.LogRecordLevel,
- ArchiveThreshold: logConfig.ArchiveThreshold,
- HmacSecret: logConfig.HmacSecret,
- }
- }
|