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 Trzciński <ayufan@ayufan.eu>2020-08-20 17:09:17 +0300
committerKamil Trzciński <ayufan@ayufan.eu>2020-08-21 11:31:56 +0300
commit9194d1f0e9f0e329f74dd49e90c7b39750e45b29 (patch)
tree2ce587de90a90e4fbdc11247b9be71fba9247bde
parentb1d215d4935d599a4368c1dde7bb999c20154e25 (diff)
Add `VFS` to `LookupPath`pluggable-disk-vfs
This extends API and Disk Serving to include VFS parameter.
-rw-r--r--internal/serving/disk/reader.go9
-rw-r--r--internal/serving/disk/serving.go7
-rw-r--r--internal/serving/lookup_path.go1
-rw-r--r--internal/source/disk/custom.go1
-rw-r--r--internal/source/disk/group.go1
-rw-r--r--internal/source/gitlab/api/lookup_path.go1
-rw-r--r--internal/source/gitlab/factory.go1
7 files changed, 18 insertions, 3 deletions
diff --git a/internal/serving/disk/reader.go b/internal/serving/disk/reader.go
index ef84d2bc..b9105f4b 100644
--- a/internal/serving/disk/reader.go
+++ b/internal/serving/disk/reader.go
@@ -19,7 +19,7 @@ import (
// Reader is a disk access driver
type Reader struct {
fileSizeMetric prometheus.Histogram
- vfs vfs.VFS
+ vfs map[string]vfs.VFS
}
func (reader *Reader) tryFile(h serving.Handler) error {
@@ -76,7 +76,12 @@ func (reader *Reader) tryNotFound(h serving.Handler) error {
// Resolve the HTTP request to a path on disk, converting requests for
// directories to requests for index.html inside the directory if appropriate.
func (reader *Reader) resolvePath(ctx context.Context, lookupPath *serving.LookupPath, subPath ...string) (vfs.Root, string, error) {
- root, err := reader.vfs.Root(ctx, lookupPath.Path)
+ vfs := reader.vfs[lookupPath.VFS]
+ if vfs == nil {
+ return nil, "", fmt.Errorf("unknown VFS: %q", lookupPath.VFS)
+ }
+
+ root, err := vfs.Root(ctx, lookupPath.Path)
if err != nil {
return nil, "", err
}
diff --git a/internal/serving/disk/serving.go b/internal/serving/disk/serving.go
index a38124ef..e7cfcec7 100644
--- a/internal/serving/disk/serving.go
+++ b/internal/serving/disk/serving.go
@@ -8,10 +8,15 @@ import (
"gitlab.com/gitlab-org/gitlab-pages/metrics"
)
+var localVFS = vfs.Instrumented(local.VFS{}, "local")
+
var disk = &Disk{
reader: Reader{
fileSizeMetric: metrics.DiskServingFileSize,
- vfs: vfs.Instrumented(local.VFS{}, "disk"),
+ vfs: map[string]vfs.VFS{
+ "": localVFS, // default to use if not specified
+ "local": localVFS,
+ },
},
}
diff --git a/internal/serving/lookup_path.go b/internal/serving/lookup_path.go
index 4360358b..64bad03d 100644
--- a/internal/serving/lookup_path.go
+++ b/internal/serving/lookup_path.go
@@ -2,6 +2,7 @@ package serving
// LookupPath holds a domain project configuration needed to handle a request
type LookupPath struct {
+ VFS string // VFS to serve the given LookupPath for example: `local` or `zip`
Prefix string // Project prefix, for example, /my/project in group.gitlab.io/my/project/index.html
Path string // Path is an internal and serving-specific location of a document
IsNamespaceProject bool // IsNamespaceProject is DEPRECATED, see https://gitlab.com/gitlab-org/gitlab-pages/issues/272
diff --git a/internal/source/disk/custom.go b/internal/source/disk/custom.go
index 4d991437..2ccd1749 100644
--- a/internal/source/disk/custom.go
+++ b/internal/source/disk/custom.go
@@ -15,6 +15,7 @@ type customProjectResolver struct {
func (p *customProjectResolver) Resolve(r *http.Request) (*serving.Request, error) {
lookupPath := &serving.LookupPath{
+ VFS: "local",
Prefix: "/",
Path: p.path,
IsNamespaceProject: false,
diff --git a/internal/source/disk/group.go b/internal/source/disk/group.go
index f161f9f7..9ec42673 100644
--- a/internal/source/disk/group.go
+++ b/internal/source/disk/group.go
@@ -88,6 +88,7 @@ func (g *Group) Resolve(r *http.Request) (*serving.Request, error) {
}
lookupPath := &serving.LookupPath{
+ VFS: "local",
Prefix: prefix,
Path: filepath.Join(g.name, projectPath, "public") + "/",
IsNamespaceProject: projectConfig.NamespaceProject,
diff --git a/internal/source/gitlab/api/lookup_path.go b/internal/source/gitlab/api/lookup_path.go
index 77b264ff..2b1d2d7e 100644
--- a/internal/source/gitlab/api/lookup_path.go
+++ b/internal/source/gitlab/api/lookup_path.go
@@ -2,6 +2,7 @@ package api
// LookupPath represents a lookup path for a virtual domain
type LookupPath struct {
+ VFS string `json:"vfs",omitempty`
ProjectID int `json:"project_id,omitempty"`
AccessControl bool `json:"access_control,omitempty"`
HTTPSOnly bool `json:"https_only,omitempty"`
diff --git a/internal/source/gitlab/factory.go b/internal/source/gitlab/factory.go
index b10dee37..d78457d6 100644
--- a/internal/source/gitlab/factory.go
+++ b/internal/source/gitlab/factory.go
@@ -16,6 +16,7 @@ import (
// https://gitlab.com/gitlab-org/gitlab-pages/issues/272
func fabricateLookupPath(size int, lookup api.LookupPath) *serving.LookupPath {
return &serving.LookupPath{
+ VFS: lookup.VFS,
Prefix: lookup.Prefix,
Path: strings.TrimPrefix(lookup.Source.Path, "/"),
IsNamespaceProject: (lookup.Prefix == "/" && size > 1),