package models import ( "time" "opsxloki/pkg/crypto" ) type StorageConfig struct { ID uint `json:"id"` Name string `json:"name"` StorageType string `json:"storageType"` Endpoint string `json:"endpoint"` Bucket string `json:"bucket"` Region string `json:"region"` AccessKey string `json:"accessKey"` SecretKey string `json:"secretKey"` PathPrefix string `json:"pathPrefix"` Insecure bool `json:"insecure"` IsDefault bool `json:"isDefault"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` } func (s *StorageConfig) Sanitized() map[string]interface{} { // AccessKey / SecretKey 在库里是 ENC: 加密存储, // 直接返回会让前端编辑框显示 ENC:xxx 密文。这里统一解密后返回明文, // 前端 Secret Key 仍用密码框(默认掩码,点「显示」才展开), // 便于管理员核对凭据并「测试连接」。 plainAK := crypto.DecryptField(s.AccessKey) plainSK := crypto.DecryptField(s.SecretKey) return map[string]interface{}{ "id": s.ID, "name": s.Name, "storageType": s.StorageType, "endpoint": s.Endpoint, "bucket": s.Bucket, "region": s.Region, "accessKey": plainAK, "secretKey": plainSK, "pathPrefix": s.PathPrefix, "insecure": s.Insecure, "isDefault": s.IsDefault, "hasSecretKey": plainSK != "", "createdAt": s.CreatedAt, "updatedAt": s.UpdatedAt, } }