diff --git a/go.mod b/go.mod index f19d0e6213..900a186230 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/dolthub/go-mysql-server v0.14.0 github.com/gdexlab/go-render v1.0.1 github.com/glpatcern/go-mime v0.0.0-20221026162842-2a8d71ad17a9 - github.com/go-chi/chi/v5 v5.0.12 + github.com/go-chi/chi/v5 v5.1.0 github.com/go-ldap/ldap/v3 v3.4.6 github.com/go-playground/locales v0.14.1 github.com/go-playground/universal-translator v0.18.1 diff --git a/go.sum b/go.sum index a0e0b36431..095e39b4fa 100644 --- a/go.sum +++ b/go.sum @@ -960,6 +960,8 @@ github.com/go-asn1-ber/asn1-ber v1.5.5 h1:MNHlNMBDgEKD4TcKr36vQN68BA00aDfjIt3/bD github.com/go-asn1-ber/asn1-ber v1.5.5/go.mod h1:hEBeB/ic+5LoWskz+yKT7vGhhPYkProFKoKdwZRWMe0= github.com/go-chi/chi/v5 v5.0.12 h1:9euLV5sTrTNTRUU9POmDUvfxyj6LAABLUcEWO+JJb4s= github.com/go-chi/chi/v5 v5.0.12/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= +github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw= +github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/go-fonts/dejavu v0.1.0/go.mod h1:4Wt4I4OU2Nq9asgDCteaAaWZOV24E+0/Pwo0gppep4g= github.com/go-fonts/latin-modern v0.2.0/go.mod h1:rQVLdDMK+mK1xscDwsqM5J8U2jrRa3T0ecnM9pNujks= github.com/go-fonts/liberation v0.1.1/go.mod h1:K6qoJYypsmfVjWg8KOVDQhLc8UDgIK2HYqyqAO9z7GY= diff --git a/internal/http/services/owncloud/ocgraph/ocgraph.go b/internal/http/services/owncloud/ocgraph/ocgraph.go index cd210978fd..b903d96e80 100644 --- a/internal/http/services/owncloud/ocgraph/ocgraph.go +++ b/internal/http/services/owncloud/ocgraph/ocgraph.go @@ -27,9 +27,9 @@ import ( gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" "github.com/cs3org/reva/pkg/rgrpc/todo/pool" "github.com/cs3org/reva/pkg/rhttp/global" - "github.com/cs3org/reva/pkg/rhttp/router" "github.com/cs3org/reva/pkg/sharedconf" "github.com/cs3org/reva/pkg/utils/cfg" + "github.com/go-chi/chi/v5" ) func init() { @@ -47,7 +47,8 @@ func (c *config) ApplyDefaults() { } type svc struct { - c *config + c *config + router *chi.Mux } func New(ctx context.Context, m map[string]interface{}) (global.Service, error) { @@ -59,68 +60,35 @@ func New(ctx context.Context, m map[string]interface{}) (global.Service, error) s := &svc{ c: &c, } + s.initRouter() return s, nil } +func (s *svc) initRouter() { + s.router.Route("/v1.0", func(r chi.Router) { + r.Route("/me", func(r chi.Router) { + r.Get("/", s.getMe) + r.Route("/drives", func(r chi.Router) { + r.Get("/", s.listMySpaces) + + }) + }) + r.Route("/drives", func(r chi.Router) { + r.Get("/{space-id}", s.getSpace) + }) + }) + s.router.Route("/v1beta1", func(r chi.Router) { + r.Get("/me/drive/sharedWithMe", s.getSharedWithMe) + r.Get("/roleManagement/permissions/roleDefinitions", s.getRoleDefinitions) + }) +} + func (s *svc) getClient() (gateway.GatewayAPIClient, error) { return pool.GetGatewayServiceClient(pool.Endpoint(s.c.GatewaySvc)) } -func (s *svc) Handler() http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - var head string - head, r.URL.Path = router.ShiftPath(r.URL.Path) - - if head == "v1.0" { - head, r.URL.Path = router.ShiftPath(r.URL.Path) - switch head { - case "drives": - s.getSpace(w, r) - return - case "me": - head, r.URL.Path = router.ShiftPath(r.URL.Path) - switch head { - case "": - s.getMe(w, r) - return - case "drives": - s.listMySpaces(w, r) - return - } - } - } else if head == "v1beta1" { - head, r.URL.Path = router.ShiftPath(r.URL.Path) - // https://demo.owncloud.com/graph/v1beta1/me/drive/sharedWithMe - switch head { - case "me": - head, r.URL.Path = router.ShiftPath(r.URL.Path) - switch head { - case "drive": - head, r.URL.Path = router.ShiftPath(r.URL.Path) - switch head { - case "sharedWithMe": - s.getSharedWithMe(w, r) - return - } - } - case "roleManagement": - head, r.URL.Path = router.ShiftPath(r.URL.Path) - switch head { - case "permissions": - head, r.URL.Path = router.ShiftPath(r.URL.Path) - switch head { - case "roleDefinitions": - s.getRoleDefinitions(w, r) - return - } - } - } - } - - w.WriteHeader(http.StatusNotFound) - }) -} +func (s *svc) Handler() http.Handler { return s.router } func (s *svc) Prefix() string { return "graph" } diff --git a/internal/http/services/owncloud/ocgraph/shares.go b/internal/http/services/owncloud/ocgraph/shares.go index b778654677..baa9e8c46c 100644 --- a/internal/http/services/owncloud/ocgraph/shares.go +++ b/internal/http/services/owncloud/ocgraph/shares.go @@ -226,3 +226,7 @@ func (s *svc) cs3GranteeToSharePointIdentitySet(ctx context.Context, grantee *pr return p, nil } + +func (s *svc) getSharedByMe(w http.ResponseWriter, r *http.Request) { + +}