This commit is contained in:
WJQSERVER 2024-10-05 22:42:43 +08:00
parent 822c08d4c0
commit 89e6be7709
10 changed files with 173 additions and 40 deletions

View file

@ -11,7 +11,7 @@ var logw = logger.Logw
func AuthHandler(c *gin.Context, cfg *config.Config) bool {
// 如果身份验证未启用,直接返回 true
if !cfg.Auth {
if !cfg.Auth.Enabled {
logw("auth PASSED")
return true
}
@ -26,10 +26,24 @@ func AuthHandler(c *gin.Context, cfg *config.Config) bool {
return false
}
isValid := authToken == cfg.AuthToken
isValid := authToken == cfg.Auth.AuthToken
if !isValid {
logw("auth FAILED: invalid auth_token: %s", authToken)
}
return isValid
}
func IsBlacklisted(username, repo string, blacklist map[string][]string, enabled bool) bool {
if !enabled {
return false
}
if repos, ok := blacklist[username]; ok {
for _, blacklistedRepo := range repos {
if blacklistedRepo == repo {
return true
}
}
}
return false
}