This commit is contained in:
WJQSERVER 2024-10-05 23:36:22 +08:00
parent 862b92a1c5
commit eec50879e9
2 changed files with 7 additions and 7 deletions

View file

@ -34,7 +34,7 @@ type Config struct {
} }
type Blacklist struct { type Blacklist struct {
Blacklist map[string][]string `yaml:"blacklist"` Blist map[string][]string `yaml:"blacklist"`
} }
// LoadConfig 从 YAML 配置文件加载配置 // LoadConfig 从 YAML 配置文件加载配置
@ -48,11 +48,11 @@ func LoadConfig(filePath string) (*Config, error) {
// LoadBlacklistConfig 从 YAML 配置文件加载黑名单配置 // LoadBlacklistConfig 从 YAML 配置文件加载黑名单配置
func LoadBlacklistConfig(filePath string) (*Blacklist, error) { func LoadBlacklistConfig(filePath string) (*Blacklist, error) {
var config Blacklist var blacklist Blacklist
if err := loadYAML(filePath, &config); err != nil { if err := loadYAML(filePath, &blacklist); err != nil {
return nil, err return nil, err
} }
return &config, nil return &blacklist, nil
} }
// LoadyamlConfig 从 YAML 配置文件加载配置 // LoadyamlConfig 从 YAML 配置文件加载配置

View file

@ -48,14 +48,14 @@ func NoRouteHandler(cfg *config.Config, blacklist *config.Blacklist) gin.Handler
repo := pathParts[2] repo := pathParts[2]
logw("Blacklist Check > Username: %s, Repo: %s", username, repo) logw("Blacklist Check > Username: %s, Repo: %s", username, repo)
if blacklist.Blacklist == nil { if blacklist.Blist == nil {
logw("Warning: Blacklist map is nil") logw("Warning: Blacklist map is nil")
// 根据需要初始化或处理 // 根据需要初始化或处理
blacklist.Blacklist = make(map[string][]string) blacklist.Blist = make(map[string][]string)
} }
// 检查仓库是否在黑名单中 // 检查仓库是否在黑名单中
if auth.IsBlacklisted(username, repo, blacklist.Blacklist, cfg.Blacklist.Enabled) { if auth.IsBlacklisted(username, repo, blacklist.Blist, cfg.Blacklist.Enabled) {
c.String(http.StatusForbidden, "Access denied: repository is blacklisted.") c.String(http.StatusForbidden, "Access denied: repository is blacklisted.")
logw("Blacklisted repository: %s/%s", username, repo) logw("Blacklisted repository: %s/%s", username, repo)
return return