Skip to content

Commit

Permalink
rewritten mux for graph svc
Browse files Browse the repository at this point in the history
  • Loading branch information
gmgigi96 committed Feb 13, 2024
1 parent 069a14e commit 32c4e11
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 34 deletions.
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -962,8 +962,6 @@ github.com/creasty/defaults v1.7.0 h1:eNdqZvc5B509z18lD8yc212CAqJNvfT1Jq6L8WowdB
github.com/creasty/defaults v1.7.0/go.mod h1:iGzKe6pbEHnpMPtfDXZEr0NVxWnPTjb1bbDy08fPzYM=
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e h1:tqSPWQeueWTKnJVMJffz4pz0o1WuQxJ28+5x5JgaHD8=
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4=
github.com/cs3org/go-cs3apis v0.0.0-20230727093620-0f4399be4543 h1:IFo6dj0XEOIA6i2baRWMC3vd+fAmuIUAVfSf77ZhoQg=
github.com/cs3org/go-cs3apis v0.0.0-20230727093620-0f4399be4543/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/cs3org/go-cs3apis v0.0.0-20231219091702-aa0d20fe6e00 h1:Gsr47puiAAp7mvvAkOmpsBPYzE1bQxQ8R0opgWkIXN4=
github.com/cs3org/go-cs3apis v0.0.0-20231219091702-aa0d20fe6e00/go.mod h1:yyP8PRo0EZou3nSH7H4qjlzQwaydPeIRNgX50npQHpE=
github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4=
Expand Down Expand Up @@ -2118,7 +2116,6 @@ golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190415081028-16da32be82c5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down Expand Up @@ -2463,7 +2460,6 @@ google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAs
google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190404172233-64821d5d2107/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
Expand Down
12 changes: 11 additions & 1 deletion internal/grpc/services/spacesregistry/spacesregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,21 @@ func (s *service) CreateStorageSpace(ctx context.Context, req *provider.CreateSt
return nil, errors.New("not yet implemented")
}

func countTypeFilters(filters []*provider.ListStorageSpacesRequest_Filter) (count int) {
for _, f := range filters {
if f.Type == provider.ListStorageSpacesRequest_Filter_TYPE_SPACE_TYPE {
count++
}
}
return
}

func (s *service) ListStorageSpaces(ctx context.Context, req *provider.ListStorageSpacesRequest) (*provider.ListStorageSpacesResponse, error) {
user := appctx.ContextMustGetUser(ctx)
filters := req.Filters

sp := []*provider.StorageSpace{}
if len(filters) == 0 {
if countTypeFilters(filters) == 0 {
homes, err := s.listSpacesByType(ctx, user, spaces.SpaceTypeHome)
if err != nil {
return &provider.ListStorageSpacesResponse{Status: status.NewInternal(ctx, err, err.Error())}, nil
Expand All @@ -131,6 +140,7 @@ func (s *service) ListStorageSpaces(ctx context.Context, req *provider.ListStora
return &provider.ListStorageSpacesResponse{Status: status.NewInternal(ctx, err, err.Error())}, nil
}
sp = append(sp, spaces...)
case provider.ListStorageSpacesRequest_Filter_TYPE_ID:
default:
return nil, errtypes.NotSupported("filter not supported")
}
Expand Down
4 changes: 2 additions & 2 deletions internal/http/services/owncloud/ocgraph/drives.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ import (
collaborationv1beta1 "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1"
providerpb "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/cs3org/reva/pkg/appctx"
"github.com/cs3org/reva/pkg/rhttp/router"
"github.com/cs3org/reva/pkg/spaces"
"github.com/cs3org/reva/pkg/utils/list"
"github.com/cs3org/reva/pkg/utils/resourceid"
"github.com/go-chi/chi/v5"
libregraph "github.com/owncloud/libre-graph-api-go"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -267,7 +267,7 @@ func (s *svc) getSpace(w http.ResponseWriter, r *http.Request) {
return
}

spaceID := chi.URLParam(r, "space-id")
spaceID, _ := router.ShiftPath(r.URL.Path)
if isShareJail(spaceID) {
shareRes, err := gw.GetReceivedShare(ctx, &collaborationv1beta1.GetReceivedShareRequest{
Ref: &collaborationv1beta1.ShareReference{
Expand Down
58 changes: 31 additions & 27 deletions internal/http/services/owncloud/ocgraph/ocgraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -47,8 +47,7 @@ func (c *config) ApplyDefaults() {
}

type svc struct {
c *config
router *chi.Mux
c *config
}

func New(ctx context.Context, m map[string]interface{}) (global.Service, error) {
Expand All @@ -57,40 +56,45 @@ func New(ctx context.Context, m map[string]interface{}) (global.Service, error)
return nil, err
}

r := chi.NewRouter()
s := &svc{
c: &c,
router: r,
}

if err := s.routerInit(); err != nil {
return nil, err
c: &c,
}

return s, nil
}

func (s *svc) routerInit() error {
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)
})
})
return nil
}

func (s *svc) getClient() (gateway.GatewayAPIClient, error) {
return pool.GetGatewayServiceClient(pool.Endpoint(s.c.GatewaySvc))
}

func (s *svc) Handler() http.Handler { return s.router }
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)

switch head {
case "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
}
}
}

w.WriteHeader(http.StatusNotFound)
})
}

func (s *svc) Prefix() string { return "graph" }

Expand Down

0 comments on commit 32c4e11

Please sign in to comment.