Use embeddable ocdav go micro service (#3397)

* allow proxy to route to micro service

Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>

* use go micre ocdav service instead of reva frontend

Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>

* add missing gateway default config

Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>

* update reva branch for testing

Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>

* add changelog

Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>

* add missing comands

Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>

* bump reva version

Signed-off-by: jkoberg <jkoberg@owncloud.com>

* tidy

Signed-off-by: jkoberg <jkoberg@owncloud.com>

* bump reva again

Signed-off-by: jkoberg <jkoberg@owncloud.com>

* a blind mans config change

Signed-off-by: jkoberg <jkoberg@owncloud.com>

* add ocdav to must start extensions

Signed-off-by: jkoberg <jkoberg@owncloud.com>

* fail when neither backend nor service is set

Signed-off-by: jkoberg <jkoberg@owncloud.com>

Co-authored-by: jkoberg <jkoberg@owncloud.com>
This commit is contained in:
Jörn Friedrich Dreyer
2022-04-12 11:27:24 +02:00
committed by GitHub
co-authored by jkoberg
parent a61d1ced9f
commit 0e88cb1bec
18 changed files with 310 additions and 69 deletions
+8 -5
View File
@@ -43,12 +43,15 @@ type Policy struct {
Routes []Route `yaml:"routes"`
}
// Route define forwarding routes
// Route defines forwarding routes
type Route struct {
Type RouteType `yaml:"type"`
Endpoint string `yaml:"endpoint"`
Backend string `yaml:"backend"`
ApacheVHost bool `yaml:"apache-vhost"`
Type RouteType `yaml:"type"`
Endpoint string `yaml:"endpoint"`
// Backend is a static URL to forward the request to
Backend string `yaml:"backend"`
// Service name to look up in the registry
Service string `yaml:"service"`
ApacheVHost bool `yaml:"apache-vhost"`
}
// RouteType defines the type of a route
+10 -6
View File
@@ -96,30 +96,34 @@ func DefaultPolicies() []config.Policy {
},
{
Endpoint: "/remote.php/",
Backend: "http://localhost:9140",
Service: "ocdav",
},
{
Endpoint: "/dav/",
Backend: "http://localhost:9140",
Service: "ocdav",
},
{
Endpoint: "/webdav/",
Backend: "http://localhost:9140",
Service: "ocdav",
},
{
Endpoint: "/status.php",
Backend: "http://localhost:9140",
Service: "ocdav",
},
{
Endpoint: "/index.php/",
Backend: "http://localhost:9140",
Service: "ocdav",
},
{
Endpoint: "/apps/",
Service: "ocdav",
},
{
Endpoint: "/data",
Backend: "http://localhost:9140",
},
{
Endpoint: "/app/",
Endpoint: "/app/", // /app or /apps? ocdav only handles /apps
Backend: "http://localhost:9140",
},
{
+31 -2
View File
@@ -12,10 +12,12 @@ import (
"time"
chimiddleware "github.com/go-chi/chi/v5/middleware"
"go-micro.dev/v4/selector"
"go.opentelemetry.io/otel/attribute"
"github.com/owncloud/ocis/ocis-pkg/log"
"github.com/owncloud/ocis/ocis-pkg/registry"
pkgtrace "github.com/owncloud/ocis/ocis-pkg/tracing"
"github.com/owncloud/ocis/proxy/pkg/config"
"github.com/owncloud/ocis/proxy/pkg/proxy/policy"
@@ -86,6 +88,10 @@ func NewMultiHostReverseProxy(opts ...Option) *MultiHostReverseProxy {
for _, pol := range options.Config.Policies {
for _, route := range pol.Routes {
rp.logger.Debug().Str("fwd: ", route.Endpoint)
if route.Backend == "" && route.Service == "" {
rp.logger.Fatal().Interface("route", route).Msg("neither Backend nor Service is set")
}
uri, err2 := url.Parse(route.Backend)
if err2 != nil {
rp.logger.
@@ -95,6 +101,7 @@ func NewMultiHostReverseProxy(opts ...Option) *MultiHostReverseProxy {
Msg("malformed url")
}
// here the backend is used as a uri
rp.AddHost(pol.Name, uri, route)
}
}
@@ -184,9 +191,31 @@ func (p *MultiHostReverseProxy) AddHost(policy string, target *url.URL, rt confi
if p.Directors[policy][routeType] == nil {
p.Directors[policy][routeType] = make(map[string]func(req *http.Request))
}
reg := registry.GetRegistry()
sel := selector.NewSelector(selector.Registry(reg))
p.Directors[policy][routeType][rt.Endpoint] = func(req *http.Request) {
req.URL.Scheme = target.Scheme
req.URL.Host = target.Host
if rt.Service != "" {
// select next node
next, err := sel.Select(rt.Service)
if err != nil {
fmt.Println(fmt.Errorf("could not select %s service from the registry: %v", rt.Service, err))
return // TODO error? fallback to target.Host & Scheme?
}
node, err := next()
if err != nil {
fmt.Println(fmt.Errorf("could not select next node for service %s: %v", rt.Service, err))
return // TODO error? fallback to target.Host & Scheme?
}
req.URL.Host = node.Address
req.URL.Scheme = node.Metadata["protocol"] // TODO check property exists?
} else {
req.URL.Host = target.Host
req.URL.Scheme = target.Scheme
}
// Apache deployments host addresses need to match on req.Host and req.URL.Host
// see https://stackoverflow.com/questions/34745654/golang-reverseproxy-with-apache2-sni-hostname-error
if rt.ApacheVHost {