Wildcards #2
@ -26,8 +26,10 @@ import (
|
|||||||
func handleSubdomain(domain, cname, path, giteaUrl, defaultCsp string, giteaClient *repo.GiteaClient, w http.ResponseWriter) {
|
func handleSubdomain(domain, cname, path, giteaUrl, defaultCsp string, giteaClient *repo.GiteaClient, w http.ResponseWriter) {
|
||||||
username := ""
|
username := ""
|
||||||
if cname != "" {
|
if cname != "" {
|
||||||
|
// If we are accessed via a CNAME, then CNAME contains our <user>.<pages domain> value.
|
||||||
username = strings.Split(cname, ".")[0]
|
username = strings.Split(cname, ".")[0]
|
||||||
} else {
|
} else {
|
||||||
|
// If we are directly accessed, then domain contains our <user>.<pages domain> value.
|
||||||
username = strings.Split(domain, ".")[0]
|
username = strings.Split(domain, ".")[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,10 +42,6 @@ func makeCSPCacheKey(username, repositoryName string) string {
|
|||||||
return username + ":" + repositoryName
|
return username + ":" + repositoryName
|
||||||
}
|
}
|
||||||
|
|
||||||
// / Try to find the repository with name @reponame of the user @username. If @cname
|
|
||||||
// / is not "", then it also verifies that the repository contains a "CNAME" with
|
|
||||||
// / the value of @cname as its content. @host, @domain, and @path are passed for
|
|
||||||
// / caching on success.
|
|
||||||
func lookupRepositoryAndCache(username, reponame, branchName, host, domain, path, cname string, giteaClient *GiteaClient) (*Repository, error) {
|
func lookupRepositoryAndCache(username, reponame, branchName, host, domain, path, cname string, giteaClient *GiteaClient) (*Repository, error) {
|
||||||
log.Debugf("CNAME: %s", cname)
|
log.Debugf("CNAME: %s", cname)
|
||||||
log.Debugf("Looking up repository %s/%s", username, reponame)
|
log.Debugf("Looking up repository %s/%s", username, reponame)
|
||||||
@ -85,8 +81,8 @@ func lookupRepositoryAndCache(username, reponame, branchName, host, domain, path
|
|||||||
)
|
)
|
||||||
|
|
||||||
log.Debugf("CNAME Content: %s", cnameContent)
|
log.Debugf("CNAME Content: %s", cnameContent)
|
||||||
if cnameContent != cname {
|
if cnameContent != host {
|
||||||
log.Warnf("CNAME mismatch: Repo '%s', CNAME '%s'", cnameContent, cname)
|
log.Warnf("CNAME mismatch: Repo '%s', Host '%s'", cnameContent, host)
|
||||||
return nil, errors.New("CNAME mismatch")
|
return nil, errors.New("CNAME mismatch")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -103,6 +99,8 @@ func lookupRepositoryAndCache(username, reponame, branchName, host, domain, path
|
|||||||
return &repo, nil
|
return &repo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// host is the domain name we're accessed from. cname is the domain that host is pointing
|
||||||
|
// if, if we're accessed via a CNAME. If not, then cname is "".
|
||||||
func RepoFromPath(username, host, cname, path string, giteaClient *GiteaClient) (*Repository, string, error) {
|
func RepoFromPath(username, host, cname, path string, giteaClient *GiteaClient) (*Repository, string, error) {
|
||||||
domain := host
|
domain := host
|
||||||
|
|
||||||
@ -117,11 +115,11 @@ func RepoFromPath(username, host, cname, path string, giteaClient *GiteaClient)
|
|||||||
// Allow specifying the repository name in the TXT record
|
// Allow specifying the repository name in the TXT record
|
||||||
reponame := ""
|
reponame := ""
|
||||||
if cname != "" {
|
if cname != "" {
|
||||||
repoLookup, err := giteaClient.lookupRepoTXT(cname)
|
repoLookup, err := giteaClient.lookupRepoTXT(host)
|
||||||
if err == nil && repoLookup != "" {
|
if err == nil && repoLookup != "" {
|
||||||
log.Infof(
|
log.Infof(
|
||||||
"TXT lookup for %s resulted in choosing repository %s",
|
"TXT lookup for %s resulted in choosing repository %s",
|
||||||
cname,
|
host,
|
||||||
repoLookup,
|
repoLookup,
|
||||||
)
|
)
|
||||||
reponame = repoLookup
|
reponame = repoLookup
|
||||||
|
Loading…
Reference in New Issue
Block a user