added hardcoded routes for the reverse proxy to bypass authentication and phoenix

This commit is contained in:
A.Unger
2020-02-24 11:02:52 +01:00
parent 59bd9a93d2
commit 60bd1d8af7

View File

@@ -1,12 +1,10 @@
package http
import (
"encoding/json"
"net/http"
"log"
"net/http/httputil"
"net/url"
"github.com/micro/go-micro/v2/config"
"github.com/micro/go-micro/v2/config/source/memory"
"github.com/micro/go-plugins/micro/router/v2"
svc "github.com/owncloud/ocis-pkg/v2/service/http"
"github.com/owncloud/ocis-proxy/pkg/version"
)
@@ -25,135 +23,25 @@ func Server(opts ...Option) (svc.Service, error) {
svc.Flags(options.Flags...),
)
// TODO replace hardcoded adresses with service registry lookups
routes := []router.Route{
{
Request: router.Request{
Method: "GET",
Host: "localhost:9200",
Path: "/.well-known/openid-configuration",
},
ProxyURL: router.URL{
Scheme: "https",
Host: "localhost:9130",
Path: "/.well-known/openid-configuration",
},
Weight: 2.0,
Type: "proxy",
},
{
Request: router.Request{
Method: "GET",
Host: "localhost:9200",
Path: "/signin/v1",
},
ProxyURL: router.URL{
Scheme: "https",
Host: "localhost:9130",
Path: "/signin/v1",
},
Weight: 2.0,
Type: "proxy",
},
{
Request: router.Request{
Method: "GET",
Host: "localhost:9200",
Path: "/konnect/v1",
},
ProxyURL: router.URL{
Scheme: "https",
Host: "localhost:9130",
Path: "/konnect/v1",
},
Weight: 2.0,
Type: "proxy",
},
{
Request: router.Request{
Method: "GET",
Host: "localhost:9200",
Path: "/reva",
},
ProxyURL: router.URL{
Scheme: "http",
Host: "localhost:9140",
Path: "/",
},
Weight: 2.0,
Type: "proxy",
},
{
Request: router.Request{
Method: "GET",
Host: "localhost:9200",
Path: "/graph/",
},
ProxyURL: router.URL{
Scheme: "http",
Host: "localhost:9120",
Path: "/",
},
Weight: 2.0,
Type: "proxy",
},
{
Request: router.Request{
Method: "GET",
Host: "localhost:9200",
Path: "/graph-explorer/",
},
ProxyURL: router.URL{
Scheme: "http",
Host: "localhost:9135",
Path: "/",
},
Weight: 2.0,
Type: "proxy",
},
{
Request: router.Request{
Method: "GET",
Host: "localhost:9200",
Path: "/",
},
ProxyURL: router.URL{
Scheme: "http",
Host: "localhost:9100",
Path: "/",
},
Weight: 2.0,
Type: "proxy",
},
}
apiConfig := map[string]interface{}{
"api": map[string]interface{}{
"routes": routes,
},
}
b, _ := json.Marshal(apiConfig)
m := memory.NewSource(memory.WithJSON(b))
conf, err := config.NewConfig(config.WithSource(m))
phoenixURL, err := url.Parse("http://localhost:9100")
if err != nil {
options.Logger.Fatal().
Err(err).
Msg("could not parse routes")
log.Fatal(err)
}
konnectdURL, err := url.Parse("http://localhost:9130")
if err != nil {
log.Fatal(err)
}
r := router.NewRouter(router.Config(conf))
wr := r.Handler()
h := wr(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Error(w, "not found", 404)
}))
service.Handle(
"/",
h,
)
service.Handle("/", httputil.NewSingleHostReverseProxy(phoenixURL))
service.Handle("/.well-known/openid-configuration", httputil.NewSingleHostReverseProxy(konnectdURL))
service.Handle("/konnect/v1/jwks.json/", httputil.NewSingleHostReverseProxy(konnectdURL))
service.Handle("/konnect/v1/token/", httputil.NewSingleHostReverseProxy(konnectdURL))
service.Handle("/konnect/v1/userinfo/", httputil.NewSingleHostReverseProxy(konnectdURL))
service.Handle("/konnect/v1/static/", httputil.NewSingleHostReverseProxy(konnectdURL))
service.Handle("/konnect/v1/session/", httputil.NewSingleHostReverseProxy(konnectdURL))
service.Handle("/konnect/v1/register/", httputil.NewSingleHostReverseProxy(konnectdURL))
service.Init()
return service, nil
}