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:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2019-09-22 13:25:27 +0300
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2019-09-22 13:25:27 +0300
commit602eb300822f23e65c8e961111d8b16096158285 (patch)
tree4384990cf40922548f0bea1c212ddb4e797e6327 /internal
parent079f5e979142bceeeb6506c4d31d7c9f1488ce78 (diff)
Remove refactoring stubs and fix go lint
Diffstat (limited to 'internal')
-rw-r--r--internal/domain/domain.go57
-rw-r--r--internal/source/dirs/group.go46
2 files changed, 39 insertions, 64 deletions
diff --git a/internal/domain/domain.go b/internal/domain/domain.go
index 1c90a232..4c5fce17 100644
--- a/internal/domain/domain.go
+++ b/internal/domain/domain.go
@@ -29,12 +29,13 @@ type locationFileNoExtensionError struct {
FullPath string
}
+// GroupConfig represents a per-request config for a group domain
type GroupConfig interface {
- IsHTTPSOnly(*http.Request) (bool, error)
- HasAccessControl(*http.Request) (bool, error)
- IsNamespaceProject(*http.Request) (bool, error)
- ProjectID(*http.Request) (uint64, error)
- ProjectExists(*http.Request) (bool, error)
+ IsHTTPSOnly(*http.Request) bool
+ HasAccessControl(*http.Request) bool
+ IsNamespaceProject(*http.Request) bool
+ ProjectID(*http.Request) uint64
+ ProjectExists(*http.Request) bool
ProjectWithSubpath(*http.Request) (string, string, error)
}
@@ -123,15 +124,7 @@ func (d *Domain) IsHTTPSOnly(r *http.Request) bool {
}
// Check projects served under the group domain, including the default one
- // TODO REFACTORING
- // if project, _, _ := d.getProjectWithSubpath(r); project != nil {
- // return project.HTTPSOnly
- // }
- if httpsOnly, err := d.GroupConfig.IsHTTPSOnly(r); err == nil {
- return httpsOnly
- }
-
- return false
+ return d.GroupConfig.IsHTTPSOnly(r)
}
// IsAccessControlEnabled figures out if the request is to a project that has access control enabled
@@ -146,14 +139,7 @@ func (d *Domain) IsAccessControlEnabled(r *http.Request) bool {
}
// Check projects served under the group domain, including the default one
- // TODO RFR if project, _, _ := d.getProjectWithSubpath(r); project != nil {
- // return project.AccessControl
- //}
- if hasAccessControl, err := d.GroupConfig.HasAccessControl(r); err == nil {
- return hasAccessControl
- }
-
- return false
+ return d.GroupConfig.HasAccessControl(r)
}
// HasAcmeChallenge checks domain directory contains particular acme challenge
@@ -195,14 +181,7 @@ func (d *Domain) IsNamespaceProject(r *http.Request) bool {
}
// Check projects served under the group domain, including the default one
- // if project, _, _ := d.getProjectWithSubpath(r); project != nil {
- // return project.NamespaceProject
- // }
- if isNamespaceProject, err := d.GroupConfig.IsNamespaceProject(r); err == nil {
- return isNamespaceProject
- }
-
- return false
+ return d.GroupConfig.IsNamespaceProject(r)
}
// GetID figures out what is the ID of the project user tries to access
@@ -215,14 +194,7 @@ func (d *Domain) GetID(r *http.Request) uint64 {
return d.ProjectID
}
- // if project, _, _ := d.getProjectWithSubpath(r); project != nil {
- // return project.ID
- // }
- if projectID, err := d.GroupConfig.ProjectID(r); err == nil {
- return projectID
- }
-
- return 0
+ return d.GroupConfig.ProjectID(r)
}
// HasProject figures out if the project exists that the user tries to access
@@ -235,14 +207,7 @@ func (d *Domain) HasProject(r *http.Request) bool {
return true
}
- // if project, _, _ := d.getProjectWithSubpath(r); project != nil {
- // return true
- // }
- if projectExists, err := d.GroupConfig.ProjectExists(r); err == nil {
- return projectExists
- }
-
- return false
+ return d.GroupConfig.ProjectExists(r)
}
// Detect file's content-type either by extension or mime-sniffing.
diff --git a/internal/source/dirs/group.go b/internal/source/dirs/group.go
index 917159e4..a711221c 100644
--- a/internal/source/dirs/group.go
+++ b/internal/source/dirs/group.go
@@ -52,12 +52,12 @@ func (g *Group) digProjectWithSubpath(parentPath string, keys []string) (*Projec
// Look up a project inside the domain based on the host and path. Returns the
// project and its name (if applicable)
-func (group *Group) getProjectConfigWithSubpath(r *http.Request) (*ProjectConfig, string, string) {
+func (g *Group) getProjectConfigWithSubpath(r *http.Request) (*ProjectConfig, string, string) {
// Check for a project specified in the URL: http://group.gitlab.io/projectA
// If present, these projects shadow the group domain.
split := strings.SplitN(r.URL.Path, "/", maxProjectDepth)
if len(split) >= 2 {
- projectConfig, projectPath, urlPath := group.digProjectWithSubpath("", split[1:])
+ projectConfig, projectPath, urlPath := g.digProjectWithSubpath("", split[1:])
if projectConfig != nil {
return projectConfig, projectPath, urlPath
}
@@ -66,7 +66,7 @@ func (group *Group) getProjectConfigWithSubpath(r *http.Request) (*ProjectConfig
// Since the URL doesn't specify a project (e.g. http://mydomain.gitlab.io),
// return the group project if it exists.
if host := host.FromRequest(r); host != "" {
- if groupProject := group.projects[host]; groupProject != nil {
+ if groupProject := g.projects[host]; groupProject != nil {
return groupProject, host, strings.Join(split[1:], "/")
}
}
@@ -74,56 +74,66 @@ func (group *Group) getProjectConfigWithSubpath(r *http.Request) (*ProjectConfig
return nil, "", ""
}
-func (g *Group) IsHTTPSOnly(r *http.Request) (bool, error) {
+// IsHTTPSOnly return true if project exists and has https-only setting
+// configured
+func (g *Group) IsHTTPSOnly(r *http.Request) bool {
project, _, _ := g.getProjectConfigWithSubpath(r)
if project != nil {
- return project.HTTPSOnly, nil
+ return project.HTTPSOnly
}
- return false, errors.New("project not found")
+ return false
}
-func (g *Group) HasAccessControl(r *http.Request) (bool, error) {
+// HasAccessControl returns true if a group project has access control setting
+// enabled
+func (g *Group) HasAccessControl(r *http.Request) bool {
project, _, _ := g.getProjectConfigWithSubpath(r)
if project != nil {
- return project.AccessControl, nil
+ return project.AccessControl
}
- return false, errors.New("project not found")
+ return false
}
-func (g *Group) IsNamespaceProject(r *http.Request) (bool, error) {
+// IsNamespaceProject return true if per-request config belongs to a namespace
+// project
+func (g *Group) IsNamespaceProject(r *http.Request) bool {
project, _, _ := g.getProjectConfigWithSubpath(r)
if project != nil {
- return project.NamespaceProject, nil
+ return project.NamespaceProject
}
- return false, errors.New("project not found")
+ return false
}
-func (g *Group) ProjectID(r *http.Request) (uint64, error) {
+// ProjectID return a per-request group project ID
+func (g *Group) ProjectID(r *http.Request) uint64 {
project, _, _ := g.getProjectConfigWithSubpath(r)
if project != nil {
- return project.ID, nil
+ return project.ID
}
- return 0, errors.New("project not found")
+ return 0
}
-func (g *Group) ProjectExists(r *http.Request) (bool, error) {
+// ProjectExists return true if project config has been found
+func (g *Group) ProjectExists(r *http.Request) bool {
project, _, _ := g.getProjectConfigWithSubpath(r)
if project != nil {
- return true, nil
+ return true
}
- return false, nil
+ return false
}
+// ProjectWithSubpath tries to find project and its config recursively for a
+// given request to a group domain
func (g *Group) ProjectWithSubpath(r *http.Request) (string, string, error) {
project, projectName, subPath := g.getProjectConfigWithSubpath(r)