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-10-30 13:55:35 +0300
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2019-10-30 13:55:35 +0300
commite9875b7cbcca259cadaa1db76d45161e22b883e6 (patch)
tree7e035f07d12a41a6135c8b34ed86b660d618df5d
parent0916e35d9f321602aee35cd34d78598d37412972 (diff)
Add scaffold of the gitlab client source cache
-rw-r--r--go.mod3
-rw-r--r--go.sum2
-rw-r--r--internal/source/gitlab/cache.go33
-rw-r--r--internal/source/gitlab/client.go2
-rw-r--r--internal/source/gitlab/gitlab.go23
-rw-r--r--internal/source/gitlab/lookup.go3
6 files changed, 55 insertions, 11 deletions
diff --git a/go.mod b/go.mod
index 5866e7fa..59bd759a 100644
--- a/go.mod
+++ b/go.mod
@@ -13,9 +13,8 @@ require (
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0
github.com/karrick/godirwalk v1.10.12
github.com/kr/pretty v0.1.0 // indirect
- github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
- github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/namsral/flag v1.7.4-pre
+ github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/prometheus/client_golang v1.1.0
github.com/rs/cors v1.7.0
github.com/sirupsen/logrus v1.4.2
diff --git a/go.sum b/go.sum
index 30ffb379..d08aed58 100644
--- a/go.sum
+++ b/go.sum
@@ -83,6 +83,8 @@ github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
+github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
+github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
github.com/philhofer/fwd v1.0.0/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU=
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
diff --git a/internal/source/gitlab/cache.go b/internal/source/gitlab/cache.go
new file mode 100644
index 00000000..19efcc1e
--- /dev/null
+++ b/internal/source/gitlab/cache.go
@@ -0,0 +1,33 @@
+package gitlab
+
+import (
+ "time"
+
+ cache "github.com/patrickmn/go-cache"
+)
+
+type Cache struct {
+ shortCache *cache.Cache
+ longCache *cache.Cache
+}
+
+func NewCache() *Cache {
+ return &Cache{
+ shortCache: cache.New(5*time.Second, 10*time.Second),
+ longCache: cache.New(5*time.Minute, 10*time.Minute),
+ }
+}
+
+// GetLookup is going to return a Lookup identified by a domain name using
+// following algorithm:
+// - if a domain lookup is present in the short cache it will return just it
+// - if it is not present in a short cache it will check the long cache
+// - if it is present in a long cache it will return the long cache version and
+// run an update in a separate thread that will fetch the lookup from the
+// GitLab source and replace the short and long cache entries
+// - if a domain lookup is not present in the long cache we will fetch the
+// lookup from the domain source and client will need to wait
+// TODO use sync.Once to synchronize retrieval
+func (c *Cache) GetLookup(domain string, retrieve func() *Lookup) *Lookup {
+ return nil
+}
diff --git a/internal/source/gitlab/client.go b/internal/source/gitlab/client.go
index 73abfaa7..202c6943 100644
--- a/internal/source/gitlab/client.go
+++ b/internal/source/gitlab/client.go
@@ -2,6 +2,6 @@ package gitlab
// client is an internal HTTP client used for communication with GitLab
// instance
-type client interface {
+type Client interface {
Resolve(domain string) *Lookup
}
diff --git a/internal/source/gitlab/gitlab.go b/internal/source/gitlab/gitlab.go
index 5eccff17..8ac8fd85 100644
--- a/internal/source/gitlab/gitlab.go
+++ b/internal/source/gitlab/gitlab.go
@@ -1,12 +1,17 @@
package gitlab
-import "gitlab.com/gitlab-org/gitlab-pages/internal/domain"
+import (
+ "net/http"
+
+ "gitlab.com/gitlab-org/gitlab-pages/internal/domain"
+ "gitlab.com/gitlab-org/gitlab-pages/internal/serving"
+)
// Gitlab source represent a new domains configuration source. We fetch all the
// information about domains from GitLab instance.
type Gitlab struct {
- client
- lookups []Lookup
+ client Client
+ cache Cache
}
// GetDomain return a representation of a domain that we have fetched from
@@ -17,14 +22,20 @@ func (g *Gitlab) GetDomain(name string) *domain.Domain {
// HasDomain checks if a domain is known to GitLab
func (g *Gitlab) HasDomain(name string) bool {
- return false
+ return g.GetDomain(name) != nil
+}
+
+// Resolve is supposed to get the serving lookup path based on the request from
+// the GitLab source
+func (g *Gitlab) Resolve(*http.Request) (*serving.LookupPath, string, error) {
+ return nil, "", nil
}
-// Watch starts Gitlab domains source
+// Watch starts Gitlab domains source TODO remove
func (g *Gitlab) Watch(rootDomain string) {
}
-// Ready checks if Gitlab domains source can be used
+// Ready checks if Gitlab domains source can be used TODO remove
func (g *Gitlab) Ready() bool {
return false
}
diff --git a/internal/source/gitlab/lookup.go b/internal/source/gitlab/lookup.go
index 6e2e0c7c..593ba8f9 100644
--- a/internal/source/gitlab/lookup.go
+++ b/internal/source/gitlab/lookup.go
@@ -5,9 +5,8 @@ type Lookup struct {
Domain string
CertificateCert string
CertificateKey string
- Serving string
- Prefix string
LookupPaths []struct {
+ Prefix string
ProjectID int
HTTPSOnly bool
AccessControl bool