mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-04-25 06:16:58 +00:00
Basic HTTP Auth (#163).
This commit is contained in:
parent
513e79832a
commit
faeb8ae499
4 changed files with 125 additions and 4 deletions
33
server/handler/handler_auth.go
Normal file
33
server/handler/handler_auth.go
Normal file
|
@ -0,0 +1,33 @@
|
|||
package handler
|
||||
|
||||
import (
|
||||
"codeberg.org/codeberg/pages/server/cache"
|
||||
"codeberg.org/codeberg/pages/server/context"
|
||||
"codeberg.org/codeberg/pages/server/dns"
|
||||
"codeberg.org/codeberg/pages/server/gitea"
|
||||
"codeberg.org/codeberg/pages/server/upstream"
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
func handleAuth(log zerolog.Logger, ctx *context.Context, giteaClient *gitea.Client,
|
||||
mainDomainSuffix string,
|
||||
trimmedHost string,
|
||||
dnsLookupCache, authCache cache.SetGetKey,
|
||||
) []string {
|
||||
// Get credentials for a given branch/repo/owner
|
||||
targetOwner, targetRepo, targetBranch := dns.GetTargetFromDNS(trimmedHost, mainDomainSuffix, dnsLookupCache)
|
||||
var credentials []string
|
||||
canonicalLink := false
|
||||
|
||||
// Try to use the given repo on the given branch or the default branch
|
||||
log.Debug().Msg("auth preparations, trying to get credentials")
|
||||
if targetOpt, works := tryBranch(log, ctx, giteaClient, &upstream.Options{
|
||||
TargetOwner: targetOwner,
|
||||
TargetRepo: targetRepo,
|
||||
TargetBranch: targetBranch,
|
||||
}, canonicalLink); works {
|
||||
credentials = targetOpt.CheckAuth(giteaClient, authCache)
|
||||
}
|
||||
|
||||
return credentials
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue