- .gitea/workflows/ci.yml:后端 gofmt/vet/test + 前端 lint/test/build 双 job 门禁 - vitest + @testing-library + jsdom 落地,14 个命脉用例:useListQuery 乱序丢弃/卸载中止、 http.ts 401 单飞刷新+队列重放+失败登出+silent 直拒、审计防抖、StepDeploy 部署目标、query-utils - 版本注入断裂修复:main 补 buildTime/gitCommit 符号,build.sh/Dockerfile 注入 main.version, /health 返回真实版本,前端 package.json 版本对齐 2.0.0 - gofmt 清零(8 个存量未格式化文件)
53 lines
1.6 KiB
Go
53 lines
1.6 KiB
Go
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:<ciphertext> 加密存储。
|
|
//
|
|
// 安全约定:
|
|
// - 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,
|
|
}
|
|
}
|