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

Make relative reference parameters in appprovider consistent with other services #2347

Open
ishank011 opened this issue Dec 9, 2021 · 1 comment

Comments

@ishank011
Copy link
Contributor

#2210 (comment)

@wkloucek
Copy link
Contributor

The below diff would change the behavior with the restriction of not using relative CS3api references. I would opt for waiting until all storage provider support relative references, then this will be cleaner and easier, since we can just pass both parameters into the relative CS3api reference.

diff --git a/internal/http/services/appprovider/appprovider.go b/internal/http/services/appprovider/appprovider.go
index ed101a0f..57c2e387 100644
--- a/internal/http/services/appprovider/appprovider.go
+++ b/internal/http/services/appprovider/appprovider.go
@@ -154,11 +154,7 @@ func (s *svc) handleNew(w http.ResponseWriter, r *http.Request) {
                return
        }
 
-       dirPart, filePart := path.Split(filename)
-       if dirPart != "" || filePart != filename {
-               writeError(w, r, appErrorInvalidParameter, "the filename must not contain a path segment", nil)
-               return
-       }
+       relativePath, filename := path.Split(filename)
 
        statParentContainerReq := &provider.StatRequest{
                Ref: &provider.Reference{
@@ -176,13 +172,29 @@ func (s *svc) handleNew(w http.ResponseWriter, r *http.Request) {
                return
        }
 
-       if parentContainer.Info.Type != provider.ResourceType_RESOURCE_TYPE_CONTAINER {
-               writeError(w, r, appErrorInvalidParameter, "the parent container id does not point to a container", nil)
+       statRelativeParentContainerReq := &provider.StatRequest{
+               Ref: &provider.Reference{
+                       Path: path.Join(parentContainer.Info.Path, utils.MakeRelativePath(relativePath)),
+               },
+       }
+       relativeParentContainer, err := client.Stat(ctx, statRelativeParentContainerReq)
+       if err != nil {
+               writeError(w, r, appErrorServerError, "error sending a grpc stat request", err)
+               return
+       }
+
+       if relativeParentContainer.Status.Code != rpc.Code_CODE_OK {
+               writeError(w, r, appErrorNotFound, "the path relative to the parent container is not accessible or does not exist", err)
+               return
+       }
+
+       if relativeParentContainer.Info.Type != provider.ResourceType_RESOURCE_TYPE_CONTAINER {
+               writeError(w, r, appErrorInvalidParameter, "the path relative to the parent container id does not point to a container", nil)
                return
        }
 
        fileRef := &provider.Reference{
-               Path: path.Join(parentContainer.Info.Path, utils.MakeRelativePath(filename)),
+               Path: path.Join(relativeParentContainer.Info.Path, utils.MakeRelativePath(filename)),
        }
 
        statFileReq := &provider.StatRequest{

@wkloucek wkloucek removed their assignment Apr 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants