Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app.go
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2019-10-02 15:56:37 +0300
committerNick Thomas <nick@gitlab.com>2019-10-02 15:56:37 +0300
commit9943255d61c5646f6cf9e1a8a03e4a2dc19831f5 (patch)
tree70632128b0eb0b7decaca56604cc5e46fb6e8183 /app.go
parent77c1fd80fe2e7e6e25b038b720a47df7d7c7f374 (diff)
parentf56d97f90b9bb67a242a1811bc6efa3592ac9f8a (diff)
Merge branch 'backstage/gb/separate-domain-source-storage' into 'master'
Separate domain config source See merge request gitlab-org/gitlab-pages!188
Diffstat (limited to 'app.go')
-rw-r--r--app.go33
1 files changed, 11 insertions, 22 deletions
diff --git a/app.go b/app.go
index e65d7510..2f47d155 100644
--- a/app.go
+++ b/app.go
@@ -7,9 +7,7 @@ import (
"net"
"net/http"
"os"
- "strings"
"sync"
- "time"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/rs/cors"
@@ -29,6 +27,7 @@ import (
"gitlab.com/gitlab-org/gitlab-pages/internal/logging"
"gitlab.com/gitlab-org/gitlab-pages/internal/netutil"
"gitlab.com/gitlab-org/gitlab-pages/internal/request"
+ "gitlab.com/gitlab-org/gitlab-pages/internal/source"
)
const (
@@ -48,8 +47,7 @@ var (
type theApp struct {
appConfig
- dm domain.Map
- lock sync.RWMutex
+ domains *source.Domains
Artifact *artifact.Artifact
Auth *auth.Auth
Handlers *handlers.Handlers
@@ -58,15 +56,7 @@ type theApp struct {
}
func (a *theApp) isReady() bool {
- return a.dm != nil
-}
-
-func (a *theApp) domain(host string) *domain.Domain {
- host = strings.ToLower(host)
- a.lock.RLock()
- defer a.lock.RUnlock()
- domain, _ := a.dm[host]
- return domain
+ return a.domains.Ready()
}
func (a *theApp) ServeTLS(ch *tls.ClientHelloInfo) (*tls.Certificate, error) {
@@ -108,6 +98,10 @@ func (a *theApp) getHostAndDomain(r *http.Request) (host string, domain *domain.
return host, a.domain(host)
}
+func (a *theApp) domain(host string) *domain.Domain {
+ return a.domains.GetDomain(host)
+}
+
func (a *theApp) checkAuthenticationIfNotExists(domain *domain.Domain, w http.ResponseWriter, r *http.Request) bool {
if domain == nil || !domain.HasProject(r) {
@@ -205,7 +199,7 @@ func (a *theApp) acmeMiddleware(handler http.Handler) http.Handler {
// authMiddleware handles authentication requests
func (a *theApp) authMiddleware(handler http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- if a.Auth.TryAuthenticate(w, r, a.dm, &a.lock) {
+ if a.Auth.TryAuthenticate(w, r, a.domains) {
return
}
@@ -322,12 +316,6 @@ func (a *theApp) buildHandlerPipeline() (http.Handler, error) {
return handler, nil
}
-func (a *theApp) UpdateDomains(dm domain.Map) {
- a.lock.Lock()
- defer a.lock.Unlock()
- a.dm = dm
-}
-
func (a *theApp) Run() {
var wg sync.WaitGroup
@@ -366,7 +354,7 @@ func (a *theApp) Run() {
a.listenAdminUnix(&wg)
a.listenAdminHTTPS(&wg)
- go domain.Watch(a.Domain, a.UpdateDomains, time.Second)
+ a.domains.Watch(a.Domain)
wg.Wait()
}
@@ -473,7 +461,8 @@ func (a *theApp) listenAdminHTTPS(wg *sync.WaitGroup) {
}
func runApp(config appConfig) {
- a := theApp{appConfig: config}
+ a := theApp{appConfig: config, domains: source.NewDomains()}
+
err := logging.ConfigureLogging(a.LogFormat, a.LogVerbose)
if err != nil {
log.WithError(err).Fatal("Failed to initialize logging")