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
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-02-11 16:21:28 +0300
committerKamil Trzcinski <ayufan@ayufan.eu>2016-02-11 16:21:28 +0300
commit8d0cdba657ec249a1815a8f83c8cda0031dbf190 (patch)
tree53cd3eab5038535769c379ef92f34200441c81e0 /domain.go
parent259af85e875293e9cd6061cf1058ea0cc2e83dcc (diff)
Read configuration and updates from shares/pages/group/project/config.json and shares/pages/.update
Diffstat (limited to 'domain.go')
-rw-r--r--domain.go25
1 files changed, 11 insertions, 14 deletions
diff --git a/domain.go b/domain.go
index d306b936..f9bbb7a7 100644
--- a/domain.go
+++ b/domain.go
@@ -1,18 +1,18 @@
package main
import (
+ "crypto/tls"
+ "errors"
"net/http"
"os"
"path/filepath"
"strings"
- "crypto/tls"
- "errors"
)
type domain struct {
Group string
Project string
- CNAME bool
+ Config *domainConfig
certificate *tls.Certificate
}
@@ -63,7 +63,7 @@ func (d *domain) tryFile(w http.ResponseWriter, r *http.Request, projectName, su
return true
}
-func (d *domain) serverGroup(w http.ResponseWriter, r *http.Request) {
+func (d *domain) serveFromGroup(w http.ResponseWriter, r *http.Request) {
// The Path always contains "/" at the beggining
split := strings.SplitN(r.URL.Path, "/", 3)
@@ -84,7 +84,7 @@ func (d *domain) serverGroup(w http.ResponseWriter, r *http.Request) {
d.notFound(w, r)
}
-func (d *domain) serveCNAME(w http.ResponseWriter, r *http.Request) {
+func (d *domain) serveFromConfig(w http.ResponseWriter, r *http.Request) {
if d.tryFile(w, r, d.Project, r.URL.Path) {
return
}
@@ -93,18 +93,15 @@ func (d *domain) serveCNAME(w http.ResponseWriter, r *http.Request) {
}
func (d *domain) ensureCertificate() (*tls.Certificate, error) {
- if !d.CNAME {
- return nil, errors.New("tls certificates can be loaded only for pages with CNAME")
+ if !d.Config {
+ return nil, errors.New("tls certificates can be loaded only for pages with configuration")
}
if d.certificate != nil {
return d.certificate, nil
}
- // Load keypair from shared/pages/group/project/domain.{crt,key}
- certificateFile := filepath.Join(*pagesRoot, d.Group, d.Project, "domain.crt")
- keyFile := filepath.Join(*pagesRoot, d.Group, d.Project, "domain.key")
- tls, err := tls.LoadX509KeyPair(certificateFile, keyFile)
+ tls, err := tls.X509KeyPair([]byte(d.Config.Certificate), []byte(d.Config.Key))
if err != nil {
return nil, err
}
@@ -114,9 +111,9 @@ func (d *domain) ensureCertificate() (*tls.Certificate, error) {
}
func (d *domain) ServeHTTP(w http.ResponseWriter, r *http.Request) {
- if d.CNAME {
- d.serveCNAME(w, r)
+ if d.Config != nil {
+ d.serveFromConfig(w, r)
} else {
- d.serverGroup(w, r)
+ d.serveFromGroup(w, r)
}
}