diff options
author | Jaime Martinez <jmartinez@gitlab.com> | 2020-09-09 09:23:02 +0300 |
---|---|---|
committer | Jaime Martinez <jmartinez@gitlab.com> | 2020-09-24 03:22:45 +0300 |
commit | 3e20c84456ec3194de8a35af3cd287a37c006549 (patch) | |
tree | 537e905021f4803bbb67c570136a0c0895ed1424 /internal/source/gitlab | |
parent | 7802bb75e8edafe05855fcbdb72aeea7bb906ae7 (diff) |
Rebase from base branch
Add vfs.VFS implementation for zip
Fix build errors
Clean zip vfs
Add tests for Root
Add zip serving metric
Return a zip.Instance() when source == zip
Add simple acceptance test for zip serving
Use correct contents
No need to start testServer in go routine
Diffstat (limited to 'internal/source/gitlab')
-rw-r--r-- | internal/source/gitlab/factory.go | 7 | ||||
-rw-r--r-- | internal/source/gitlab/gitlab.go | 12 |
2 files changed, 16 insertions, 3 deletions
diff --git a/internal/source/gitlab/factory.go b/internal/source/gitlab/factory.go index b5ab367b..39193a16 100644 --- a/internal/source/gitlab/factory.go +++ b/internal/source/gitlab/factory.go @@ -1,12 +1,11 @@ package gitlab import ( - "strings" - log "github.com/sirupsen/logrus" "gitlab.com/gitlab-org/gitlab-pages/internal/serving" "gitlab.com/gitlab-org/gitlab-pages/internal/serving/disk/local" + "gitlab.com/gitlab-org/gitlab-pages/internal/serving/disk/zip" "gitlab.com/gitlab-org/gitlab-pages/internal/serving/serverless" "gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/api" ) @@ -17,7 +16,7 @@ import ( func fabricateLookupPath(size int, lookup api.LookupPath) *serving.LookupPath { return &serving.LookupPath{ Prefix: lookup.Prefix, - Path: strings.TrimPrefix(lookup.Source.Path, "/"), + Path: lookup.Source.Path, IsNamespaceProject: (lookup.Prefix == "/" && size > 1), IsHTTPSOnly: lookup.HTTPSOnly, HasAccessControl: lookup.AccessControl, @@ -32,6 +31,8 @@ func fabricateServing(lookup api.LookupPath) serving.Serving { switch source.Type { case "file": return local.Instance() + case "zip": + return zip.Instance() case "serverless": serving, err := serverless.NewFromAPISource(source.Serverless) if err != nil { diff --git a/internal/source/gitlab/gitlab.go b/internal/source/gitlab/gitlab.go index 67c4eb6b..fb15a07a 100644 --- a/internal/source/gitlab/gitlab.go +++ b/internal/source/gitlab/gitlab.go @@ -4,6 +4,7 @@ import ( "context" "errors" "net/http" + "net/url" "path" "strings" "sync" @@ -94,6 +95,17 @@ func (g *Gitlab) Resolve(r *http.Request) (*serving.Request, error) { subPath = strings.TrimPrefix(urlPath, lookup.Prefix) } + if lookup.Source.Type == "zip" { + urlPath, err := url.Parse(lookup.Source.Path) + if err != nil { + return nil, err + } + + lookup.Source.Path = urlPath.String() + } else { + lookup.Source.Path = strings.TrimPrefix(lookup.Source.Path, "/") + } + return &serving.Request{ Serving: fabricateServing(lookup), LookupPath: fabricateLookupPath(size, lookup), |