package models import ( "time" "lokistack/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{} { // 凭据在库里是 ENC: 加密存储。 // // 安全约定: // - AccessKey 解密后明文返回(管理员需要核对自己用的是哪个 AK) // - SecretKey 一律不返回明文,只给 hasSecretKey 标记 // —— 避免任何登录用户点一下「显示」按钮就能拿到 SK。 // 编辑时前端留空表示「不修改」,测试连接由后端用库里保存的 SK 兜底。 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": "", "pathPrefix": s.PathPrefix, "insecure": s.Insecure, "isDefault": s.IsDefault, "hasSecretKey": plainSK != "", "createdAt": s.CreatedAt, "updatedAt": s.UpdatedAt, } }