Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] introduce /dav/spaces endpoint && CS3 list spaces implementation (ocis driver only) #1678

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
d2f4fc4
add storage provider list spaces interface
butonic May 3, 2021
577caad
add stubs
butonic May 3, 2021
8e527a8
initial ocis implementation for list storage spaces
butonic May 3, 2021
569e244
minor fixes
butonic May 3, 2021
1d2467d
add thoughts on proper spaces persistence layout
butonic May 5, 2021
234d995
Initial spaces implementation.
May 6, 2021
43520ac
more spaces work
butonic May 6, 2021
7d3016f
filter spaces based on permissions, return name
butonic May 7, 2021
56de961
resolve linter issues
May 12, 2021
e4292f7
implement storage space support into the storageprovider
May 12, 2021
f65949d
fix dav spaces href
butonic May 14, 2021
17a36ea
GET preparations
butonic May 14, 2021
636723c
WIP: spaces datatx
May 14, 2021
3084c1d
Add spaces.go
May 14, 2021
d4bb62d
distinguish spaces/simple datatx
butonic May 14, 2021
a0c493b
make GET work for spaces
butonic May 14, 2021
11974df
MKCol implementation for spaces WIP
May 17, 2021
9f8d688
refactor CreateDir
butonic May 17, 2021
e2456c7
make MKCOL work for spaces
May 17, 2021
f3b2e61
implement delete for the spaces api
May 18, 2021
c90a6f7
fix: unwrap the requested reference before using it further
May 19, 2021
2de3176
implement MOVE for spaces
May 20, 2021
41ee813
simplify check if request body is empty
May 20, 2021
8b6f2f4
setup constants for webdav verbs
May 20, 2021
77f972c
fix listcontainers for spaces references
May 21, 2021
fdb6445
implement PROPPATCH for spaces
May 21, 2021
1d760bf
implement COPY for spaces
May 26, 2021
f3eb0e8
add cases for lock, unlock and report for spaces
May 27, 2021
08e2e08
implement PUT for spaces
May 27, 2021
71451fa
implement POST for spaces
May 27, 2021
bdddbd9
implement HEAD for spaces
May 27, 2021
dcfd8b3
clean up and deduplicate webdav HEAD code
May 28, 2021
b347ac3
clean up and deduplicate webdav DELETE code
May 28, 2021
dc196eb
clean up and deduplicate webdav GET code
May 28, 2021
eb58b0d
clean up and deduplicate webdav PROPFIND code
May 28, 2021
bcee4d7
clean up and deduplicate webdav MKCOL code
May 28, 2021
18418b1
clean up and deduplicate webdav MOVE code
May 28, 2021
84d7a71
clean up and deduplicate webdav PROPPATCH code
May 28, 2021
b900c19
clean up and deduplicate webdav COPY code
May 31, 2021
7b97467
clean up and deduplicate webdav TUS POST code
Jun 1, 2021
949fba0
clean up and deduplicate webdav PUT code
Jun 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 66 additions & 21 deletions internal/grpc/services/gateway/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (s *svc) ListStorageSpaces(ctx context.Context, req *provider.ListStorageSp
}
}
c, err := s.findByID(ctx, &provider.ResourceId{
OpaqueId: id.OpaqueId,
StorageId: id.OpaqueId, // TODO fix id is nil
})
if err != nil {
return &provider.ListStorageSpacesResponse{
Expand Down Expand Up @@ -196,6 +196,11 @@ func (s *svc) getHome(_ context.Context) string {

func (s *svc) InitiateFileDownload(ctx context.Context, req *provider.InitiateFileDownloadRequest) (*gateway.InitiateFileDownloadResponse, error) {
log := appctx.GetLogger(ctx)

if isStorageSpaceReference(req.Ref) {
return s.initiateFileDownload(ctx, req)
}

p, st := s.getPath(ctx, req.Ref)
if st.Code != rpc.Code_CODE_OK {
return &gateway.InitiateFileDownloadResponse{
Expand Down Expand Up @@ -419,6 +424,9 @@ func (s *svc) initiateFileDownload(ctx context.Context, req *provider.InitiateFi

func (s *svc) InitiateFileUpload(ctx context.Context, req *provider.InitiateFileUploadRequest) (*gateway.InitiateFileUploadResponse, error) {
log := appctx.GetLogger(ctx)
if isStorageSpaceReference(req.Ref) {
return s.initiateFileUpload(ctx, req)
}
p, st := s.getPath(ctx, req.Ref)
if st.Code != rpc.Code_CODE_OK {
return &gateway.InitiateFileUploadResponse{
Expand Down Expand Up @@ -662,6 +670,11 @@ func (s *svc) GetPath(ctx context.Context, req *provider.GetPathRequest) (*provi

func (s *svc) CreateContainer(ctx context.Context, req *provider.CreateContainerRequest) (*provider.CreateContainerResponse, error) {
log := appctx.GetLogger(ctx)

if isStorageSpaceReference(req.Ref) {
return s.createContainer(ctx, req)
}

p, st := s.getPath(ctx, req.Ref)
if st.Code != rpc.Code_CODE_OK {
return &provider.CreateContainerResponse{
Expand Down Expand Up @@ -1161,7 +1174,15 @@ func (s *svc) stat(ctx context.Context, req *provider.StatRequest) (*provider.St
Status: status.NewInternal(ctx, err, "error connecting to storage provider="+providers[0].Address),
}, nil
}
return c.Stat(ctx, req)
rsp, err := c.Stat(ctx, req)
if err != nil || rsp.Status.Code != rpc.Code_CODE_OK {
return rsp, err
}
if !isStorageSpaceReference(req.Ref) {
rsp.Info.Path = path.Join(providers[0].ProviderPath, rsp.Info.Path)
}

return rsp, nil
}

infoFromProviders := make([]*provider.ResourceInfo, len(providers))
Expand Down Expand Up @@ -1209,18 +1230,20 @@ func (s *svc) statOnProvider(ctx context.Context, req *provider.StatRequest, res
return
}

resPath := path.Clean(req.Ref.GetPath())
newPath := req.Ref.GetPath()
if resPath != "" && !strings.HasPrefix(resPath, p.ProviderPath) {
newPath = p.ProviderPath
}
r, err := c.Stat(ctx, &provider.StatRequest{
Ref: &provider.Reference{
if !isStorageSpaceReference(req.Ref) {
resPath := path.Clean(req.Ref.GetPath())
newPath := req.Ref.GetPath()
if resPath != "" && !strings.HasPrefix(resPath, p.ProviderPath) {
newPath = p.ProviderPath
}
req.Ref = &provider.Reference{
Spec: &provider.Reference_Path{
Path: newPath,
},
},
})
}
}

r, err := c.Stat(ctx, req)
if err != nil {
*e = errors.Wrap(err, "gateway: error calling ListContainer")
return
Expand All @@ -1232,6 +1255,11 @@ func (s *svc) statOnProvider(ctx context.Context, req *provider.StatRequest, res
}

func (s *svc) Stat(ctx context.Context, req *provider.StatRequest) (*provider.StatResponse, error) {

if isStorageSpaceReference(req.Ref) {
return s.stat(ctx, req)
}

p, st := s.getPath(ctx, req.Ref, req.ArbitraryMetadataKeys...)
if st.Code != rpc.Code_CODE_OK {
return &provider.StatResponse{
Expand Down Expand Up @@ -1532,6 +1560,10 @@ func (s *svc) listSharesFolder(ctx context.Context) (*provider.ListContainerResp
return lcr, nil
}

func isStorageSpaceReference(ref *provider.Reference) bool {
return strings.HasPrefix(ref.GetId().GetOpaqueId(), "/")
}

func (s *svc) listContainer(ctx context.Context, req *provider.ListContainerRequest) (*provider.ListContainerResponse, error) {
providers, err := s.findProviders(ctx, req.Ref)
if err != nil {
Expand Down Expand Up @@ -1560,7 +1592,7 @@ func (s *svc) listContainer(ctx context.Context, req *provider.ListContainerRequ
}, nil
}
for _, inf := range infoFromProviders[i] {
if parent := path.Dir(inf.Path); resPath != "" && resPath != parent {
if parent := path.Dir(inf.Path); resPath != "." && resPath != parent {
parts := strings.Split(strings.TrimPrefix(inf.Path, resPath), "/")
p := path.Join(resPath, parts[1])
indirects[p] = append(indirects[p], inf)
Expand Down Expand Up @@ -1598,27 +1630,40 @@ func (s *svc) listContainerOnProvider(ctx context.Context, req *provider.ListCon
return
}

resPath := path.Clean(req.Ref.GetPath())
newPath := req.Ref.GetPath()
if resPath != "" && !strings.HasPrefix(resPath, p.ProviderPath) {
newPath = p.ProviderPath
}
r, err := c.ListContainer(ctx, &provider.ListContainerRequest{
Ref: &provider.Reference{
if !isStorageSpaceReference(req.Ref) {
resPath := path.Clean(req.Ref.GetPath())
newPath := req.Ref.GetPath()
if resPath != "" && !strings.HasPrefix(resPath, p.ProviderPath) {
newPath = p.ProviderPath
}
req.Ref = &provider.Reference{
Spec: &provider.Reference_Path{
Path: newPath,
},
},
})
}
}

r, err := c.ListContainer(ctx, req)
if err != nil {
*e = errors.Wrap(err, "gateway: error calling ListContainer")
return
}

if !isStorageSpaceReference(req.Ref) {
for i := range r.Infos {
r.Infos[i].Path = path.Join(p.ProviderPath, r.Infos[i].Path)
}
}
*res = r.Infos
}

func (s *svc) ListContainer(ctx context.Context, req *provider.ListContainerRequest) (*provider.ListContainerResponse, error) {
log := appctx.GetLogger(ctx)

if isStorageSpaceReference(req.Ref) {
return s.listContainer(ctx, req)
}

p, st := s.getPath(ctx, req.Ref, req.ArbitraryMetadataKeys...)
if st.Code != rpc.Code_CODE_OK {
return &provider.ListContainerResponse{
Expand Down
Loading