Basic HTTP Auth (#163).

This commit is contained in:
jimafisk 2023-01-31 15:14:31 -05:00
parent 513e79832a
commit faeb8ae499
4 changed files with 125 additions and 4 deletions

View 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
}