diff --git a/ADOPTERS.md b/ADOPTERS.md index 550bd8f51e..f935897737 100644 --- a/ADOPTERS.md +++ b/ADOPTERS.md @@ -6,4 +6,4 @@ If you'd like to be include here, please send a pull request modifying this file We intend to use this list to contact you for surveys and for sending invitations to events. We will also point to this list if we are asked who uses REVA. -We will not use any of the information here for protomotios nor to send other regular communications. +We will not use any of the information here for promotions nor to send other regular communications. diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 9926373a93..0af9cf8e48 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -1,6 +1,7 @@ - Alex Unger - Diogo Castro - Felix Hillingshaeuser +- Giuseppe Lo Presti - Hugo Gonzalez Labrador - Jörn Friedrich Dreyer - Mohitty diff --git a/cmd/revad/svcs/grpcsvcs/appprovidersvc/appprovidersvc.go b/cmd/revad/svcs/grpcsvcs/appprovidersvc/appprovidersvc.go index 188b29a9ca..2c7efcc457 100644 --- a/cmd/revad/svcs/grpcsvcs/appprovidersvc/appprovidersvc.go +++ b/cmd/revad/svcs/grpcsvcs/appprovidersvc/appprovidersvc.go @@ -24,12 +24,12 @@ import ( "io" appproviderv0alphapb "github.com/cs3org/go-cs3apis/cs3/appprovider/v0alpha" - rpcpb "github.com/cs3org/go-cs3apis/cs3/rpc" "github.com/cs3org/reva/cmd/revad/grpcserver" + "github.com/cs3org/reva/cmd/revad/svcs/grpcsvcs/status" "github.com/cs3org/reva/pkg/app" "github.com/cs3org/reva/pkg/app/provider/demo" - "github.com/cs3org/reva/pkg/appctx" "github.com/mitchellh/mapstructure" + "github.com/pkg/errors" "google.golang.org/grpc" ) @@ -89,19 +89,16 @@ func getProvider(c *config) (app.Provider, error) { } func (s *service) Open(ctx context.Context, req *appproviderv0alphapb.OpenRequest) (*appproviderv0alphapb.OpenResponse, error) { - log := appctx.GetLogger(ctx) - token := req.AccessToken - - iframeLocation, err := s.provider.GetIFrame(ctx, req.ResourceInfo.Id, token) + iframeLocation, err := s.provider.GetIFrame(ctx, req.ResourceInfo.Id, req.AccessToken) if err != nil { - log.Error().Err(err).Msg("error getting iframe") + err := errors.Wrap(err, "appprovidersvc: error calling GetIFrame") res := &appproviderv0alphapb.OpenResponse{ - Status: &rpcpb.Status{Code: rpcpb.Code_CODE_INTERNAL}, + Status: status.NewInternal(ctx, err, "error getting app's iframe"), } return res, nil } res := &appproviderv0alphapb.OpenResponse{ - Status: &rpcpb.Status{Code: rpcpb.Code_CODE_OK}, + Status: status.NewOK(ctx), IframeUrl: iframeLocation, } return res, nil diff --git a/cmd/revad/svcs/grpcsvcs/appregistrysvc/appregistrysvc.go b/cmd/revad/svcs/grpcsvcs/appregistrysvc/appregistrysvc.go index 41eab752c4..2ff92cd0f5 100644 --- a/cmd/revad/svcs/grpcsvcs/appregistrysvc/appregistrysvc.go +++ b/cmd/revad/svcs/grpcsvcs/appregistrysvc/appregistrysvc.go @@ -23,14 +23,13 @@ import ( "fmt" "io" - rpcpb "github.com/cs3org/go-cs3apis/cs3/rpc" "google.golang.org/grpc" appregistryv0alphapb "github.com/cs3org/go-cs3apis/cs3/appregistry/v0alpha" "github.com/cs3org/reva/cmd/revad/grpcserver" + "github.com/cs3org/reva/cmd/revad/svcs/grpcsvcs/status" "github.com/cs3org/reva/pkg/app" "github.com/cs3org/reva/pkg/app/registry/static" - "github.com/cs3org/reva/pkg/appctx" "github.com/mitchellh/mapstructure" ) @@ -90,19 +89,16 @@ func getRegistry(c *config) (app.Registry, error) { } func (s *svc) GetAppProviders(ctx context.Context, req *appregistryv0alphapb.GetAppProvidersRequest) (*appregistryv0alphapb.GetAppProvidersResponse, error) { - log := appctx.GetLogger(ctx) p, err := s.registry.FindProvider(ctx, req.ResourceInfo.MimeType) if err != nil { - log.Error().Err(err).Msg("error sending grpc find provider request") - res := &appregistryv0alphapb.GetAppProvidersResponse{ - Status: &rpcpb.Status{Code: rpcpb.Code_CODE_INTERNAL}, - } - return res, nil + return &appregistryv0alphapb.GetAppProvidersResponse{ + Status: status.NewInternal(ctx, err, "error looking for the app provider"), + }, nil } provider := format(p) res := &appregistryv0alphapb.GetAppProvidersResponse{ - Status: &rpcpb.Status{Code: rpcpb.Code_CODE_OK}, + Status: status.NewOK(ctx), Providers: []*appregistryv0alphapb.ProviderInfo{provider}, } return res, nil @@ -111,10 +107,9 @@ func (s *svc) GetAppProviders(ctx context.Context, req *appregistryv0alphapb.Get func (s *svc) ListAppProviders(ctx context.Context, req *appregistryv0alphapb.ListAppProvidersRequest) (*appregistryv0alphapb.ListAppProvidersResponse, error) { pvds, err := s.registry.ListProviders(ctx) if err != nil { - res := &appregistryv0alphapb.ListAppProvidersResponse{ - Status: &rpcpb.Status{Code: rpcpb.Code_CODE_INTERNAL}, - } - return res, nil + return &appregistryv0alphapb.ListAppProvidersResponse{ + Status: status.NewInternal(ctx, err, "error listing the app providers"), + }, nil } providers := make([]*appregistryv0alphapb.ProviderInfo, 0, len(pvds)) for _, pvd := range pvds { @@ -122,7 +117,7 @@ func (s *svc) ListAppProviders(ctx context.Context, req *appregistryv0alphapb.Li } res := &appregistryv0alphapb.ListAppProvidersResponse{ - Status: &rpcpb.Status{Code: rpcpb.Code_CODE_OK}, + Status: status.NewOK(ctx), Providers: providers, } return res, nil diff --git a/cmd/revad/svcs/grpcsvcs/authsvc/authsvc.go b/cmd/revad/svcs/grpcsvcs/authsvc/authsvc.go index 3067412ff9..2cb2323ea8 100644 --- a/cmd/revad/svcs/grpcsvcs/authsvc/authsvc.go +++ b/cmd/revad/svcs/grpcsvcs/authsvc/authsvc.go @@ -24,6 +24,7 @@ import ( "io" "github.com/cs3org/reva/cmd/revad/grpcserver" + "github.com/cs3org/reva/cmd/revad/svcs/grpcsvcs/status" "github.com/cs3org/reva/pkg/auth/manager/registry" tokenmgr "github.com/cs3org/reva/pkg/token/manager/registry" usermgr "github.com/cs3org/reva/pkg/user/manager/registry" @@ -34,7 +35,6 @@ import ( "github.com/cs3org/reva/pkg/user" authv0alphapb "github.com/cs3org/go-cs3apis/cs3/auth/v0alpha" - rpcpb "github.com/cs3org/go-cs3apis/cs3/rpc" typespb "github.com/cs3org/go-cs3apis/cs3/types" "github.com/cs3org/reva/pkg/appctx" @@ -134,49 +134,51 @@ func (s *service) GenerateAccessToken(ctx context.Context, req *authv0alphapb.Ge ctx, err := s.authmgr.Authenticate(ctx, username, password) if err != nil { - log.Error().Err(err).Msg("error authenticating user") - status := &rpcpb.Status{Code: rpcpb.Code_CODE_UNAUTHENTICATED} - res := &authv0alphapb.GenerateAccessTokenResponse{Status: status} + err = errors.Wrap(err, "authsvc: error in Authenticate") + res := &authv0alphapb.GenerateAccessTokenResponse{ + Status: status.NewUnauthenticated(ctx, err, "error authenticating user"), + } return res, nil } user, err := s.usermgr.GetUser(ctx, uid) if err != nil { - log.Error().Err(err).Msg("error getting user information") - status := &rpcpb.Status{Code: rpcpb.Code_CODE_UNAUTHENTICATED} - res := &authv0alphapb.GenerateAccessTokenResponse{Status: status} + err = errors.Wrap(err, "authsvc: error in GetUser") + res := &authv0alphapb.GenerateAccessTokenResponse{ + Status: status.NewUnauthenticated(ctx, err, "error getting user information"), + } return res, nil } accessToken, err := s.tokenmgr.MintToken(ctx, user) if err != nil { - err = errors.Wrap(err, "error creating access token") - log.Error().Err(err).Msg("error creating access token") - status := &rpcpb.Status{Code: rpcpb.Code_CODE_UNAUTHENTICATED} - res := &authv0alphapb.GenerateAccessTokenResponse{Status: status} + err = errors.Wrap(err, "authsvc: error in MintToken") + res := &authv0alphapb.GenerateAccessTokenResponse{ + Status: status.NewUnauthenticated(ctx, err, "error creating access token"), + } return res, nil } log.Info().Msgf("user %s authenticated", user.Username) - status := &rpcpb.Status{Code: rpcpb.Code_CODE_OK} - res := &authv0alphapb.GenerateAccessTokenResponse{Status: status, AccessToken: accessToken} + res := &authv0alphapb.GenerateAccessTokenResponse{ + Status: status.NewOK(ctx), + AccessToken: accessToken, + } return res, nil - } func (s *service) WhoAmI(ctx context.Context, req *authv0alphapb.WhoAmIRequest) (*authv0alphapb.WhoAmIResponse, error) { - log := appctx.GetLogger(ctx) - token := req.AccessToken - u, err := s.tokenmgr.DismantleToken(ctx, token) + u, err := s.tokenmgr.DismantleToken(ctx, req.AccessToken) if err != nil { - err = errors.Wrap(err, "error getting user from access token") - log.Error().Err(err).Msg("error dismantling access token") - status := &rpcpb.Status{Code: rpcpb.Code_CODE_UNAUTHENTICATED} - res := &authv0alphapb.WhoAmIResponse{Status: status} - return res, nil + err = errors.Wrap(err, "authsvc: error getting user from access token") + return &authv0alphapb.WhoAmIResponse{ + Status: status.NewUnauthenticated(ctx, err, "error dismantling access token"), + }, nil } - status := &rpcpb.Status{Code: rpcpb.Code_CODE_OK} - res := &authv0alphapb.WhoAmIResponse{Status: status, User: u} + res := &authv0alphapb.WhoAmIResponse{ + Status: status.NewOK(ctx), + User: u, + } return res, nil } diff --git a/cmd/revad/svcs/grpcsvcs/gatewaysvc/appprovidersvc.go b/cmd/revad/svcs/grpcsvcs/gatewaysvc/appprovidersvc.go index da4322ac93..1303cf9d6b 100644 --- a/cmd/revad/svcs/grpcsvcs/gatewaysvc/appprovidersvc.go +++ b/cmd/revad/svcs/grpcsvcs/gatewaysvc/appprovidersvc.go @@ -26,43 +26,38 @@ import ( rpcpb "github.com/cs3org/go-cs3apis/cs3/rpc" storageproviderv0alphapb "github.com/cs3org/go-cs3apis/cs3/storageprovider/v0alpha" "github.com/cs3org/reva/cmd/revad/svcs/grpcsvcs/pool" - "github.com/cs3org/reva/pkg/appctx" + "github.com/cs3org/reva/cmd/revad/svcs/grpcsvcs/status" "github.com/cs3org/reva/pkg/errtypes" "github.com/pkg/errors" ) func (s *svc) Open(ctx context.Context, req *appproviderv0alphapb.OpenRequest) (*appproviderv0alphapb.OpenResponse, error) { - log := appctx.GetLogger(ctx) provider, err := s.findAppProvider(ctx, req.ResourceInfo) if err != nil { - log.Err(err).Msg("gatewaysvc: error finding app provider") + err = errors.Wrap(err, "gatewaysvc: error calling findAppProvider") + var st *rpcpb.Status if _, ok := err.(errtypes.IsNotFound); ok { - return &appproviderv0alphapb.OpenResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_NOT_FOUND, - }, - }, nil + st = status.NewNotFound(ctx, "app provider not found") + } else { + st = status.NewInternal(ctx, err, "error searching for app provider") } + return &appproviderv0alphapb.OpenResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, + Status: st, }, nil } c, err := pool.GetAppProviderClient(provider.Address) if err != nil { - log.Err(err).Msg("gatewaysvc: error getting appprovider client") + err = errors.Wrap(err, "gatewaysvc: error calling GetAppProviderClient") return &appproviderv0alphapb.OpenResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, + Status: status.NewInternal(ctx, err, "error getting appprovider client"), }, nil } res, err := c.Open(ctx, req) if err != nil { - return nil, errors.Wrap(err, "gatewaysvc: error calling Open") + return nil, errors.Wrap(err, "gatewaysvc: error calling c.Open") } return res, nil @@ -91,7 +86,7 @@ func (s *svc) findAppProvider(ctx context.Context, ri *storageproviderv0alphapb. } if res.Status.Code == rpcpb.Code_CODE_NOT_FOUND { - return nil, errtypes.NotFound("gatewaysvc: app provider not found for resource:" + ri.String()) + return nil, errtypes.NotFound("gatewaysvc: app provider not found for resource: " + ri.String()) } return nil, errors.New("gatewaysvc: error finding a storage provider") diff --git a/cmd/revad/svcs/grpcsvcs/gatewaysvc/appregistry.go b/cmd/revad/svcs/grpcsvcs/gatewaysvc/appregistry.go index 52ffd7dd24..7d078951ce 100644 --- a/cmd/revad/svcs/grpcsvcs/gatewaysvc/appregistry.go +++ b/cmd/revad/svcs/grpcsvcs/gatewaysvc/appregistry.go @@ -22,22 +22,16 @@ import ( "context" appregistryv0alphapb "github.com/cs3org/go-cs3apis/cs3/appregistry/v0alpha" - rpcpb "github.com/cs3org/go-cs3apis/cs3/rpc" "github.com/cs3org/reva/cmd/revad/svcs/grpcsvcs/pool" - "github.com/cs3org/reva/pkg/appctx" + "github.com/cs3org/reva/cmd/revad/svcs/grpcsvcs/status" "github.com/pkg/errors" ) func (s *svc) GetAppProviders(ctx context.Context, req *appregistryv0alphapb.GetAppProvidersRequest) (*appregistryv0alphapb.GetAppProvidersResponse, error) { - log := appctx.GetLogger(ctx) - c, err := pool.GetAppRegistryClient(s.c.AppRegistryEndpoint) if err != nil { - log.Err(err).Msg("gatewaysvc: error getting appregistry client") return &appregistryv0alphapb.GetAppProvidersResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, + Status: status.NewInternal(ctx, err, "error getting app registry client"), }, nil } @@ -50,15 +44,10 @@ func (s *svc) GetAppProviders(ctx context.Context, req *appregistryv0alphapb.Get } func (s *svc) ListAppProviders(ctx context.Context, req *appregistryv0alphapb.ListAppProvidersRequest) (*appregistryv0alphapb.ListAppProvidersResponse, error) { - log := appctx.GetLogger(ctx) - c, err := pool.GetAppRegistryClient(s.c.AppRegistryEndpoint) if err != nil { - log.Err(err).Msg("gatewaysvc: error getting appregistry client") return &appregistryv0alphapb.ListAppProvidersResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, + Status: status.NewInternal(ctx, err, "error getting app registry client"), }, nil } diff --git a/cmd/revad/svcs/grpcsvcs/gatewaysvc/authsvc.go b/cmd/revad/svcs/grpcsvcs/gatewaysvc/authsvc.go index b44ef0e33f..5b855b0c5e 100644 --- a/cmd/revad/svcs/grpcsvcs/gatewaysvc/authsvc.go +++ b/cmd/revad/svcs/grpcsvcs/gatewaysvc/authsvc.go @@ -22,22 +22,16 @@ import ( "context" authv0alphapb "github.com/cs3org/go-cs3apis/cs3/auth/v0alpha" - rpcpb "github.com/cs3org/go-cs3apis/cs3/rpc" "github.com/cs3org/reva/cmd/revad/svcs/grpcsvcs/pool" - "github.com/cs3org/reva/pkg/appctx" + "github.com/cs3org/reva/cmd/revad/svcs/grpcsvcs/status" "github.com/pkg/errors" ) func (s *svc) GenerateAccessToken(ctx context.Context, req *authv0alphapb.GenerateAccessTokenRequest) (*authv0alphapb.GenerateAccessTokenResponse, error) { - log := appctx.GetLogger(ctx) - c, err := pool.GetAuthServiceClient(s.c.AuthEndpoint) if err != nil { - log.Err(err).Msg("gatewaysvc: error getting auth client") return &authv0alphapb.GenerateAccessTokenResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, + Status: status.NewInternal(ctx, err, "error getting auth client"), }, nil } @@ -50,15 +44,10 @@ func (s *svc) GenerateAccessToken(ctx context.Context, req *authv0alphapb.Genera } func (s *svc) WhoAmI(ctx context.Context, req *authv0alphapb.WhoAmIRequest) (*authv0alphapb.WhoAmIResponse, error) { - log := appctx.GetLogger(ctx) - c, err := pool.GetAuthServiceClient(s.c.AuthEndpoint) if err != nil { - log.Err(err).Msg("gatewaysvc: error getting auth client") return &authv0alphapb.WhoAmIResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, + Status: status.NewInternal(ctx, err, "error getting auth client"), }, nil } diff --git a/cmd/revad/svcs/grpcsvcs/gatewaysvc/preferencessvc.go b/cmd/revad/svcs/grpcsvcs/gatewaysvc/preferencessvc.go index f0dd59cfe0..4fb36c903d 100644 --- a/cmd/revad/svcs/grpcsvcs/gatewaysvc/preferencessvc.go +++ b/cmd/revad/svcs/grpcsvcs/gatewaysvc/preferencessvc.go @@ -22,22 +22,17 @@ import ( "context" preferencesv0alphapb "github.com/cs3org/go-cs3apis/cs3/preferences/v0alpha" - rpcpb "github.com/cs3org/go-cs3apis/cs3/rpc" "github.com/cs3org/reva/cmd/revad/svcs/grpcsvcs/pool" - "github.com/cs3org/reva/pkg/appctx" + "github.com/cs3org/reva/cmd/revad/svcs/grpcsvcs/status" "github.com/pkg/errors" ) func (s *svc) SetKey(ctx context.Context, req *preferencesv0alphapb.SetKeyRequest) (*preferencesv0alphapb.SetKeyResponse, error) { - log := appctx.GetLogger(ctx) - c, err := pool.GetPreferencesClient(s.c.PreferencesEndpoint) if err != nil { - log.Err(err).Msg("gatewaysvc: error getting preferences client") + err = errors.Wrap(err, "gatewaysvc: error calling GetPreferencesClient") return &preferencesv0alphapb.SetKeyResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, + Status: status.NewInternal(ctx, err, "error getting preferences client"), }, nil } @@ -50,15 +45,11 @@ func (s *svc) SetKey(ctx context.Context, req *preferencesv0alphapb.SetKeyReques } func (s *svc) GetKey(ctx context.Context, req *preferencesv0alphapb.GetKeyRequest) (*preferencesv0alphapb.GetKeyResponse, error) { - log := appctx.GetLogger(ctx) - c, err := pool.GetPreferencesClient(s.c.PreferencesEndpoint) if err != nil { - log.Err(err).Msg("gatewaysvc: error getting preferences client") + err = errors.Wrap(err, "gatewaysvc: error calling GetPreferencesClient") return &preferencesv0alphapb.GetKeyResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, + Status: status.NewInternal(ctx, err, "error getting preferences client"), }, nil } diff --git a/cmd/revad/svcs/grpcsvcs/gatewaysvc/storageprovidersvc.go b/cmd/revad/svcs/grpcsvcs/gatewaysvc/storageprovidersvc.go index fb2c1b40f6..c8e646cddb 100644 --- a/cmd/revad/svcs/grpcsvcs/gatewaysvc/storageprovidersvc.go +++ b/cmd/revad/svcs/grpcsvcs/gatewaysvc/storageprovidersvc.go @@ -26,6 +26,7 @@ import ( storageregistryv0alphapb "github.com/cs3org/go-cs3apis/cs3/storageregistry/v0alpha" storagetypespb "github.com/cs3org/go-cs3apis/cs3/storagetypes" "github.com/cs3org/reva/cmd/revad/svcs/grpcsvcs/pool" + "github.com/cs3org/reva/cmd/revad/svcs/grpcsvcs/status" "github.com/cs3org/reva/pkg/appctx" "github.com/cs3org/reva/pkg/errtypes" "github.com/pkg/errors" @@ -33,9 +34,7 @@ import ( func (s *svc) GetProvider(ctx context.Context, req *storageproviderv0alphapb.GetProviderRequest) (*storageproviderv0alphapb.GetProviderResponse, error) { res := &storageproviderv0alphapb.GetProviderResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_UNIMPLEMENTED, - }, + Status: status.NewUnimplemented(ctx, nil, "GetProvider not yet implemented"), } return res, nil } @@ -44,20 +43,13 @@ func (s *svc) InitiateFileDownload(ctx context.Context, req *storageproviderv0al log := appctx.GetLogger(ctx) pi, err := s.find(ctx, req.Ref) if err != nil { - log.Err(err).Msg("gatewaysvc: error finding storage provider") - if _, ok := err.(errtypes.IsNotFound); ok { return &storageproviderv0alphapb.InitiateFileDownloadResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_NOT_FOUND, - }, + Status: status.NewNotFound(ctx, "storage provider not found"), }, nil } - return &storageproviderv0alphapb.InitiateFileDownloadResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, + Status: status.NewInternal(ctx, err, "error finding storage provider"), }, nil } @@ -66,17 +58,14 @@ func (s *svc) InitiateFileDownload(ctx context.Context, req *storageproviderv0al // TODO(labkode): check for capabilities here c, err := pool.GetStorageProviderServiceClient(pi.Address) if err != nil { - log.Err(err).Msg("gatewaysvc: error getting storage provider client") return &storageproviderv0alphapb.InitiateFileDownloadResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, + Status: status.NewInternal(ctx, err, "error getting storage provider client"), }, nil } res, err := c.InitiateFileDownload(ctx, req) if err != nil { - return nil, errors.Wrap(err, "gatewaysvc: error calling Stat") + return nil, errors.Wrap(err, "gatewaysvc: error calling InitiateFileDownload") } return res, nil @@ -86,20 +75,13 @@ func (s *svc) InitiateFileUpload(ctx context.Context, req *storageproviderv0alph log := appctx.GetLogger(ctx) pi, err := s.find(ctx, req.Ref) if err != nil { - log.Err(err).Msg("gatewaysvc: error finding storage provider") - if _, ok := err.(errtypes.IsNotFound); ok { return &storageproviderv0alphapb.InitiateFileUploadResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_NOT_FOUND, - }, + Status: status.NewNotFound(ctx, "storage provider not found"), }, nil } - return &storageproviderv0alphapb.InitiateFileUploadResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, + Status: status.NewInternal(ctx, err, "error finding storage provider"), }, nil } @@ -108,17 +90,14 @@ func (s *svc) InitiateFileUpload(ctx context.Context, req *storageproviderv0alph // TODO(labkode): check for capabilities here c, err := pool.GetStorageProviderServiceClient(pi.Address) if err != nil { - log.Err(err).Msg("gatewaysvc: error getting storage provider client") return &storageproviderv0alphapb.InitiateFileUploadResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, + Status: status.NewInternal(ctx, err, "error getting storage provider client"), }, nil } res, err := c.InitiateFileUpload(ctx, req) if err != nil { - return nil, errors.Wrap(err, "gatewaysvc: error calling Stat") + return nil, errors.Wrap(err, "gatewaysvc: error calling InitiateFileDownload") } return res, nil @@ -126,9 +105,7 @@ func (s *svc) InitiateFileUpload(ctx context.Context, req *storageproviderv0alph func (s *svc) GetPath(ctx context.Context, req *storageproviderv0alphapb.GetPathRequest) (*storageproviderv0alphapb.GetPathResponse, error) { res := &storageproviderv0alphapb.GetPathResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_UNIMPLEMENTED, - }, + Status: status.NewUnimplemented(ctx, nil, "GetPath not yet implemented"), } return res, nil } @@ -137,20 +114,13 @@ func (s *svc) CreateContainer(ctx context.Context, req *storageproviderv0alphapb log := appctx.GetLogger(ctx) pi, err := s.find(ctx, req.Ref) if err != nil { - log.Err(err).Msg("gatewaysvc: error finding storage provider") - if _, ok := err.(errtypes.IsNotFound); ok { return &storageproviderv0alphapb.CreateContainerResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_NOT_FOUND, - }, + Status: status.NewNotFound(ctx, "storage provider not found"), }, nil } - return &storageproviderv0alphapb.CreateContainerResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, + Status: status.NewInternal(ctx, err, "error finding storage provider"), }, nil } @@ -159,17 +129,14 @@ func (s *svc) CreateContainer(ctx context.Context, req *storageproviderv0alphapb // TODO(labkode): check for capabilities here c, err := pool.GetStorageProviderServiceClient(pi.Address) if err != nil { - log.Err(err).Msg("gatewaysvc: error getting storage provider client") return &storageproviderv0alphapb.CreateContainerResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, + Status: status.NewInternal(ctx, err, "error getting storage provider client"), }, nil } res, err := c.CreateContainer(ctx, req) if err != nil { - return nil, errors.Wrap(err, "gatewaysvc: error calling Stat") + return nil, errors.Wrap(err, "gatewaysvc: error calling CreateContainer") } return res, nil @@ -179,20 +146,13 @@ func (s *svc) Delete(ctx context.Context, req *storageproviderv0alphapb.DeleteRe log := appctx.GetLogger(ctx) pi, err := s.find(ctx, req.Ref) if err != nil { - log.Err(err).Msg("gatewaysvc: error finding storage provider") - if _, ok := err.(errtypes.IsNotFound); ok { return &storageproviderv0alphapb.DeleteResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_NOT_FOUND, - }, + Status: status.NewNotFound(ctx, "storage provider not found"), }, nil } - return &storageproviderv0alphapb.DeleteResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, + Status: status.NewInternal(ctx, err, "error finding storage provider"), }, nil } @@ -201,17 +161,14 @@ func (s *svc) Delete(ctx context.Context, req *storageproviderv0alphapb.DeleteRe // TODO(labkode): check for capabilities here c, err := pool.GetStorageProviderServiceClient(pi.Address) if err != nil { - log.Err(err).Msg("gatewaysvc: error getting storage provider client") return &storageproviderv0alphapb.DeleteResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, + Status: status.NewInternal(ctx, err, "error getting storage provider client"), }, nil } res, err := c.Delete(ctx, req) if err != nil { - return nil, errors.Wrap(err, "gatewaysvc: error calling Stat") + return nil, errors.Wrap(err, "gatewaysvc: error calling Delete") } return res, nil @@ -219,9 +176,7 @@ func (s *svc) Delete(ctx context.Context, req *storageproviderv0alphapb.DeleteRe func (s *svc) Move(ctx context.Context, req *storageproviderv0alphapb.MoveRequest) (*storageproviderv0alphapb.MoveResponse, error) { res := &storageproviderv0alphapb.MoveResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_UNIMPLEMENTED, - }, + Status: status.NewUnimplemented(ctx, nil, "Move not yet implemented"), } return res, nil } @@ -230,20 +185,13 @@ func (s *svc) Stat(ctx context.Context, req *storageproviderv0alphapb.StatReques log := appctx.GetLogger(ctx) pi, err := s.find(ctx, req.Ref) if err != nil { - log.Err(err).Msg("gatewaysvc: error finding storage provider") - if _, ok := err.(errtypes.IsNotFound); ok { return &storageproviderv0alphapb.StatResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_NOT_FOUND, - }, + Status: status.NewNotFound(ctx, "storage provider not found"), }, nil } - return &storageproviderv0alphapb.StatResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, + Status: status.NewInternal(ctx, err, "error finding storage provider"), }, nil } @@ -252,11 +200,8 @@ func (s *svc) Stat(ctx context.Context, req *storageproviderv0alphapb.StatReques // TODO(labkode): check for capabilities here c, err := pool.GetStorageProviderServiceClient(pi.Address) if err != nil { - log.Err(err).Msg("gatewaysvc: error getting storage provider client") return &storageproviderv0alphapb.StatResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, + Status: status.NewInternal(ctx, err, "error getting storage provider client"), }, nil } @@ -269,27 +214,20 @@ func (s *svc) Stat(ctx context.Context, req *storageproviderv0alphapb.StatReques } func (s *svc) ListContainerStream(req *storageproviderv0alphapb.ListContainerStreamRequest, ss storageproviderv0alphapb.StorageProviderService_ListContainerStreamServer) error { - return errors.New("unimplemented") + return errors.New("Unimplemented") } func (s *svc) ListContainer(ctx context.Context, req *storageproviderv0alphapb.ListContainerRequest) (*storageproviderv0alphapb.ListContainerResponse, error) { log := appctx.GetLogger(ctx) pi, err := s.find(ctx, req.Ref) if err != nil { - log.Err(err).Msg("gatewaysvc: error finding storage provider") - if _, ok := err.(errtypes.IsNotFound); ok { return &storageproviderv0alphapb.ListContainerResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_NOT_FOUND, - }, + Status: status.NewNotFound(ctx, "storage provider not found"), }, nil } - return &storageproviderv0alphapb.ListContainerResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, + Status: status.NewInternal(ctx, err, "error finding storage provider"), }, nil } @@ -298,11 +236,8 @@ func (s *svc) ListContainer(ctx context.Context, req *storageproviderv0alphapb.L // TODO(labkode): check for capabilities here c, err := pool.GetStorageProviderServiceClient(pi.Address) if err != nil { - log.Err(err).Msg("gatewaysvc: error getting storage provider client") return &storageproviderv0alphapb.ListContainerResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, + Status: status.NewInternal(ctx, err, "error getting storage provider client"), }, nil } @@ -318,20 +253,13 @@ func (s *svc) ListFileVersions(ctx context.Context, req *storageproviderv0alphap log := appctx.GetLogger(ctx) pi, err := s.find(ctx, req.Ref) if err != nil { - log.Err(err).Msg("gatewaysvc: error finding storage provider") - if _, ok := err.(errtypes.IsNotFound); ok { return &storageproviderv0alphapb.ListFileVersionsResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_NOT_FOUND, - }, + Status: status.NewNotFound(ctx, "storage provider not found"), }, nil } - return &storageproviderv0alphapb.ListFileVersionsResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, + Status: status.NewInternal(ctx, err, "error finding storage provider"), }, nil } @@ -340,17 +268,14 @@ func (s *svc) ListFileVersions(ctx context.Context, req *storageproviderv0alphap // TODO(labkode): check for capabilities here c, err := pool.GetStorageProviderServiceClient(pi.Address) if err != nil { - log.Err(err).Msg("gatewaysvc: error getting storage provider client") return &storageproviderv0alphapb.ListFileVersionsResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, + Status: status.NewInternal(ctx, err, "error getting storage provider client"), }, nil } res, err := c.ListFileVersions(ctx, req) if err != nil { - return nil, errors.Wrap(err, "gatewaysvc: error calling Stat") + return nil, errors.Wrap(err, "gatewaysvc: error calling ListFileVersions") } return res, nil @@ -360,20 +285,13 @@ func (s *svc) RestoreFileVersion(ctx context.Context, req *storageproviderv0alph log := appctx.GetLogger(ctx) pi, err := s.find(ctx, req.Ref) if err != nil { - log.Err(err).Msg("gatewaysvc: error finding storage provider") - if _, ok := err.(errtypes.IsNotFound); ok { return &storageproviderv0alphapb.RestoreFileVersionResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_NOT_FOUND, - }, + Status: status.NewNotFound(ctx, "storage provider not found"), }, nil } - return &storageproviderv0alphapb.RestoreFileVersionResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, + Status: status.NewInternal(ctx, err, "error finding storage provider"), }, nil } @@ -382,51 +300,42 @@ func (s *svc) RestoreFileVersion(ctx context.Context, req *storageproviderv0alph // TODO(labkode): check for capabilities here c, err := pool.GetStorageProviderServiceClient(pi.Address) if err != nil { - log.Err(err).Msg("gatewaysvc: error getting storage provider client") return &storageproviderv0alphapb.RestoreFileVersionResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, + Status: status.NewInternal(ctx, err, "error getting storage provider client"), }, nil } res, err := c.RestoreFileVersion(ctx, req) if err != nil { - return nil, errors.Wrap(err, "gatewaysvc: error calling Stat") + return nil, errors.Wrap(err, "gatewaysvc: error calling RestoreFileVersion") } return res, nil } func (s *svc) ListRecycleStream(req *storageproviderv0alphapb.ListRecycleStreamRequest, ss storageproviderv0alphapb.StorageProviderService_ListRecycleStreamServer) error { - return errors.New("unimplemented") + return errors.New("Unimplemented") } func (s *svc) ListRecycle(ctx context.Context, req *storageproviderv0alphapb.ListRecycleRequest) (*storageproviderv0alphapb.ListRecycleResponse, error) { // TODO(labkode): query all available storage providers to get unified list as the request does not come // with ref information to target only one storage provider. res := &storageproviderv0alphapb.ListRecycleResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_UNIMPLEMENTED, - }, + Status: status.NewUnimplemented(ctx, nil, "ListRecycle not yet implemented"), } return res, nil } func (s *svc) RestoreRecycleItem(ctx context.Context, req *storageproviderv0alphapb.RestoreRecycleItemRequest) (*storageproviderv0alphapb.RestoreRecycleItemResponse, error) { res := &storageproviderv0alphapb.RestoreRecycleItemResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_UNIMPLEMENTED, - }, + Status: status.NewUnimplemented(ctx, nil, "RestoreRecycleItem not yet implemented"), } return res, nil } func (s *svc) PurgeRecycle(ctx context.Context, req *storageproviderv0alphapb.PurgeRecycleRequest) (*storageproviderv0alphapb.PurgeRecycleResponse, error) { res := &storageproviderv0alphapb.PurgeRecycleResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_UNIMPLEMENTED, - }, + Status: status.NewUnimplemented(ctx, nil, "PurgeRecycle not yet implemented"), } return res, nil } @@ -435,20 +344,13 @@ func (s *svc) ListGrants(ctx context.Context, req *storageproviderv0alphapb.List log := appctx.GetLogger(ctx) pi, err := s.find(ctx, req.Ref) if err != nil { - log.Err(err).Msg("gatewaysvc: error finding storage provider") - if _, ok := err.(errtypes.IsNotFound); ok { return &storageproviderv0alphapb.ListGrantsResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_NOT_FOUND, - }, + Status: status.NewNotFound(ctx, "storage provider not found"), }, nil } - return &storageproviderv0alphapb.ListGrantsResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, + Status: status.NewInternal(ctx, err, "error finding storage provider"), }, nil } @@ -457,17 +359,14 @@ func (s *svc) ListGrants(ctx context.Context, req *storageproviderv0alphapb.List // TODO(labkode): check for capabilities here c, err := pool.GetStorageProviderServiceClient(pi.Address) if err != nil { - log.Err(err).Msg("gatewaysvc: error getting storage provider client") return &storageproviderv0alphapb.ListGrantsResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, + Status: status.NewInternal(ctx, err, "error getting storage provider client"), }, nil } res, err := c.ListGrants(ctx, req) if err != nil { - return nil, errors.Wrap(err, "gatewaysvc: error calling Stat") + return nil, errors.Wrap(err, "gatewaysvc: error calling ListGrants") } return res, nil @@ -477,39 +376,29 @@ func (s *svc) AddGrant(ctx context.Context, req *storageproviderv0alphapb.AddGra log := appctx.GetLogger(ctx) pi, err := s.find(ctx, req.Ref) if err != nil { - log.Err(err).Msg("gatewaysvc: error finding storage provider") - if _, ok := err.(errtypes.IsNotFound); ok { return &storageproviderv0alphapb.AddGrantResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_NOT_FOUND, - }, + Status: status.NewNotFound(ctx, "storage provider not found"), }, nil } - return &storageproviderv0alphapb.AddGrantResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, + Status: status.NewInternal(ctx, err, "error finding storage provider"), }, nil } - log.Info().Str("address", pi.Address).Str("ref", req.Ref.String()).Str("provider", pi.String()).Msg("storage provider found") + log.Info().Str("address", pi.Address).Str("ref", req.Ref.String()).Msg("storage provider found") // TODO(labkode): check for capabilities here c, err := pool.GetStorageProviderServiceClient(pi.Address) if err != nil { - log.Err(err).Msg("gatewaysvc: error getting storage provider client") return &storageproviderv0alphapb.AddGrantResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, + Status: status.NewInternal(ctx, err, "error getting storage provider client"), }, nil } res, err := c.AddGrant(ctx, req) if err != nil { - return nil, errors.Wrap(err, "gatewaysvc: error calling Stat") + return nil, errors.Wrap(err, "gatewaysvc: error calling AddGrant") } return res, nil @@ -519,20 +408,13 @@ func (s *svc) UpdateGrant(ctx context.Context, req *storageproviderv0alphapb.Upd log := appctx.GetLogger(ctx) pi, err := s.find(ctx, req.Ref) if err != nil { - log.Err(err).Msg("gatewaysvc: error finding storage provider") - if _, ok := err.(errtypes.IsNotFound); ok { return &storageproviderv0alphapb.UpdateGrantResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_NOT_FOUND, - }, + Status: status.NewNotFound(ctx, "storage provider not found"), }, nil } - return &storageproviderv0alphapb.UpdateGrantResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, + Status: status.NewInternal(ctx, err, "error finding storage provider"), }, nil } @@ -541,17 +423,14 @@ func (s *svc) UpdateGrant(ctx context.Context, req *storageproviderv0alphapb.Upd // TODO(labkode): check for capabilities here c, err := pool.GetStorageProviderServiceClient(pi.Address) if err != nil { - log.Err(err).Msg("gatewaysvc: error getting storage provider client") return &storageproviderv0alphapb.UpdateGrantResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, + Status: status.NewInternal(ctx, err, "error getting storage provider client"), }, nil } res, err := c.UpdateGrant(ctx, req) if err != nil { - return nil, errors.Wrap(err, "gatewaysvc: error calling Stat") + return nil, errors.Wrap(err, "gatewaysvc: error calling UpdateGrant") } return res, nil @@ -561,20 +440,13 @@ func (s *svc) RemoveGrant(ctx context.Context, req *storageproviderv0alphapb.Rem log := appctx.GetLogger(ctx) pi, err := s.find(ctx, req.Ref) if err != nil { - log.Err(err).Msg("gatewaysvc: error finding storage provider") - if _, ok := err.(errtypes.IsNotFound); ok { return &storageproviderv0alphapb.RemoveGrantResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_NOT_FOUND, - }, + Status: status.NewNotFound(ctx, "storage provider not found"), }, nil } - return &storageproviderv0alphapb.RemoveGrantResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, + Status: status.NewInternal(ctx, err, "error finding storage provider"), }, nil } @@ -583,17 +455,14 @@ func (s *svc) RemoveGrant(ctx context.Context, req *storageproviderv0alphapb.Rem // TODO(labkode): check for capabilities here c, err := pool.GetStorageProviderServiceClient(pi.Address) if err != nil { - log.Err(err).Msg("gatewaysvc: error getting storage provider client") return &storageproviderv0alphapb.RemoveGrantResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, + Status: status.NewInternal(ctx, err, "error getting storage provider client"), }, nil } res, err := c.RemoveGrant(ctx, req) if err != nil { - return nil, errors.Wrap(err, "gatewaysvc: error calling Stat") + return nil, errors.Wrap(err, "gatewaysvc: error calling RemoveGrant") } return res, nil @@ -601,9 +470,7 @@ func (s *svc) RemoveGrant(ctx context.Context, req *storageproviderv0alphapb.Rem func (s *svc) GetQuota(ctx context.Context, req *storageproviderv0alphapb.GetQuotaRequest) (*storageproviderv0alphapb.GetQuotaResponse, error) { res := &storageproviderv0alphapb.GetQuotaResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_UNIMPLEMENTED, - }, + Status: status.NewUnimplemented(ctx, nil, "GetQuota not yet implemented"), } return res, nil } diff --git a/cmd/revad/svcs/grpcsvcs/gatewaysvc/storageregistrysvc.go b/cmd/revad/svcs/grpcsvcs/gatewaysvc/storageregistrysvc.go index 87378e510c..94c4784b50 100644 --- a/cmd/revad/svcs/grpcsvcs/gatewaysvc/storageregistrysvc.go +++ b/cmd/revad/svcs/grpcsvcs/gatewaysvc/storageregistrysvc.go @@ -21,23 +21,18 @@ package gatewaysvc import ( "context" - rpcpb "github.com/cs3org/go-cs3apis/cs3/rpc" storageregv0alphapb "github.com/cs3org/go-cs3apis/cs3/storageregistry/v0alpha" "github.com/cs3org/reva/cmd/revad/svcs/grpcsvcs/pool" - "github.com/cs3org/reva/pkg/appctx" + "github.com/cs3org/reva/cmd/revad/svcs/grpcsvcs/status" "github.com/pkg/errors" ) func (s *svc) ListStorageProviders(ctx context.Context, req *storageregv0alphapb.ListStorageProvidersRequest) (*storageregv0alphapb.ListStorageProvidersResponse, error) { - log := appctx.GetLogger(ctx) - c, err := pool.GetStorageRegistryClient(s.c.StorageRegistryEndpoint) if err != nil { - log.Err(err).Msg("gatewaysvc: error getting storageregistry client") + err = errors.Wrap(err, "gatewaysvc: error calling GetStorageRegistryClient") return &storageregv0alphapb.ListStorageProvidersResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, + Status: status.NewInternal(ctx, err, "error getting storage registry client"), }, nil } @@ -50,15 +45,11 @@ func (s *svc) ListStorageProviders(ctx context.Context, req *storageregv0alphapb } func (s *svc) GetStorageProvider(ctx context.Context, req *storageregv0alphapb.GetStorageProviderRequest) (*storageregv0alphapb.GetStorageProviderResponse, error) { - log := appctx.GetLogger(ctx) - c, err := pool.GetStorageRegistryClient(s.c.StorageRegistryEndpoint) if err != nil { - log.Err(err).Msg("gatewaysvc: error getting storageregistry client") + err = errors.Wrap(err, "gatewaysvc: error calling GetStorageRegistryClient") return &storageregv0alphapb.GetStorageProviderResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, + Status: status.NewInternal(ctx, err, "error getting storage registry client"), }, nil } diff --git a/cmd/revad/svcs/grpcsvcs/gatewaysvc/usershareprovidersvc.go b/cmd/revad/svcs/grpcsvcs/gatewaysvc/usershareprovidersvc.go index b240f3b0b1..a30f15f0eb 100644 --- a/cmd/revad/svcs/grpcsvcs/gatewaysvc/usershareprovidersvc.go +++ b/cmd/revad/svcs/grpcsvcs/gatewaysvc/usershareprovidersvc.go @@ -26,21 +26,15 @@ import ( usershareproviderv0alphapb "github.com/cs3org/go-cs3apis/cs3/usershareprovider/v0alpha" "github.com/cs3org/reva/cmd/revad/svcs/grpcsvcs/pool" "github.com/cs3org/reva/cmd/revad/svcs/grpcsvcs/status" - "github.com/cs3org/reva/pkg/appctx" "github.com/pkg/errors" ) // TODO(labkode): add multi-phase commit logic when commit share or commit ref is enabled. func (s *svc) CreateShare(ctx context.Context, req *usershareproviderv0alphapb.CreateShareRequest) (*usershareproviderv0alphapb.CreateShareResponse, error) { - log := appctx.GetLogger(ctx) - c, err := pool.GetUserShareProviderClient(s.c.UserShareProviderEndpoint) if err != nil { - log.Err(err).Msg("gatewaysvc: error getting usershareprovider client") return &usershareproviderv0alphapb.CreateShareResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, + Status: status.NewInternal(ctx, err, "error getting user share provider client"), }, nil } @@ -77,7 +71,8 @@ func (s *svc) CreateShare(ctx context.Context, req *usershareproviderv0alphapb.C } if grantRes.Status.Code != rpcpb.Code_CODE_OK { res := &usershareproviderv0alphapb.CreateShareResponse{ - Status: status.NewInternal(ctx, "error committing share to storage grant"), + Status: status.NewInternal(ctx, status.NewErrorFromCode(grantRes.Status.Code, "gatewaysvc"), + "error committing share to storage grant"), } return res, nil } @@ -87,13 +82,10 @@ func (s *svc) CreateShare(ctx context.Context, req *usershareproviderv0alphapb.C } func (s *svc) RemoveShare(ctx context.Context, req *usershareproviderv0alphapb.RemoveShareRequest) (*usershareproviderv0alphapb.RemoveShareResponse, error) { - log := appctx.GetLogger(ctx) - c, err := pool.GetUserShareProviderClient(s.c.UserShareProviderEndpoint) if err != nil { - log.Err(err).Msg("gatewaysvc: error getting usershareprovider client") return &usershareproviderv0alphapb.RemoveShareResponse{ - Status: status.NewInternal(ctx, "error getting user share provider client"), + Status: status.NewInternal(ctx, err, "error getting user share provider client"), }, nil } @@ -110,7 +102,8 @@ func (s *svc) RemoveShare(ctx context.Context, req *usershareproviderv0alphapb.R if getShareRes.Status.Code != rpcpb.Code_CODE_OK { res := &usershareproviderv0alphapb.RemoveShareResponse{ - Status: status.NewInternal(ctx, "error getting share when committing to the storage"), + Status: status.NewInternal(ctx, status.NewErrorFromCode(getShareRes.Status.Code, "gatewaysvc"), + "error getting share when committing to the storage"), } return res, nil } @@ -146,10 +139,10 @@ func (s *svc) RemoveShare(ctx context.Context, req *usershareproviderv0alphapb.R return nil, errors.Wrap(err, "gatewaysvc: error calling RemoveGrant") } if grantRes.Status.Code != rpcpb.Code_CODE_OK { - res := &usershareproviderv0alphapb.RemoveShareResponse{ - Status: status.NewInternal(ctx, "error removing storage grant"), - } - return res, nil + return &usershareproviderv0alphapb.RemoveShareResponse{ + Status: status.NewInternal(ctx, status.NewErrorFromCode(grantRes.Status.Code, "gatewaysvc"), + "error removing storage grant"), + }, nil } } @@ -164,15 +157,11 @@ func (s *svc) GetShare(ctx context.Context, req *usershareproviderv0alphapb.GetS } func (s *svc) getShare(ctx context.Context, req *usershareproviderv0alphapb.GetShareRequest) (*usershareproviderv0alphapb.GetShareResponse, error) { - log := appctx.GetLogger(ctx) - c, err := pool.GetUserShareProviderClient(s.c.UserShareProviderEndpoint) if err != nil { - log.Err(err).Msg("gatewaysvc: error getting usershareprovider client") + err = errors.Wrap(err, "gatewaysvc: error calling GetUserShareProviderClient") return &usershareproviderv0alphapb.GetShareResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, + Status: status.NewInternal(ctx, err, "error getting user share provider client"), }, nil } @@ -186,15 +175,11 @@ func (s *svc) getShare(ctx context.Context, req *usershareproviderv0alphapb.GetS // TODO(labkode): read GetShare comment. func (s *svc) ListShares(ctx context.Context, req *usershareproviderv0alphapb.ListSharesRequest) (*usershareproviderv0alphapb.ListSharesResponse, error) { - log := appctx.GetLogger(ctx) - c, err := pool.GetUserShareProviderClient(s.c.UserShareProviderEndpoint) if err != nil { - log.Err(err).Msg("gatewaysvc: error getting usershareprovider client") + err = errors.Wrap(err, "gatewaysvc: error calling GetUserShareProviderClient") return &usershareproviderv0alphapb.ListSharesResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, + Status: status.NewInternal(ctx, err, "error getting user share provider client"), }, nil } @@ -207,15 +192,11 @@ func (s *svc) ListShares(ctx context.Context, req *usershareproviderv0alphapb.Li } func (s *svc) UpdateShare(ctx context.Context, req *usershareproviderv0alphapb.UpdateShareRequest) (*usershareproviderv0alphapb.UpdateShareResponse, error) { - log := appctx.GetLogger(ctx) - c, err := pool.GetUserShareProviderClient(s.c.UserShareProviderEndpoint) if err != nil { - log.Err(err).Msg("gatewaysvc: error getting usershareprovider client") + err = errors.Wrap(err, "gatewaysvc: error calling GetUserShareProviderClient") return &usershareproviderv0alphapb.UpdateShareResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, + Status: status.NewInternal(ctx, err, "error getting share provider client"), }, nil } @@ -240,10 +221,10 @@ func (s *svc) UpdateShare(ctx context.Context, req *usershareproviderv0alphapb.U } if getShareRes.Status.Code != rpcpb.Code_CODE_OK { - res := &usershareproviderv0alphapb.UpdateShareResponse{ - Status: status.NewInternal(ctx, "error getting share when committing to the share"), - } - return res, nil + return &usershareproviderv0alphapb.UpdateShareResponse{ + Status: status.NewInternal(ctx, status.NewErrorFromCode(getShareRes.Status.Code, "gatewaysvc"), + "error getting share when committing to the share"), + }, nil } grantReq := &storageproviderv0alphapb.UpdateGrantRequest{ @@ -262,10 +243,10 @@ func (s *svc) UpdateShare(ctx context.Context, req *usershareproviderv0alphapb.U return nil, errors.Wrap(err, "gatewaysvc: error calling UpdateGrant") } if grantRes.Status.Code != rpcpb.Code_CODE_OK { - res := &usershareproviderv0alphapb.UpdateShareResponse{ - Status: status.NewInternal(ctx, "error updating storage grant"), - } - return res, nil + return &usershareproviderv0alphapb.UpdateShareResponse{ + Status: status.NewInternal(ctx, status.NewErrorFromCode(grantRes.Status.Code, "gatewaysvc"), + "error updating storage grant"), + }, nil } } @@ -273,15 +254,11 @@ func (s *svc) UpdateShare(ctx context.Context, req *usershareproviderv0alphapb.U } func (s *svc) ListReceivedShares(ctx context.Context, req *usershareproviderv0alphapb.ListReceivedSharesRequest) (*usershareproviderv0alphapb.ListReceivedSharesResponse, error) { - log := appctx.GetLogger(ctx) - c, err := pool.GetUserShareProviderClient(s.c.UserShareProviderEndpoint) if err != nil { - log.Err(err).Msg("gatewaysvc: error getting usershareprovider client") + err = errors.Wrap(err, "gatewaysvc: error calling GetUserShareProviderClient") return &usershareproviderv0alphapb.ListReceivedSharesResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, + Status: status.NewInternal(ctx, err, "error getting share provider client"), }, nil } @@ -294,15 +271,11 @@ func (s *svc) ListReceivedShares(ctx context.Context, req *usershareproviderv0al } func (s *svc) UpdateReceivedShare(ctx context.Context, req *usershareproviderv0alphapb.UpdateReceivedShareRequest) (*usershareproviderv0alphapb.UpdateReceivedShareResponse, error) { - log := appctx.GetLogger(ctx) - c, err := pool.GetUserShareProviderClient(s.c.UserShareProviderEndpoint) if err != nil { - log.Err(err).Msg("gatewaysvc: error getting usershareprovider client") + err = errors.Wrap(err, "gatewaysvc: error calling GetUserShareProviderClient") return &usershareproviderv0alphapb.UpdateReceivedShareResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, + Status: status.NewInternal(ctx, err, "error getting share provider client"), }, nil } diff --git a/cmd/revad/svcs/grpcsvcs/preferencessvc/preferencessvc.go b/cmd/revad/svcs/grpcsvcs/preferencessvc/preferencessvc.go index f3eeebb147..75c62dd19c 100644 --- a/cmd/revad/svcs/grpcsvcs/preferencessvc/preferencessvc.go +++ b/cmd/revad/svcs/grpcsvcs/preferencessvc/preferencessvc.go @@ -23,12 +23,12 @@ import ( "io" "sync" - rpcpb "github.com/cs3org/go-cs3apis/cs3/rpc" "google.golang.org/grpc" authv0alphapb "github.com/cs3org/go-cs3apis/cs3/auth/v0alpha" preferencesv0alphapb "github.com/cs3org/go-cs3apis/cs3/preferences/v0alpha" "github.com/cs3org/reva/cmd/revad/grpcserver" + "github.com/cs3org/reva/cmd/revad/svcs/grpcsvcs/status" "github.com/cs3org/reva/pkg/user" "github.com/pkg/errors" ) @@ -75,10 +75,10 @@ func (s *service) SetKey(ctx context.Context, req *preferencesv0alphapb.SetKeyRe u, err := getUser(ctx) if err != nil { - res := &preferencesv0alphapb.SetKeyResponse{ - Status: &rpcpb.Status{Code: rpcpb.Code_CODE_UNAUTHENTICATED}, - } - return res, err + err = errors.Wrap(err, "preferencessvc: failed to call getUser") + return &preferencesv0alphapb.SetKeyResponse{ + Status: status.NewUnauthenticated(ctx, err, "user not found or invalid"), + }, err } name := u.Username @@ -92,20 +92,19 @@ func (s *service) SetKey(ctx context.Context, req *preferencesv0alphapb.SetKeyRe usersettings[key] = value } - res := &preferencesv0alphapb.SetKeyResponse{ - Status: &rpcpb.Status{Code: rpcpb.Code_CODE_OK}, - } - return res, nil + return &preferencesv0alphapb.SetKeyResponse{ + Status: status.NewOK(ctx), + }, nil } func (s *service) GetKey(ctx context.Context, req *preferencesv0alphapb.GetKeyRequest) (*preferencesv0alphapb.GetKeyResponse, error) { key := req.Key u, err := getUser(ctx) if err != nil { - res := &preferencesv0alphapb.GetKeyResponse{ - Status: &rpcpb.Status{Code: rpcpb.Code_CODE_UNAUTHENTICATED}, - } - return res, err + err = errors.Wrap(err, "preferencessvc: failed to call getUser") + return &preferencesv0alphapb.GetKeyResponse{ + Status: status.NewUnauthenticated(ctx, err, "user not found or invalid"), + }, err } name := u.Username @@ -114,16 +113,15 @@ func (s *service) GetKey(ctx context.Context, req *preferencesv0alphapb.GetKeyRe defer mutex.Unlock() if len(m[name]) != 0 { if value, ok := m[name][key]; ok { - res := &preferencesv0alphapb.GetKeyResponse{ - Status: &rpcpb.Status{Code: rpcpb.Code_CODE_OK}, + return &preferencesv0alphapb.GetKeyResponse{ + Status: status.NewOK(ctx), Val: value, - } - return res, nil + }, nil } } res := &preferencesv0alphapb.GetKeyResponse{ - Status: &rpcpb.Status{Code: rpcpb.Code_CODE_NOT_FOUND}, + Status: status.NewNotFound(ctx, "key not found"), Val: "", } return res, nil diff --git a/cmd/revad/svcs/grpcsvcs/status/status.go b/cmd/revad/svcs/grpcsvcs/status/status.go index c85673af4c..c2c8a7029c 100644 --- a/cmd/revad/svcs/grpcsvcs/status/status.go +++ b/cmd/revad/svcs/grpcsvcs/status/status.go @@ -23,8 +23,10 @@ package status import ( "context" + "errors" rpcpb "github.com/cs3org/go-cs3apis/cs3/rpc" + "github.com/cs3org/reva/pkg/appctx" "go.opencensus.io/trace" ) @@ -36,8 +38,9 @@ func NewOK(ctx context.Context) *rpcpb.Status { } } -// NewNotFound returns a Status with CODE_NOT_FOUND. +// NewNotFound returns a Status with CODE_NOT_FOUND and logs the msg. func NewNotFound(ctx context.Context, msg string) *rpcpb.Status { + appctx.GetLogger(ctx).Warn().Msg(msg) return &rpcpb.Status{ Code: rpcpb.Code_CODE_NOT_FOUND, Message: msg, @@ -45,8 +48,21 @@ func NewNotFound(ctx context.Context, msg string) *rpcpb.Status { } } -// NewInternal returns a Status with CODE_INTERNAL. -func NewInternal(ctx context.Context, msg string) *rpcpb.Status { +// NewInvalid returns a Status with CODE_INVALID_ARGUMENT and logs the msg. +func NewInvalid(ctx context.Context, msg string) *rpcpb.Status { + appctx.GetLogger(ctx).Warn().Msg(msg) + return &rpcpb.Status{ + Code: rpcpb.Code_CODE_INVALID_ARGUMENT, + Message: msg, + Trace: getTrace(ctx), + } +} + +// NewInternal returns a Status with CODE_INTERNAL and logs the msg. +func NewInternal(ctx context.Context, err error, msg string) *rpcpb.Status { + if err != nil { + appctx.GetLogger(ctx).Err(err).Msg(msg) + } return &rpcpb.Status{ Code: rpcpb.Code_CODE_INTERNAL, Message: msg, @@ -54,8 +70,11 @@ func NewInternal(ctx context.Context, msg string) *rpcpb.Status { } } -// NewUnauthenticated returns a Status with CODE_UNAUTHENTICATED. -func NewUnauthenticated(ctx context.Context, msg string) *rpcpb.Status { +// NewUnauthenticated returns a Status with CODE_UNAUTHENTICATED and logs the msg. +func NewUnauthenticated(ctx context.Context, err error, msg string) *rpcpb.Status { + if err != nil { + appctx.GetLogger(ctx).Err(err).Msg(msg) + } return &rpcpb.Status{ Code: rpcpb.Code_CODE_UNAUTHENTICATED, Message: msg, @@ -63,8 +82,11 @@ func NewUnauthenticated(ctx context.Context, msg string) *rpcpb.Status { } } -// NewUnimplemented returns a Status with CODE_UNIMPLEMENTED. -func NewUnimplemented(ctx context.Context, msg string) *rpcpb.Status { +// NewUnimplemented returns a Status with CODE_UNIMPLEMENTED and logs the msg. +func NewUnimplemented(ctx context.Context, err error, msg string) *rpcpb.Status { + if err != nil { + appctx.GetLogger(ctx).Err(err).Msg(msg) + } return &rpcpb.Status{ Code: rpcpb.Code_CODE_UNIMPLEMENTED, Message: msg, @@ -72,6 +94,12 @@ func NewUnimplemented(ctx context.Context, msg string) *rpcpb.Status { } } +// NewErrorFromCode returns a standardized Error for a given RPC code. +func NewErrorFromCode(code rpcpb.Code, pkgname string) error { + return errors.New(pkgname + ": RPC failed with code " + code.String()) +} + +// internal function to attach the trace to a context func getTrace(ctx context.Context) string { span := trace.FromContext(ctx) return span.SpanContext().TraceID.String() diff --git a/cmd/revad/svcs/grpcsvcs/storageprovidersvc/storageprovidersvc.go b/cmd/revad/svcs/grpcsvcs/storageprovidersvc/storageprovidersvc.go index a9c9a1db45..5818fb1a7b 100644 --- a/cmd/revad/svcs/grpcsvcs/storageprovidersvc/storageprovidersvc.go +++ b/cmd/revad/svcs/grpcsvcs/storageprovidersvc/storageprovidersvc.go @@ -31,6 +31,7 @@ import ( storageproviderv0alphapb "github.com/cs3org/go-cs3apis/cs3/storageprovider/v0alpha" storagetypespb "github.com/cs3org/go-cs3apis/cs3/storagetypes" "github.com/cs3org/reva/cmd/revad/grpcserver" + "github.com/cs3org/reva/cmd/revad/svcs/grpcsvcs/status" "github.com/cs3org/reva/pkg/appctx" "github.com/cs3org/reva/pkg/errtypes" "github.com/cs3org/reva/pkg/storage" @@ -158,10 +159,8 @@ func (s *service) GetProvider(ctx context.Context, req *storageproviderv0alphapb // Features: ? TODO(labkode): } res := &storageproviderv0alphapb.GetProviderResponse{ - Info: provider, - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_OK, - }, + Info: provider, + Status: status.NewOK(ctx), } return res, nil } @@ -178,7 +177,7 @@ func (s *service) InitiateFileDownload(ctx context.Context, req *storageprovider log.Info().Str("data-server", url.String()).Str("fn", req.Ref.GetPath()).Msg("file download") res := &storageproviderv0alphapb.InitiateFileDownloadResponse{ DownloadEndpoint: url.String(), - Status: &rpcpb.Status{Code: rpcpb.Code_CODE_OK}, + Status: status.NewOK(ctx), } return res, nil } @@ -194,117 +193,104 @@ func (s *service) InitiateFileUpload(ctx context.Context, req *storageproviderv0 Msg("file upload") res := &storageproviderv0alphapb.InitiateFileUploadResponse{ UploadEndpoint: url.String(), - Status: &rpcpb.Status{Code: rpcpb.Code_CODE_OK}, + Status: status.NewOK(ctx), AvailableChecksums: s.availableXS, } return res, nil } func (s *service) GetPath(ctx context.Context, req *storageproviderv0alphapb.GetPathRequest) (*storageproviderv0alphapb.GetPathResponse, error) { - log := appctx.GetLogger(ctx) // TODO(labkode): check that the storage ID is the same as the storage provider id. fn, err := s.storage.GetPathByID(ctx, req.ResourceId) if err != nil { - log.Error().Err(err).Msg("error getting path by id") - res := &storageproviderv0alphapb.GetPathResponse{ - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_INTERNAL, - }, - } - return res, nil + return &storageproviderv0alphapb.GetPathResponse{ + Status: status.NewInternal(ctx, err, "error getting path by id"), + }, nil } fn = path.Join(s.mountPath, path.Clean(fn)) res := &storageproviderv0alphapb.GetPathResponse{ - Path: fn, - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_OK, - }, + Path: fn, + Status: status.NewOK(ctx), } return res, nil } func (s *service) CreateContainer(ctx context.Context, req *storageproviderv0alphapb.CreateContainerRequest) (*storageproviderv0alphapb.CreateContainerResponse, error) { - log := appctx.GetLogger(ctx) newRef, err := s.unwrap(ctx, req.Ref) if err != nil { - log.Error().Err(err).Msg("error unwraping path") - status := &rpcpb.Status{Code: rpcpb.Code_CODE_INVALID} - res := &storageproviderv0alphapb.CreateContainerResponse{Status: status} - return res, nil + return &storageproviderv0alphapb.CreateContainerResponse{ + Status: status.NewInternal(ctx, err, "error unwrapping path"), + }, nil } if err := s.storage.CreateDir(ctx, newRef.GetPath()); err != nil { + var st *rpcpb.Status if _, ok := err.(errtypes.IsNotFound); ok { - status := &rpcpb.Status{Code: rpcpb.Code_CODE_NOT_FOUND} - res := &storageproviderv0alphapb.CreateContainerResponse{Status: status} - return res, nil + st = status.NewNotFound(ctx, "path not found when creating container") + } else { + st = status.NewInternal(ctx, err, "error creating container: "+req.Ref.String()) } - log.Error().Err(err).Msg("error creating container: " + req.Ref.String()) - status := &rpcpb.Status{Code: rpcpb.Code_CODE_INTERNAL} - res := &storageproviderv0alphapb.CreateContainerResponse{Status: status} - return res, nil + return &storageproviderv0alphapb.CreateContainerResponse{ + Status: st, + }, nil } - status := &rpcpb.Status{Code: rpcpb.Code_CODE_OK} - res := &storageproviderv0alphapb.CreateContainerResponse{Status: status} + res := &storageproviderv0alphapb.CreateContainerResponse{ + Status: status.NewOK(ctx), + } return res, nil } func (s *service) Delete(ctx context.Context, req *storageproviderv0alphapb.DeleteRequest) (*storageproviderv0alphapb.DeleteResponse, error) { - log := appctx.GetLogger(ctx) newRef, err := s.unwrap(ctx, req.Ref) if err != nil { - status := &rpcpb.Status{Code: rpcpb.Code_CODE_INTERNAL} - res := &storageproviderv0alphapb.DeleteResponse{Status: status} - return res, nil + return &storageproviderv0alphapb.DeleteResponse{ + Status: status.NewInternal(ctx, err, "error unwrapping path"), + }, nil } if err := s.storage.Delete(ctx, newRef); err != nil { + var st *rpcpb.Status if _, ok := err.(errtypes.IsNotFound); ok { - log.Error().Err(err).Msg("file not found") - status := &rpcpb.Status{Code: rpcpb.Code_CODE_NOT_FOUND} - res := &storageproviderv0alphapb.DeleteResponse{Status: status} - return res, nil + st = status.NewNotFound(ctx, "file not found") + } else { + st = status.NewInternal(ctx, err, "error deleting file: "+req.Ref.String()) } - log.Error().Err(err).Msg("error deleting file") - status := &rpcpb.Status{Code: rpcpb.Code_CODE_INTERNAL} - res := &storageproviderv0alphapb.DeleteResponse{Status: status} - return res, nil + return &storageproviderv0alphapb.DeleteResponse{ + Status: st, + }, nil } - status := &rpcpb.Status{Code: rpcpb.Code_CODE_OK} - res := &storageproviderv0alphapb.DeleteResponse{Status: status} + res := &storageproviderv0alphapb.DeleteResponse{ + Status: status.NewOK(ctx), + } return res, nil } func (s *service) Move(ctx context.Context, req *storageproviderv0alphapb.MoveRequest) (*storageproviderv0alphapb.MoveResponse, error) { - log := appctx.GetLogger(ctx) - sourceRef, err := s.unwrap(ctx, req.Source) if err != nil { - log.Error().Err(err).Msg("error unwraping source ref") - status := &rpcpb.Status{Code: rpcpb.Code_CODE_INTERNAL} - res := &storageproviderv0alphapb.MoveResponse{Status: status} - return res, nil + return &storageproviderv0alphapb.MoveResponse{ + Status: status.NewInternal(ctx, err, "error unwrapping source path"), + }, nil } targetRef, err := s.unwrap(ctx, req.Destination) if err != nil { - log.Error().Err(err).Msg("error unwraping target ref") - status := &rpcpb.Status{Code: rpcpb.Code_CODE_INTERNAL} - res := &storageproviderv0alphapb.MoveResponse{Status: status} - return res, nil + return &storageproviderv0alphapb.MoveResponse{ + Status: status.NewInternal(ctx, err, "error unwrapping destination path"), + }, nil } if err := s.storage.Move(ctx, sourceRef, targetRef); err != nil { - log.Error().Err(err).Msg("error moving file") - status := &rpcpb.Status{Code: rpcpb.Code_CODE_INTERNAL} - res := &storageproviderv0alphapb.MoveResponse{Status: status} - return res, nil + return &storageproviderv0alphapb.MoveResponse{ + Status: status.NewInternal(ctx, err, "error moving file"), + }, nil } - status := &rpcpb.Status{Code: rpcpb.Code_CODE_OK} - res := &storageproviderv0alphapb.MoveResponse{Status: status} + res := &storageproviderv0alphapb.MoveResponse{ + Status: status.NewOK(ctx), + } return res, nil } @@ -316,33 +302,31 @@ func (s *service) Stat(ctx context.Context, req *storageproviderv0alphapb.StatRe trace.StringAttribute("ref", req.Ref.String()), ) - log := appctx.GetLogger(ctx) - newRef, err := s.unwrap(ctx, req.Ref) if err != nil { - status := &rpcpb.Status{Code: rpcpb.Code_CODE_INVALID} - res := &storageproviderv0alphapb.StatResponse{Status: status} - return res, nil + return &storageproviderv0alphapb.StatResponse{ + Status: status.NewInternal(ctx, err, "error unwrapping path"), + }, nil } md, err := s.storage.GetMD(ctx, newRef) if err != nil { + var st *rpcpb.Status if _, ok := err.(errtypes.IsNotFound); ok { - log.Warn().Str("ref", req.Ref.String()).Msg("resource not found") - status := &rpcpb.Status{Code: rpcpb.Code_CODE_NOT_FOUND} - res := &storageproviderv0alphapb.StatResponse{Status: status} - return res, nil + st = status.NewNotFound(ctx, "file not found") + } else { + st = status.NewInternal(ctx, err, "error stating file: "+req.Ref.String()) } - log.Error().Err(err).Msg("error stating file") - status := &rpcpb.Status{Code: rpcpb.Code_CODE_INTERNAL} - res := &storageproviderv0alphapb.StatResponse{Status: status} - return res, nil + return &storageproviderv0alphapb.StatResponse{ + Status: st, + }, nil } s.wrap(md) - - status := &rpcpb.Status{Code: rpcpb.Code_CODE_OK} - res := &storageproviderv0alphapb.StatResponse{Status: status, Info: md} + res := &storageproviderv0alphapb.StatResponse{ + Status: status.NewOK(ctx), + Info: md, + } return res, nil } @@ -352,11 +336,11 @@ func (s *service) ListContainerStream(req *storageproviderv0alphapb.ListContaine newRef, err := s.unwrap(ctx, req.Ref) if err != nil { - log.Error().Err(err).Msg("error unwraping path") - status := &rpcpb.Status{Code: rpcpb.Code_CODE_INTERNAL} - res := &storageproviderv0alphapb.ListContainerStreamResponse{Status: status} + res := &storageproviderv0alphapb.ListContainerStreamResponse{ + Status: status.NewInternal(ctx, err, "error unwrapping path"), + } if err := ss.Send(res); err != nil { - log.Error().Err(err).Msg("error sending response") + log.Error().Err(err).Msg("ListContainerStream: error sending response") return err } return nil @@ -364,11 +348,11 @@ func (s *service) ListContainerStream(req *storageproviderv0alphapb.ListContaine mds, err := s.storage.ListFolder(ctx, newRef) if err != nil { - log.Error().Err(err).Msg("error listing folder") - status := &rpcpb.Status{Code: rpcpb.Code_CODE_INTERNAL} - res := &storageproviderv0alphapb.ListContainerStreamResponse{Status: status} + res := &storageproviderv0alphapb.ListContainerStreamResponse{ + Status: status.NewInternal(ctx, err, "error listing folder"), + } if err := ss.Send(res); err != nil { - log.Error().Err(err).Msg("error sending response") + log.Error().Err(err).Msg("ListContainerStream: error sending response") return err } return nil @@ -377,14 +361,12 @@ func (s *service) ListContainerStream(req *storageproviderv0alphapb.ListContaine for _, md := range mds { s.wrap(md) res := &storageproviderv0alphapb.ListContainerStreamResponse{ - Info: md, - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_OK, - }, + Info: md, + Status: status.NewOK(ctx), } if err := ss.Send(res); err != nil { - log.Error().Err(err).Msg("error sending response") + log.Error().Err(err).Msg("ListContainerStream: error sending response") return err } } @@ -392,22 +374,18 @@ func (s *service) ListContainerStream(req *storageproviderv0alphapb.ListContaine } func (s *service) ListContainer(ctx context.Context, req *storageproviderv0alphapb.ListContainerRequest) (*storageproviderv0alphapb.ListContainerResponse, error) { - log := appctx.GetLogger(ctx) - newRef, err := s.unwrap(ctx, req.Ref) if err != nil { - log.Error().Err(err).Msg("error unwraping path") - status := &rpcpb.Status{Code: rpcpb.Code_CODE_INTERNAL} - res := &storageproviderv0alphapb.ListContainerResponse{Status: status} - return res, nil + return &storageproviderv0alphapb.ListContainerResponse{ + Status: status.NewInternal(ctx, err, "error unwrapping path"), + }, nil } mds, err := s.storage.ListFolder(ctx, newRef) if err != nil { - log.Error().Err(err).Msg("error listing folder") - status := &rpcpb.Status{Code: rpcpb.Code_CODE_INTERNAL} - res := &storageproviderv0alphapb.ListContainerResponse{Status: status} - return res, nil + return &storageproviderv0alphapb.ListContainerResponse{ + Status: status.NewInternal(ctx, err, "error listing folder"), + }, nil } var infos = make([]*storageproviderv0alphapb.ResourceInfo, 0, len(mds)) @@ -416,68 +394,65 @@ func (s *service) ListContainer(ctx context.Context, req *storageproviderv0alpha infos = append(infos, md) } res := &storageproviderv0alphapb.ListContainerResponse{ - Status: &rpcpb.Status{Code: rpcpb.Code_CODE_OK}, + Status: status.NewOK(ctx), Infos: infos, } return res, nil } func (s *service) ListFileVersions(ctx context.Context, req *storageproviderv0alphapb.ListFileVersionsRequest) (*storageproviderv0alphapb.ListFileVersionsResponse, error) { - log := appctx.GetLogger(ctx) - newRef, err := s.unwrap(ctx, req.Ref) if err != nil { - log.Error().Err(err).Msg("error unwraping path") - status := &rpcpb.Status{Code: rpcpb.Code_CODE_INTERNAL} - res := &storageproviderv0alphapb.ListFileVersionsResponse{Status: status} - return res, nil + return &storageproviderv0alphapb.ListFileVersionsResponse{ + Status: status.NewInternal(ctx, err, "error unwrapping path"), + }, nil } revs, err := s.storage.ListRevisions(ctx, newRef) if err != nil { - log.Error().Err(err).Msg("error listing file versions") - status := &rpcpb.Status{Code: rpcpb.Code_CODE_INTERNAL} - res := &storageproviderv0alphapb.ListFileVersionsResponse{Status: status} - return res, nil + return &storageproviderv0alphapb.ListFileVersionsResponse{ + Status: status.NewInternal(ctx, err, "error listing file versions"), + }, nil } - status := &rpcpb.Status{Code: rpcpb.Code_CODE_OK} - res := &storageproviderv0alphapb.ListFileVersionsResponse{Status: status, Versions: revs} + res := &storageproviderv0alphapb.ListFileVersionsResponse{ + Status: status.NewOK(ctx), + Versions: revs, + } return res, nil } func (s *service) RestoreFileVersion(ctx context.Context, req *storageproviderv0alphapb.RestoreFileVersionRequest) (*storageproviderv0alphapb.RestoreFileVersionResponse, error) { - log := appctx.GetLogger(ctx) - newRef, err := s.unwrap(ctx, req.Ref) if err != nil { - log.Error().Err(err).Msg("error unwraping path") - status := &rpcpb.Status{Code: rpcpb.Code_CODE_INTERNAL} - res := &storageproviderv0alphapb.RestoreFileVersionResponse{Status: status} - return res, nil + return &storageproviderv0alphapb.RestoreFileVersionResponse{ + Status: status.NewInternal(ctx, err, "error unwrapping path"), + }, nil } if err := s.storage.RestoreRevision(ctx, newRef, req.Key); err != nil { - log.Error().Err(err).Msg("error restoring version") - status := &rpcpb.Status{Code: rpcpb.Code_CODE_INTERNAL} - res := &storageproviderv0alphapb.RestoreFileVersionResponse{Status: status} - return res, nil + return &storageproviderv0alphapb.RestoreFileVersionResponse{ + Status: status.NewInternal(ctx, err, "error restoring version"), + }, nil + } + + res := &storageproviderv0alphapb.RestoreFileVersionResponse{ + Status: status.NewOK(ctx), } - status := &rpcpb.Status{Code: rpcpb.Code_CODE_INTERNAL} - res := &storageproviderv0alphapb.RestoreFileVersionResponse{Status: status} return res, nil } func (s *service) ListRecycleStream(req *storageproviderv0alphapb.ListRecycleStreamRequest, ss storageproviderv0alphapb.StorageProviderService_ListRecycleStreamServer) error { ctx := ss.Context() log := appctx.GetLogger(ctx) + items, err := s.storage.ListRecycle(ctx) if err != nil { - log.Error().Err(err).Msg("error listing recycle") - status := &rpcpb.Status{Code: rpcpb.Code_CODE_INTERNAL} - res := &storageproviderv0alphapb.ListRecycleStreamResponse{Status: status} + res := &storageproviderv0alphapb.ListRecycleStreamResponse{ + Status: status.NewInternal(ctx, err, "error listing recycle"), + } if err := ss.Send(res); err != nil { - log.Error().Err(err).Msg("error sending response") + log.Error().Err(err).Msg("ListRecycleStream: error sending response") return err } return nil @@ -487,12 +462,10 @@ func (s *service) ListRecycleStream(req *storageproviderv0alphapb.ListRecycleStr for _, item := range items { res := &storageproviderv0alphapb.ListRecycleStreamResponse{ RecycleItem: item, - Status: &rpcpb.Status{ - Code: rpcpb.Code_CODE_OK, - }, + Status: status.NewOK(ctx), } if err := ss.Send(res); err != nil { - log.Error().Err(err).Msg("error sending response") + log.Error().Err(err).Msg("ListRecycleStream: error sending response") return err } } @@ -500,48 +473,45 @@ func (s *service) ListRecycleStream(req *storageproviderv0alphapb.ListRecycleStr } func (s *service) ListRecycle(ctx context.Context, req *storageproviderv0alphapb.ListRecycleRequest) (*storageproviderv0alphapb.ListRecycleResponse, error) { - log := appctx.GetLogger(ctx) items, err := s.storage.ListRecycle(ctx) // TODO(labkode): CRITICAL: fill recycle info with storage provider. if err != nil { - log.Error().Err(err).Msg("error listing recycle") - status := &rpcpb.Status{Code: rpcpb.Code_CODE_INTERNAL} - res := &storageproviderv0alphapb.ListRecycleResponse{Status: status} - return res, nil + return &storageproviderv0alphapb.ListRecycleResponse{ + Status: status.NewInternal(ctx, err, "error listing recycle bin"), + }, nil } - status := &rpcpb.Status{Code: rpcpb.Code_CODE_OK} res := &storageproviderv0alphapb.ListRecycleResponse{ - Status: status, + Status: status.NewOK(ctx), RecycleItems: items, } return res, nil } func (s *service) RestoreRecycleItem(ctx context.Context, req *storageproviderv0alphapb.RestoreRecycleItemRequest) (*storageproviderv0alphapb.RestoreRecycleItemResponse, error) { - log := appctx.GetLogger(ctx) // TODO(labkode): CRITICAL: fill recycle info with storage provider. if err := s.storage.RestoreRecycleItem(ctx, req.Key); err != nil { - log.Error().Err(err).Msg("error restoring recycle item") - status := &rpcpb.Status{Code: rpcpb.Code_CODE_INTERNAL} - res := &storageproviderv0alphapb.RestoreRecycleItemResponse{Status: status} - return res, nil + return &storageproviderv0alphapb.RestoreRecycleItemResponse{ + Status: status.NewInternal(ctx, err, "error restoring recycle bin item"), + }, nil + } + + res := &storageproviderv0alphapb.RestoreRecycleItemResponse{ + Status: status.NewOK(ctx), } - status := &rpcpb.Status{Code: rpcpb.Code_CODE_OK} - res := &storageproviderv0alphapb.RestoreRecycleItemResponse{Status: status} return res, nil } func (s *service) PurgeRecycle(ctx context.Context, req *storageproviderv0alphapb.PurgeRecycleRequest) (*storageproviderv0alphapb.PurgeRecycleResponse, error) { - log := appctx.GetLogger(ctx) if err := s.storage.EmptyRecycle(ctx); err != nil { - log.Error().Err(err).Msg("error purging recycle") - status := &rpcpb.Status{Code: rpcpb.Code_CODE_INTERNAL} - res := &storageproviderv0alphapb.PurgeRecycleResponse{Status: status} - return res, nil + return &storageproviderv0alphapb.PurgeRecycleResponse{ + Status: status.NewInternal(ctx, err, "error purging recycle bin"), + }, nil + } + + res := &storageproviderv0alphapb.PurgeRecycleResponse{ + Status: status.NewOK(ctx), } - status := &rpcpb.Status{Code: rpcpb.Code_CODE_OK} - res := &storageproviderv0alphapb.PurgeRecycleResponse{Status: status} return res, nil } @@ -550,107 +520,100 @@ func (s *service) ListGrants(ctx context.Context, req *storageproviderv0alphapb. } func (s *service) AddGrant(ctx context.Context, req *storageproviderv0alphapb.AddGrantRequest) (*storageproviderv0alphapb.AddGrantResponse, error) { - log := appctx.GetLogger(ctx) - // check grantee type is valid + // check grantee type is valid if req.Grant.Grantee.Type == storageproviderv0alphapb.GranteeType_GRANTEE_TYPE_INVALID { - log.Warn().Msg("grantee type is invalid") - status := &rpcpb.Status{Code: rpcpb.Code_CODE_INVALID_ARGUMENT, Message: "grantee type is invalid"} - res := &storageproviderv0alphapb.AddGrantResponse{Status: status} - return res, nil + return &storageproviderv0alphapb.AddGrantResponse{ + Status: status.NewInvalid(ctx, "grantee type is invalid"), + }, nil } newRef, err := s.unwrap(ctx, req.Ref) if err != nil { - log.Error().Err(err).Msg("error unwraping ref") - status := &rpcpb.Status{Code: rpcpb.Code_CODE_INTERNAL} - res := &storageproviderv0alphapb.AddGrantResponse{Status: status} - return res, nil + return &storageproviderv0alphapb.AddGrantResponse{ + Status: status.NewInternal(ctx, err, "error unwrapping path"), + }, nil } err = s.storage.AddGrant(ctx, newRef, req.Grant) if err != nil { - log.Error().Err(err).Msg("error setting acl") - status := &rpcpb.Status{Code: rpcpb.Code_CODE_INTERNAL} - res := &storageproviderv0alphapb.AddGrantResponse{Status: status} - return res, nil + return &storageproviderv0alphapb.AddGrantResponse{ + Status: status.NewInternal(ctx, err, "error setting ACL"), + }, nil } - status := &rpcpb.Status{Code: rpcpb.Code_CODE_OK} - res := &storageproviderv0alphapb.AddGrantResponse{Status: status} + res := &storageproviderv0alphapb.AddGrantResponse{ + Status: status.NewOK(ctx), + } return res, nil } func (s *service) UpdateGrant(ctx context.Context, req *storageproviderv0alphapb.UpdateGrantRequest) (*storageproviderv0alphapb.UpdateGrantResponse, error) { - log := appctx.GetLogger(ctx) - + // check grantee type is valid if req.Grant.Grantee.Type == storageproviderv0alphapb.GranteeType_GRANTEE_TYPE_INVALID { - log.Warn().Msg("grantee type is invalid") - status := &rpcpb.Status{Code: rpcpb.Code_CODE_INVALID_ARGUMENT, Message: "grantee type is invalid"} - res := &storageproviderv0alphapb.UpdateGrantResponse{Status: status} - return res, nil + return &storageproviderv0alphapb.UpdateGrantResponse{ + Status: status.NewInvalid(ctx, "grantee type is invalid"), + }, nil } newRef, err := s.unwrap(ctx, req.Ref) if err != nil { - log.Error().Err(err).Msg("error unwraping path") - status := &rpcpb.Status{Code: rpcpb.Code_CODE_INTERNAL} - res := &storageproviderv0alphapb.UpdateGrantResponse{Status: status} - return res, nil + return &storageproviderv0alphapb.UpdateGrantResponse{ + Status: status.NewInternal(ctx, err, "error unwrapping path"), + }, nil } if err := s.storage.UpdateGrant(ctx, newRef, req.Grant); err != nil { - log.Error().Err(err).Msg("error updating acl") - status := &rpcpb.Status{Code: rpcpb.Code_CODE_INTERNAL} - res := &storageproviderv0alphapb.UpdateGrantResponse{Status: status} - return res, nil + return &storageproviderv0alphapb.UpdateGrantResponse{ + Status: status.NewInternal(ctx, err, "error updating ACL"), + }, nil + } + + res := &storageproviderv0alphapb.UpdateGrantResponse{ + Status: status.NewOK(ctx), } - status := &rpcpb.Status{Code: rpcpb.Code_CODE_OK} - res := &storageproviderv0alphapb.UpdateGrantResponse{Status: status} return res, nil } func (s *service) RemoveGrant(ctx context.Context, req *storageproviderv0alphapb.RemoveGrantRequest) (*storageproviderv0alphapb.RemoveGrantResponse, error) { - log := appctx.GetLogger(ctx) - // check targetType is valid if req.Grant.Grantee.Type == storageproviderv0alphapb.GranteeType_GRANTEE_TYPE_INVALID { - log.Warn().Msg("grantee type is invalid") - status := &rpcpb.Status{Code: rpcpb.Code_CODE_INVALID_ARGUMENT, Message: "grantee type is invalid"} - res := &storageproviderv0alphapb.RemoveGrantResponse{Status: status} - return res, nil + return &storageproviderv0alphapb.RemoveGrantResponse{ + Status: status.NewInvalid(ctx, "grantee type is invalid"), + }, nil } newRef, err := s.unwrap(ctx, req.Ref) if err != nil { - log.Error().Err(err).Msg("error unwraping path") - status := &rpcpb.Status{Code: rpcpb.Code_CODE_INTERNAL} - res := &storageproviderv0alphapb.RemoveGrantResponse{Status: status} - return res, nil + return &storageproviderv0alphapb.RemoveGrantResponse{ + Status: status.NewInternal(ctx, err, "error unwrapping path"), + }, nil } if err := s.storage.RemoveGrant(ctx, newRef, req.Grant); err != nil { - log.Error().Err(err).Msg("error removing grant") - status := &rpcpb.Status{Code: rpcpb.Code_CODE_INTERNAL} - res := &storageproviderv0alphapb.RemoveGrantResponse{Status: status} - return res, nil + return &storageproviderv0alphapb.RemoveGrantResponse{ + Status: status.NewInternal(ctx, err, "error removing ACL"), + }, nil } - status := &rpcpb.Status{Code: rpcpb.Code_CODE_OK} - res := &storageproviderv0alphapb.RemoveGrantResponse{Status: status} + res := &storageproviderv0alphapb.RemoveGrantResponse{ + Status: status.NewOK(ctx), + } return res, nil } func (s *service) GetQuota(ctx context.Context, req *storageproviderv0alphapb.GetQuotaRequest) (*storageproviderv0alphapb.GetQuotaResponse, error) { - log := appctx.GetLogger(ctx) total, used, err := s.storage.GetQuota(ctx) if err != nil { - log.Error().Err(err).Msg("error gettign quota") - status := &rpcpb.Status{Code: rpcpb.Code_CODE_INTERNAL} - res := &storageproviderv0alphapb.GetQuotaResponse{Status: status} - return res, nil + return &storageproviderv0alphapb.GetQuotaResponse{ + Status: status.NewInternal(ctx, err, "error getting quota"), + }, nil + } + + res := &storageproviderv0alphapb.GetQuotaResponse{ + Status: status.NewOK(ctx), + TotalBytes: uint64(total), + UsedBytes: uint64(used), } - status := &rpcpb.Status{Code: rpcpb.Code_CODE_OK} - res := &storageproviderv0alphapb.GetQuotaResponse{Status: status, TotalBytes: uint64(total), UsedBytes: uint64(used)} return res, nil } diff --git a/cmd/revad/svcs/grpcsvcs/storageregistrysvc/storageregistrysvc.go b/cmd/revad/svcs/grpcsvcs/storageregistrysvc/storageregistrysvc.go index 4e08bfb3d1..1da7590c6a 100644 --- a/cmd/revad/svcs/grpcsvcs/storageregistrysvc/storageregistrysvc.go +++ b/cmd/revad/svcs/grpcsvcs/storageregistrysvc/storageregistrysvc.go @@ -25,12 +25,11 @@ import ( storagetypespb "github.com/cs3org/go-cs3apis/cs3/storagetypes" - rpcpb "github.com/cs3org/go-cs3apis/cs3/rpc" "google.golang.org/grpc" storageregv0alphapb "github.com/cs3org/go-cs3apis/cs3/storageregistry/v0alpha" "github.com/cs3org/reva/cmd/revad/grpcserver" - "github.com/cs3org/reva/pkg/appctx" + "github.com/cs3org/reva/cmd/revad/svcs/grpcsvcs/status" "github.com/cs3org/reva/pkg/storage" "github.com/cs3org/reva/pkg/storage/registry/registry" "github.com/mitchellh/mapstructure" @@ -91,10 +90,9 @@ func getRegistry(c *config) (storage.Registry, error) { func (s *service) ListStorageProviders(ctx context.Context, req *storageregv0alphapb.ListStorageProvidersRequest) (*storageregv0alphapb.ListStorageProvidersResponse, error) { pinfos, err := s.reg.ListProviders(ctx) if err != nil { - res := &storageregv0alphapb.ListStorageProvidersResponse{ - Status: &rpcpb.Status{Code: rpcpb.Code_CODE_INTERNAL}, - } - return res, nil + return &storageregv0alphapb.ListStorageProvidersResponse{ + Status: status.NewInternal(ctx, err, "error getting list of storage providers"), + }, nil } providers := make([]*storagetypespb.ProviderInfo, 0, len(pinfos)) @@ -104,26 +102,23 @@ func (s *service) ListStorageProviders(ctx context.Context, req *storageregv0alp } res := &storageregv0alphapb.ListStorageProvidersResponse{ - Status: &rpcpb.Status{Code: rpcpb.Code_CODE_OK}, + Status: status.NewOK(ctx), Providers: providers, } return res, nil } func (s *service) GetStorageProvider(ctx context.Context, req *storageregv0alphapb.GetStorageProviderRequest) (*storageregv0alphapb.GetStorageProviderResponse, error) { - log := appctx.GetLogger(ctx) p, err := s.reg.FindProvider(ctx, req.Ref) if err != nil { - log.Error().Err(err).Msg("error finding storage provider") - res := &storageregv0alphapb.GetStorageProviderResponse{ - Status: &rpcpb.Status{Code: rpcpb.Code_CODE_INTERNAL}, - } - return res, nil + return &storageregv0alphapb.GetStorageProviderResponse{ + Status: status.NewInternal(ctx, err, "error finding storage provider"), + }, nil } fill(p) res := &storageregv0alphapb.GetStorageProviderResponse{ - Status: &rpcpb.Status{Code: rpcpb.Code_CODE_OK}, + Status: status.NewOK(ctx), Provider: p, } return res, nil diff --git a/cmd/revad/svcs/grpcsvcs/usershareprovidersvc/usershareprovidersvc.go b/cmd/revad/svcs/grpcsvcs/usershareprovidersvc/usershareprovidersvc.go index c012e39cc7..45c33c12c2 100644 --- a/cmd/revad/svcs/grpcsvcs/usershareprovidersvc/usershareprovidersvc.go +++ b/cmd/revad/svcs/grpcsvcs/usershareprovidersvc/usershareprovidersvc.go @@ -26,7 +26,6 @@ import ( usershareproviderv0alphapb "github.com/cs3org/go-cs3apis/cs3/usershareprovider/v0alpha" "github.com/cs3org/reva/cmd/revad/grpcserver" "github.com/cs3org/reva/cmd/revad/svcs/grpcsvcs/status" - "github.com/cs3org/reva/pkg/appctx" "github.com/cs3org/reva/pkg/share" "github.com/cs3org/reva/pkg/share/manager/registry" "github.com/mitchellh/mapstructure" @@ -92,8 +91,6 @@ func New(m map[string]interface{}, ss *grpc.Server) (io.Closer, error) { } func (s *service) CreateShare(ctx context.Context, req *usershareproviderv0alphapb.CreateShareRequest) (*usershareproviderv0alphapb.CreateShareResponse, error) { - log := appctx.GetLogger(ctx) - // TODO(labkode): validate input // TODO(labkode): hack: use configured IDP or use hostname as default. if req.Grant.Grantee.Id.Idp == "" { @@ -101,9 +98,8 @@ func (s *service) CreateShare(ctx context.Context, req *usershareproviderv0alpha } share, err := s.sm.Share(ctx, req.ResourceInfo, req.Grant) if err != nil { - log.Err(err).Msg("error creating share") return &usershareproviderv0alphapb.CreateShareResponse{ - Status: status.NewInternal(ctx, "error creating share"), + Status: status.NewInternal(ctx, err, "error creating share"), }, nil } @@ -115,12 +111,10 @@ func (s *service) CreateShare(ctx context.Context, req *usershareproviderv0alpha } func (s *service) RemoveShare(ctx context.Context, req *usershareproviderv0alphapb.RemoveShareRequest) (*usershareproviderv0alphapb.RemoveShareResponse, error) { - log := appctx.GetLogger(ctx) err := s.sm.Unshare(ctx, req.Ref) if err != nil { - log.Err(err).Msg("error removing share") return &usershareproviderv0alphapb.RemoveShareResponse{ - Status: status.NewInternal(ctx, "error removing share"), + Status: status.NewInternal(ctx, err, "error removing share"), }, nil } @@ -130,12 +124,10 @@ func (s *service) RemoveShare(ctx context.Context, req *usershareproviderv0alpha } func (s *service) GetShare(ctx context.Context, req *usershareproviderv0alphapb.GetShareRequest) (*usershareproviderv0alphapb.GetShareResponse, error) { - log := appctx.GetLogger(ctx) share, err := s.sm.GetShare(ctx, req.Ref) if err != nil { - log.Err(err).Msg("error getting share") return &usershareproviderv0alphapb.GetShareResponse{ - Status: status.NewInternal(ctx, "error getting share"), + Status: status.NewInternal(ctx, err, "error getting share"), }, nil } @@ -146,13 +138,10 @@ func (s *service) GetShare(ctx context.Context, req *usershareproviderv0alphapb. } func (s *service) ListShares(ctx context.Context, req *usershareproviderv0alphapb.ListSharesRequest) (*usershareproviderv0alphapb.ListSharesResponse, error) { - log := appctx.GetLogger(ctx) - shares, err := s.sm.ListShares(ctx, req.Filters) // TODO(labkode): add filter to share manager if err != nil { - log.Err(err).Msg("error listing shares") return &usershareproviderv0alphapb.ListSharesResponse{ - Status: status.NewInternal(ctx, "error listing shares"), + Status: status.NewInternal(ctx, err, "error listing shares"), }, nil } @@ -164,13 +153,10 @@ func (s *service) ListShares(ctx context.Context, req *usershareproviderv0alphap } func (s *service) UpdateShare(ctx context.Context, req *usershareproviderv0alphapb.UpdateShareRequest) (*usershareproviderv0alphapb.UpdateShareResponse, error) { - log := appctx.GetLogger(ctx) - _, err := s.sm.UpdateShare(ctx, req.Ref, req.Field.GetPermissions()) // TODO(labkode): check what to update if err != nil { - log.Err(err).Msg("error updating share") return &usershareproviderv0alphapb.UpdateShareResponse{ - Status: status.NewInternal(ctx, "error updating share"), + Status: status.NewInternal(ctx, err, "error updating share"), }, nil } @@ -181,13 +167,10 @@ func (s *service) UpdateShare(ctx context.Context, req *usershareproviderv0alpha } func (s *service) ListReceivedShares(ctx context.Context, req *usershareproviderv0alphapb.ListReceivedSharesRequest) (*usershareproviderv0alphapb.ListReceivedSharesResponse, error) { - log := appctx.GetLogger(ctx) - shares, err := s.sm.ListReceivedShares(ctx) // TODO(labkode): check what to update if err != nil { - log.Err(err).Msg("error listing received shares") return &usershareproviderv0alphapb.ListReceivedSharesResponse{ - Status: status.NewInternal(ctx, "error listing received shares"), + Status: status.NewInternal(ctx, err, "error listing received shares"), }, nil } @@ -199,13 +182,10 @@ func (s *service) ListReceivedShares(ctx context.Context, req *usershareprovider } func (s *service) UpdateReceivedShare(ctx context.Context, req *usershareproviderv0alphapb.UpdateReceivedShareRequest) (*usershareproviderv0alphapb.UpdateReceivedShareResponse, error) { - log := appctx.GetLogger(ctx) - _, err := s.sm.UpdateReceivedShare(ctx, req.Ref, req.Field) // TODO(labkode): check what to update if err != nil { - log.Err(err).Msg("error updating received share") return &usershareproviderv0alphapb.UpdateReceivedShareResponse{ - Status: status.NewInternal(ctx, "error updating received share"), + Status: status.NewInternal(ctx, err, "error updating received share"), }, nil }