Skip to content

Commit

Permalink
owncloud/ocs: Move to go-chi/chi based URL routing
Browse files Browse the repository at this point in the history
This should help with code readability and make it easier to figure out
which code is executed for which URL.

Closes cs3org#1986
  • Loading branch information
rhafer committed Aug 31, 2021
1 parent aa070ff commit cb79c38
Show file tree
Hide file tree
Showing 18 changed files with 184 additions and 496 deletions.
4 changes: 4 additions & 0 deletions changelog/unreleased/owncloud-ocs-move-to-go-chi-routing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Enhancement: Move owncloud/ocs API to go-chi/chi based URL routing

https://github.com/cs3org/reva/pull/2006
https://github.com/cs3org/reva/issues/1986
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require (
github.com/cs3org/go-cs3apis v0.0.0-20210802070913-970eec344e59
github.com/eventials/go-tus v0.0.0-20200718001131-45c7ec8f5d59
github.com/gdexlab/go-render v1.0.1
github.com/go-chi/chi/v5 v5.0.3
github.com/go-ldap/ldap/v3 v3.3.0
github.com/go-openapi/errors v0.20.0 // indirect
github.com/go-openapi/strfmt v0.19.5 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm
github.com/gin-gonic/gin v1.5.0/go.mod h1:Nd6IXA8m5kNZdNEHMBd93KT+mdY3+bewLgRvmCsR2Do=
github.com/go-asn1-ber/asn1-ber v1.5.1 h1:pDbRAunXzIUXfx4CB2QJFv5IuPiuoW+sWvr/Us009o8=
github.com/go-asn1-ber/asn1-ber v1.5.1/go.mod h1:hEBeB/ic+5LoWskz+yKT7vGhhPYkProFKoKdwZRWMe0=
github.com/go-chi/chi/v5 v5.0.3 h1:khYQBdPivkYG1s1TAzDQG1f6eX4kD2TItYVZexL5rS4=
github.com/go-chi/chi/v5 v5.0.3/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
Expand Down
72 changes: 0 additions & 72 deletions internal/http/services/owncloud/ocs/handlers/apps/apps.go

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/cs3org/reva/internal/http/services/owncloud/ocs/response"
"github.com/cs3org/reva/pkg/appctx"
"github.com/cs3org/reva/pkg/rgrpc/todo/pool"
"github.com/cs3org/reva/pkg/rhttp/router"
"github.com/cs3org/reva/pkg/storage/utils/templates"
)

Expand All @@ -40,24 +39,13 @@ type Handler struct {
}

// Init initializes this and any contained handlers
func (h *Handler) Init(c *config.Config) error {
func (h *Handler) Init(c *config.Config) {
h.gatewayAddr = c.GatewaySvc
h.additionalInfoAttribute = c.AdditionalInfoAttribute
return nil
}

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
log := appctx.GetLogger(r.Context())

var head string
head, r.URL.Path = router.ShiftPath(r.URL.Path)

log.Debug().Str("head", head).Str("tail", r.URL.Path).Msg("http routing")

h.findSharees(w, r)
}

func (h *Handler) findSharees(w http.ResponseWriter, r *http.Request) {
// FindSharees implements the /apps/files_sharing/api/v1/sharees endpoint
func (h *Handler) FindSharees(w http.ResponseWriter, r *http.Request) {
log := appctx.GetLogger(r.Context())
term := r.URL.Query().Get("search")

Expand All @@ -71,7 +59,6 @@ func (h *Handler) findSharees(w http.ResponseWriter, r *http.Request) {
response.WriteOCSError(w, r, response.MetaServerError.StatusCode, "error getting gateway grpc client", err)
return
}

usersRes, err := gwc.FindUsers(r.Context(), &userpb.FindUsersRequest{Filter: term})
if err != nil {
response.WriteOCSError(w, r, response.MetaServerError.StatusCode, "error searching users", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,22 @@ import (
"github.com/cs3org/reva/internal/http/services/owncloud/ocs/response"
"github.com/cs3org/reva/pkg/appctx"
"github.com/cs3org/reva/pkg/rgrpc/todo/pool"
"github.com/go-chi/chi/v5"
"github.com/pkg/errors"
)

// AcceptReceivedShare handles Post Requests on /apps/files_sharing/api/v1/shares/{shareid}
func (h *Handler) AcceptReceivedShare(w http.ResponseWriter, r *http.Request) {
shareID := chi.URLParam(r, "shareid")
h.updateReceivedShare(w, r, shareID, false)
}

// RejectReceivedShare handles DELETE Requests on /apps/files_sharing/api/v1/shares/{shareid}
func (h *Handler) RejectReceivedShare(w http.ResponseWriter, r *http.Request) {
shareID := chi.URLParam(r, "shareid")
h.updateReceivedShare(w, r, shareID, true)
}

func (h *Handler) updateReceivedShare(w http.ResponseWriter, r *http.Request, shareID string, rejectShare bool) {
ctx := r.Context()
logger := appctx.GetLogger(ctx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
ocm "github.com/cs3org/go-cs3apis/cs3/sharing/ocm/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
"github.com/go-chi/chi/v5"

"github.com/cs3org/reva/internal/http/services/owncloud/ocs/conversions"
"github.com/cs3org/reva/internal/http/services/owncloud/ocs/response"
Expand Down Expand Up @@ -119,11 +120,13 @@ func (h *Handler) createFederatedCloudShare(w http.ResponseWriter, r *http.Reque
response.WriteOCSSuccess(w, r, "OCM Share created")
}

func (h *Handler) getFederatedShare(w http.ResponseWriter, r *http.Request, shareID string) {
// GetFederatedShare handles GET requests on /apps/files_sharing/api/v1/shares/remote_shares/{shareid}
func (h *Handler) GetFederatedShare(w http.ResponseWriter, r *http.Request) {

// TODO: Implement response with HAL schemating
ctx := r.Context()

shareID := chi.URLParam(r, "shareid")
gatewayClient, err := pool.GetGatewayServiceClient(h.gatewayAddr)
if err != nil {
response.WriteOCSError(w, r, response.MetaServerError.StatusCode, "error getting grpc gateway client", err)
Expand Down Expand Up @@ -153,7 +156,8 @@ func (h *Handler) getFederatedShare(w http.ResponseWriter, r *http.Request, shar
response.WriteOCSSuccess(w, r, share)
}

func (h *Handler) listFederatedShares(w http.ResponseWriter, r *http.Request) {
// ListFederatedShares handles GET requests on /apps/files_sharing/api/v1/shares/remote_shares
func (h *Handler) ListFederatedShares(w http.ResponseWriter, r *http.Request) {

// TODO Implement pagination.
// TODO Implement response with HAL schemating
Expand Down
Loading

0 comments on commit cb79c38

Please sign in to comment.