From d833b1ca49d2bdbaddbb8676837c775679656ec3 Mon Sep 17 00:00:00 2001 From: Gianmaria Del Monte <39946305+gmgigi96@users.noreply.github.com> Date: Tue, 29 Nov 2022 17:11:17 +0100 Subject: [PATCH] Fix errors of public share provider according to cs3apis (#3501) * fix errors of public share provider according to cs3apis * add changelog --- .../errors-public-share-provider.md | 7 ++ .../publicshareprovider.go | 87 ++++++++++++------- 2 files changed, 65 insertions(+), 29 deletions(-) create mode 100644 changelog/unreleased/errors-public-share-provider.md diff --git a/changelog/unreleased/errors-public-share-provider.md b/changelog/unreleased/errors-public-share-provider.md new file mode 100644 index 0000000000..c73e512bd8 --- /dev/null +++ b/changelog/unreleased/errors-public-share-provider.md @@ -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 \ No newline at end of file diff --git a/internal/grpc/services/publicshareprovider/publicshareprovider.go b/internal/grpc/services/publicshareprovider/publicshareprovider.go index d93cfaf9b9..067834500b 100644 --- a/internal/grpc/services/publicshareprovider/publicshareprovider.go +++ b/internal/grpc/services/publicshareprovider/publicshareprovider.go @@ -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) { @@ -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) { @@ -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) { @@ -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 }