Skip to content

Commit

Permalink
Fix errors of public share provider according to cs3apis (#3501)
Browse files Browse the repository at this point in the history
* fix errors of public share provider according to cs3apis

* add changelog
  • Loading branch information
gmgigi96 authored Nov 29, 2022
1 parent 48a2870 commit d833b1c
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 29 deletions.
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
}

0 comments on commit d833b1c

Please sign in to comment.