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

Fix errors of public share provider according to cs3apis #3501

Merged
merged 2 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions changelog/unreleased/errors-public-share-provider.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Bugfix: Fix errors of public share provider according to cs3apis

All the errors returned by the public share provider
where internal errors. Now this has been fixed and the
returned errors are the one defined in the cs3apis.

https://github.com/cs3org/reva/pull/3501
87 changes: 58 additions & 29 deletions internal/grpc/services/publicshareprovider/publicshareprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,25 @@ func (s *service) CreatePublicShare(ctx context.Context, req *link.CreatePublicS
}

share, err := s.sm.CreatePublicShare(ctx, u, req.ResourceInfo, req.Grant, req.Description, req.Internal)
if err != nil {
log.Debug().Err(err).Str("createShare", "shares").Msg("error connecting to storage provider")
}

res := &link.CreatePublicShareResponse{
Status: status.NewOK(ctx),
Share: share,
switch err.(type) {
case nil:
return &link.CreatePublicShareResponse{
Status: status.NewOK(ctx),
Share: share,
}, nil
case errtypes.NotFound:
return &link.CreatePublicShareResponse{
Status: status.NewNotFound(ctx, "resource does not exist"),
}, nil
case errtypes.AlreadyExists:
return &link.CreatePublicShareResponse{
Status: status.NewAlreadyExists(ctx, err, "share already exists"),
}, nil
default:
return &link.CreatePublicShareResponse{
Status: status.NewInternal(ctx, err, "unknown error"),
}, nil
}
return res, nil
}

func (s *service) RemovePublicShare(ctx context.Context, req *link.RemovePublicShareRequest) (*link.RemovePublicShareResponse, error) {
Expand All @@ -163,14 +173,20 @@ func (s *service) RemovePublicShare(ctx context.Context, req *link.RemovePublicS

user := ctxpkg.ContextMustGetUser(ctx)
err := s.sm.RevokePublicShare(ctx, user, req.Ref)
if err != nil {
switch err.(type) {
case nil:
return &link.RemovePublicShareResponse{
Status: status.NewOK(ctx),
}, nil
case errtypes.NotFound:
return &link.RemovePublicShareResponse{
Status: status.NewNotFound(ctx, "unknown token"),
}, nil
default:
return &link.RemovePublicShareResponse{
Status: status.NewInternal(ctx, err, "error deleting public share"),
}, err
}, nil
}
return &link.RemovePublicShareResponse{
Status: status.NewOK(ctx),
}, nil
}

func (s *service) GetPublicShareByToken(ctx context.Context, req *link.GetPublicShareByTokenRequest) (*link.GetPublicShareByTokenResponse, error) {
Expand Down Expand Up @@ -210,14 +226,21 @@ func (s *service) GetPublicShare(ctx context.Context, req *link.GetPublicShareRe
}

found, err := s.sm.GetPublicShare(ctx, u, req.Ref, req.GetSign())
if err != nil {
return nil, err
switch err.(type) {
case nil:
return &link.GetPublicShareResponse{
Status: status.NewOK(ctx),
Share: found,
}, nil
case errtypes.NotFound:
return &link.GetPublicShareResponse{
Status: status.NewNotFound(ctx, "share not found"),
}, nil
default:
return &link.GetPublicShareResponse{
Status: status.NewInternal(ctx, err, "unknown error"),
}, nil
}

return &link.GetPublicShareResponse{
Status: status.NewOK(ctx),
Share: found,
}, nil
}

func (s *service) ListPublicShares(ctx context.Context, req *link.ListPublicSharesRequest) (*link.ListPublicSharesResponse, error) {
Expand Down Expand Up @@ -249,14 +272,20 @@ func (s *service) UpdatePublicShare(ctx context.Context, req *link.UpdatePublicS
log.Error().Msg("error getting user from context")
}

updateR, err := s.sm.UpdatePublicShare(ctx, u, req, nil)
if err != nil {
log.Err(err).Msgf("error updating public shares: %v", err)
}

res := &link.UpdatePublicShareResponse{
Status: status.NewOK(ctx),
Share: updateR,
updated, err := s.sm.UpdatePublicShare(ctx, u, req, nil)
switch err.(type) {
case nil:
return &link.UpdatePublicShareResponse{
Status: status.NewOK(ctx),
Share: updated,
}, nil
case errtypes.NotFound:
return &link.UpdatePublicShareResponse{
Status: status.NewNotFound(ctx, "share not found"),
}, nil
default:
return &link.UpdatePublicShareResponse{
Status: status.NewInternal(ctx, err, "unknown error"),
}, nil
}
return res, nil
}