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:
authorTuomo Ala-Vannesluoma <tuomoav@gmail.com>2018-04-06 18:23:58 +0300
committerTuomo Ala-Vannesluoma <tuomoav@gmail.com>2018-06-30 22:50:19 +0300
commit9cf40354085f4b4446f06d4d03926dcaa6ab9565 (patch)
treeeb6ade3a82feec5f9b258417f41a8fecd3e9aec9 /internal/domain
parentc4a419ed595281f62977fd47aa30d225c4eddb5d (diff)
Add support for private projects and authentication with GitLab API
Diffstat (limited to 'internal/domain')
-rw-r--r--internal/domain/domain.go51
-rw-r--r--internal/domain/domain_config.go7
-rw-r--r--internal/domain/domain_test.go1
-rw-r--r--internal/domain/map.go11
4 files changed, 58 insertions, 12 deletions
diff --git a/internal/domain/domain.go b/internal/domain/domain.go
index f50dacd8..3aef96f5 100644
--- a/internal/domain/domain.go
+++ b/internal/domain/domain.go
@@ -24,7 +24,10 @@ type locationDirectoryError struct {
}
type project struct {
- HTTPSOnly bool
+ HTTPSOnly bool
+ Private bool
+ AccessControl bool
+ ID int
}
type projects map[string]*project
@@ -97,6 +100,14 @@ func setContentType(w http.ResponseWriter, fullPath string) {
}
}
+func (d *D) getProject(r *http.Request) *project {
+ split := strings.SplitN(r.URL.Path, "/", 3)
+ if len(split) < 2 {
+ return nil
+ }
+ return d.projects[split[1]]
+}
+
// IsHTTPSOnly figures out if the request should be handled with HTTPS
// only by looking at group and project level config.
func (d *D) IsHTTPSOnly(r *http.Request) bool {
@@ -104,20 +115,48 @@ func (d *D) IsHTTPSOnly(r *http.Request) bool {
return d.config.HTTPSOnly
}
- split := strings.SplitN(r.URL.Path, "/", 3)
- if len(split) < 2 {
- return false
+ project := d.getProject(r)
+
+ if project != nil {
+ return project.HTTPSOnly
+ }
+
+ return false
+}
+
+// IsAccessControlEnabled figures out if the request is to a project that has access control enabled
+func (d *D) IsAccessControlEnabled(r *http.Request) bool {
+ project := d.getProject(r)
+
+ if project != nil {
+ return project.AccessControl
}
- project := d.projects[split[1]]
+ return false
+}
+
+// IsPrivate figures out if the request is to a project that needs user to sign in
+func (d *D) IsPrivate(r *http.Request) bool {
+ project := d.getProject(r)
if project != nil {
- return project.HTTPSOnly
+ return project.Private
}
return false
}
+// GetID figures out what is the ID of the project user tries to access
+func (d *D) GetID(r *http.Request) int {
+ project := d.getProject(r)
+
+ if project != nil {
+ return project.ID
+ }
+
+ return -1
+}
+
func (d *D) serveFile(w http.ResponseWriter, r *http.Request, origPath string) error {
fullPath := handleGZip(w, r, origPath)
diff --git a/internal/domain/domain_config.go b/internal/domain/domain_config.go
index ed7e0820..1acb3461 100644
--- a/internal/domain/domain_config.go
+++ b/internal/domain/domain_config.go
@@ -15,8 +15,11 @@ type domainConfig struct {
}
type domainsConfig struct {
- Domains []domainConfig
- HTTPSOnly bool `json:"https_only"`
+ Domains []domainConfig
+ HTTPSOnly bool `json:"https_only"`
+ Private bool `json:"private"`
+ ID int `json:"id"`
+ AccessControl bool `json:"access_control"`
}
func (c *domainConfig) Valid(rootDomain string) bool {
diff --git a/internal/domain/domain_test.go b/internal/domain/domain_test.go
index 130501d6..4cbc6cc2 100644
--- a/internal/domain/domain_test.go
+++ b/internal/domain/domain_test.go
@@ -38,6 +38,7 @@ func TestGroupServeHTTP(t *testing.T) {
assert.HTTPBodyContains(t, testGroup.ServeHTTP, "GET", "http://group.test.io/project/subdir/", nil, "project-subsubdir")
assert.HTTPBodyContains(t, testGroup.ServeHTTP, "GET", "http://group.test.io/project2/", nil, "project2-main")
assert.HTTPBodyContains(t, testGroup.ServeHTTP, "GET", "http://group.test.io/project2/index.html", nil, "project2-main")
+ assert.HTTPRedirect(t, testGroup.ServeHTTP, "GET", "http://group.test.io/private.project/", nil)
assert.HTTPError(t, testGroup.ServeHTTP, "GET", "http://group.test.io//about.gitlab.com/%2e%2e", nil)
assert.HTTPError(t, testGroup.ServeHTTP, "GET", "http://group.test.io/symlink", nil)
assert.HTTPError(t, testGroup.ServeHTTP, "GET", "http://group.test.io/symlink/index.html", nil)
diff --git a/internal/domain/map.go b/internal/domain/map.go
index 943f5c20..a6537bda 100644
--- a/internal/domain/map.go
+++ b/internal/domain/map.go
@@ -32,7 +32,7 @@ func (dm Map) addDomain(rootDomain, group, projectName string, config *domainCon
dm[domainName] = newDomain
}
-func (dm Map) updateGroupDomain(rootDomain, group, projectName string, httpsOnly bool) {
+func (dm Map) updateGroupDomain(rootDomain, group, projectName string, httpsOnly bool, private bool, accessControl bool, id int) {
domainName := strings.ToLower(group + "." + rootDomain)
groupDomain := dm[domainName]
@@ -44,7 +44,10 @@ func (dm Map) updateGroupDomain(rootDomain, group, projectName string, httpsOnly
}
groupDomain.projects[projectName] = &project{
- HTTPSOnly: httpsOnly,
+ HTTPSOnly: httpsOnly,
+ Private: private,
+ AccessControl: accessControl,
+ ID: id,
}
dm[domainName] = groupDomain
@@ -55,11 +58,11 @@ func (dm Map) readProjectConfig(rootDomain string, group, projectName string, co
// This is necessary to preserve the previous behaviour where a
// group domain is created even if no config.json files are
// loaded successfully. Is it safe to remove this?
- dm.updateGroupDomain(rootDomain, group, projectName, false)
+ dm.updateGroupDomain(rootDomain, group, projectName, false, false, false, -1)
return
}
- dm.updateGroupDomain(rootDomain, group, projectName, config.HTTPSOnly)
+ dm.updateGroupDomain(rootDomain, group, projectName, config.HTTPSOnly, config.Private, config.AccessControl, config.ID)
for _, domainConfig := range config.Domains {
config := domainConfig // domainConfig is reused for each loop iteration