From e628ec7ecf00633398dc67067ed12809a7bd28bb Mon Sep 17 00:00:00 2001 From: "Alexander \"PapaTutuWawa" Date: Sat, 6 Jan 2024 21:26:09 +0100 Subject: [PATCH] What is a CNAME? --- cmd/rio/main.go | 2 ++ internal/repo/repo.go | 14 ++++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cmd/rio/main.go b/cmd/rio/main.go index 339f195..69858ab 100644 --- a/cmd/rio/main.go +++ b/cmd/rio/main.go @@ -26,8 +26,10 @@ import ( func handleSubdomain(domain, cname, path, giteaUrl, defaultCsp string, giteaClient *repo.GiteaClient, w http.ResponseWriter) { username := "" if cname != "" { + // If we are accessed via a CNAME, then CNAME contains our . value. username = strings.Split(cname, ".")[0] } else { + // If we are directly accessed, then domain contains our . value. username = strings.Split(domain, ".")[0] } diff --git a/internal/repo/repo.go b/internal/repo/repo.go index c879be8..8439bca 100644 --- a/internal/repo/repo.go +++ b/internal/repo/repo.go @@ -42,10 +42,6 @@ func makeCSPCacheKey(username, repositoryName string) string { 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) { log.Debugf("CNAME: %s", cname) 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) - if cnameContent != cname { - log.Warnf("CNAME mismatch: Repo '%s', CNAME '%s'", cnameContent, cname) + if cnameContent != host { + log.Warnf("CNAME mismatch: Repo '%s', Host '%s'", cnameContent, host) return nil, errors.New("CNAME mismatch") } } @@ -103,6 +99,8 @@ func lookupRepositoryAndCache(username, reponame, branchName, host, domain, path 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) { domain := host @@ -117,11 +115,11 @@ func RepoFromPath(username, host, cname, path string, giteaClient *GiteaClient) // Allow specifying the repository name in the TXT record reponame := "" if cname != "" { - repoLookup, err := giteaClient.lookupRepoTXT(cname) + repoLookup, err := giteaClient.lookupRepoTXT(host) if err == nil && repoLookup != "" { log.Infof( "TXT lookup for %s resulted in choosing repository %s", - cname, + host, repoLookup, ) reponame = repoLookup