Skip to content

Commit

Permalink
update status.NewInternal API
Browse files Browse the repository at this point in the history
  • Loading branch information
David Christofas committed Dec 13, 2021
1 parent cfba9b7 commit 847eb39
Show file tree
Hide file tree
Showing 32 changed files with 261 additions and 297 deletions.
8 changes: 4 additions & 4 deletions internal/grpc/services/applicationauth/applicationauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (s *service) GenerateAppPassword(ctx context.Context, req *appauthpb.Genera
pwd, err := s.am.GenerateAppPassword(ctx, req.TokenScope, req.Label, req.Expiration)
if err != nil {
return &appauthpb.GenerateAppPasswordResponse{
Status: status.NewInternal(ctx, err, "error generating app password"),
Status: status.NewInternal(ctx, "error generating app password"),
}, nil
}

Expand All @@ -120,7 +120,7 @@ func (s *service) ListAppPasswords(ctx context.Context, req *appauthpb.ListAppPa
pwds, err := s.am.ListAppPasswords(ctx)
if err != nil {
return &appauthpb.ListAppPasswordsResponse{
Status: status.NewInternal(ctx, err, "error listing app passwords"),
Status: status.NewInternal(ctx, "error listing app passwords"),
}, nil
}

Expand All @@ -134,7 +134,7 @@ func (s *service) InvalidateAppPassword(ctx context.Context, req *appauthpb.Inva
err := s.am.InvalidateAppPassword(ctx, req.Password)
if err != nil {
return &appauthpb.InvalidateAppPasswordResponse{
Status: status.NewInternal(ctx, err, "error invalidating app password"),
Status: status.NewInternal(ctx, "error invalidating app password"),
}, nil
}

Expand All @@ -147,7 +147,7 @@ func (s *service) GetAppPassword(ctx context.Context, req *appauthpb.GetAppPassw
pwd, err := s.am.GetAppPassword(ctx, req.User, req.Password)
if err != nil {
return &appauthpb.GetAppPasswordResponse{
Status: status.NewInternal(ctx, err, "error getting app password via username/password"),
Status: status.NewInternal(ctx, "error getting app password via username/password"),
}, nil
}

Expand Down
3 changes: 1 addition & 2 deletions internal/grpc/services/appprovider/appprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package appprovider

import (
"context"
"errors"
"os"
"strconv"
"time"
Expand Down Expand Up @@ -173,7 +172,7 @@ func (s *service) OpenInApp(ctx context.Context, req *providerpb.OpenInAppReques
appURL, err := s.provider.GetAppURL(ctx, req.ResourceInfo, req.ViewMode, req.AccessToken)
if err != nil {
res := &providerpb.OpenInAppResponse{
Status: status.NewInternal(ctx, errors.New("appprovider: error calling GetAppURL"), err.Error()),
Status: status.NewInternal(ctx, err.Error()),
}
return res, nil
}
Expand Down
12 changes: 6 additions & 6 deletions internal/grpc/services/appregistry/appregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (s *svc) GetAppProviders(ctx context.Context, req *registrypb.GetAppProvide
p, err := s.reg.FindProviders(ctx, req.ResourceInfo.MimeType)
if err != nil {
return &registrypb.GetAppProvidersResponse{
Status: status.NewInternal(ctx, err, "error looking for the app provider"),
Status: status.NewInternal(ctx, "error looking for the app provider"),
}, nil
}

Expand All @@ -118,7 +118,7 @@ func (s *svc) AddAppProvider(ctx context.Context, req *registrypb.AddAppProvider
err := s.reg.AddProvider(ctx, req.Provider)
if err != nil {
return &registrypb.AddAppProviderResponse{
Status: status.NewInternal(ctx, err, "error adding the app provider"),
Status: status.NewInternal(ctx, "error adding the app provider"),
}, nil
}

Expand All @@ -132,7 +132,7 @@ func (s *svc) ListAppProviders(ctx context.Context, req *registrypb.ListAppProvi
providers, err := s.reg.ListProviders(ctx)
if err != nil {
return &registrypb.ListAppProvidersResponse{
Status: status.NewInternal(ctx, err, "error listing the app providers"),
Status: status.NewInternal(ctx, "error listing the app providers"),
}, nil
}

Expand All @@ -147,7 +147,7 @@ func (s *svc) ListSupportedMimeTypes(ctx context.Context, req *registrypb.ListSu
mimeTypes, err := s.reg.ListSupportedMimeTypes(ctx)
if err != nil {
return &registrypb.ListSupportedMimeTypesResponse{
Status: status.NewInternal(ctx, err, "error listing the supported mime types"),
Status: status.NewInternal(ctx, "error listing the supported mime types"),
}, nil
}

Expand All @@ -169,7 +169,7 @@ func (s *svc) GetDefaultAppProviderForMimeType(ctx context.Context, req *registr
provider, err := s.reg.GetDefaultProviderForMimeType(ctx, req.MimeType)
if err != nil {
return &registrypb.GetDefaultAppProviderForMimeTypeResponse{
Status: status.NewInternal(ctx, err, "error getting the default app provider for the mimetype"),
Status: status.NewInternal(ctx, "error getting the default app provider for the mimetype"),
}, nil
}

Expand All @@ -184,7 +184,7 @@ func (s *svc) SetDefaultAppProviderForMimeType(ctx context.Context, req *registr
err := s.reg.SetDefaultProviderForMimeType(ctx, req.MimeType, req.Provider)
if err != nil {
return &registrypb.SetDefaultAppProviderForMimeTypeResponse{
Status: status.NewInternal(ctx, err, "error setting the default app provider for the mimetype"),
Status: status.NewInternal(ctx, "error setting the default app provider for the mimetype"),
}, nil
}

Expand Down
4 changes: 2 additions & 2 deletions internal/grpc/services/authregistry/authregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (s *service) ListAuthProviders(ctx context.Context, req *registrypb.ListAut
pinfos, err := s.reg.ListProviders(ctx)
if err != nil {
return &registrypb.ListAuthProvidersResponse{
Status: status.NewInternal(ctx, err, "error getting list of auth providers"),
Status: status.NewInternal(ctx, "error getting list of auth providers"),
}, nil
}

Expand All @@ -120,7 +120,7 @@ func (s *service) GetAuthProvider(ctx context.Context, req *registrypb.GetAuthPr
pinfo, err := s.reg.GetProvider(ctx, req.Type)
if err != nil {
return &registrypb.GetAuthProviderResponse{
Status: status.NewInternal(ctx, err, "error getting auth provider for type: "+req.Type),
Status: status.NewInternal(ctx, "error getting auth provider for type: "+req.Type),
}, nil
}

Expand Down
12 changes: 4 additions & 8 deletions internal/grpc/services/gateway/applicationauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ import (
func (s *svc) GenerateAppPassword(ctx context.Context, req *appauthpb.GenerateAppPasswordRequest) (*appauthpb.GenerateAppPasswordResponse, error) {
c, err := pool.GetAppAuthProviderServiceClient(s.c.ApplicationAuthEndpoint)
if err != nil {
err = errors.Wrap(err, "gateway: error calling GetAppAuthProviderServiceClient")
return &appauthpb.GenerateAppPasswordResponse{
Status: status.NewInternal(ctx, err, "error getting app auth provider client"),
Status: status.NewInternal(ctx, "error getting app auth provider client"),
}, nil
}

Expand All @@ -47,9 +46,8 @@ func (s *svc) GenerateAppPassword(ctx context.Context, req *appauthpb.GenerateAp
func (s *svc) ListAppPasswords(ctx context.Context, req *appauthpb.ListAppPasswordsRequest) (*appauthpb.ListAppPasswordsResponse, error) {
c, err := pool.GetAppAuthProviderServiceClient(s.c.ApplicationAuthEndpoint)
if err != nil {
err = errors.Wrap(err, "gateway: error calling GetAppAuthProviderServiceClient")
return &appauthpb.ListAppPasswordsResponse{
Status: status.NewInternal(ctx, err, "error getting app auth provider client"),
Status: status.NewInternal(ctx, "error getting app auth provider client"),
}, nil
}

Expand All @@ -64,9 +62,8 @@ func (s *svc) ListAppPasswords(ctx context.Context, req *appauthpb.ListAppPasswo
func (s *svc) InvalidateAppPassword(ctx context.Context, req *appauthpb.InvalidateAppPasswordRequest) (*appauthpb.InvalidateAppPasswordResponse, error) {
c, err := pool.GetAppAuthProviderServiceClient(s.c.ApplicationAuthEndpoint)
if err != nil {
err = errors.Wrap(err, "gateway: error calling GetAppAuthProviderServiceClient")
return &appauthpb.InvalidateAppPasswordResponse{
Status: status.NewInternal(ctx, err, "error getting app auth provider client"),
Status: status.NewInternal(ctx, "error getting app auth provider client"),
}, nil
}

Expand All @@ -81,9 +78,8 @@ func (s *svc) InvalidateAppPassword(ctx context.Context, req *appauthpb.Invalida
func (s *svc) GetAppPassword(ctx context.Context, req *appauthpb.GetAppPasswordRequest) (*appauthpb.GetAppPasswordResponse, error) {
c, err := pool.GetAppAuthProviderServiceClient(s.c.ApplicationAuthEndpoint)
if err != nil {
err = errors.Wrap(err, "gateway: error calling GetAppAuthProviderServiceClient")
return &appauthpb.GetAppPasswordResponse{
Status: status.NewInternal(ctx, err, "error getting app auth provider client"),
Status: status.NewInternal(ctx, "error getting app auth provider client"),
}, nil
}

Expand Down
9 changes: 4 additions & 5 deletions internal/grpc/services/gateway/appprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (s *svc) OpenInApp(ctx context.Context, req *gateway.OpenInAppRequest) (*pr
})
if err != nil {
return &providerpb.OpenInAppResponse{
Status: status.NewInternal(ctx, err, "gateway: error calling Stat on the resource path for the app provider: "+req.Ref.GetPath()),
Status: status.NewInternal(ctx, "gateway: error calling Stat on the resource path for the app provider: "+req.Ref.GetPath()),
}, nil
}
if statRes.Status.Code != rpc.Code_CODE_OK {
Expand All @@ -67,7 +67,7 @@ func (s *svc) OpenInApp(ctx context.Context, req *gateway.OpenInAppRequest) (*pr
uri, err := url.Parse(fileInfo.Target)
if err != nil {
return &providerpb.OpenInAppResponse{
Status: status.NewInternal(ctx, err, "gateway: error parsing target uri: "+fileInfo.Target),
Status: status.NewInternal(ctx, "gateway: error parsing target uri: "+fileInfo.Target),
}, nil
}
if uri.Scheme == "webdav" {
Expand All @@ -80,13 +80,12 @@ func (s *svc) OpenInApp(ctx context.Context, req *gateway.OpenInAppRequest) (*pr
})
if err != nil {
return &providerpb.OpenInAppResponse{
Status: status.NewInternal(ctx, err, "gateway: error calling Stat on the resource path for the app provider: "+req.Ref.GetPath()),
Status: status.NewInternal(ctx, "gateway: error calling Stat on the resource path for the app provider: "+req.Ref.GetPath()),
}, nil
}
if res.Status.Code != rpc.Code_CODE_OK {
err := status.NewErrorFromCode(res.Status.GetCode(), "gateway")
return &providerpb.OpenInAppResponse{
Status: status.NewInternal(ctx, err, "Stat failed on the resource path for the app provider: "+req.Ref.GetPath()),
Status: status.NewInternal(ctx, "Stat failed on the resource path for the app provider: "+req.Ref.GetPath()),
}, nil
}
fileInfo = res.Info
Expand Down
18 changes: 6 additions & 12 deletions internal/grpc/services/gateway/appregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ import (
func (s *svc) GetAppProviders(ctx context.Context, req *registry.GetAppProvidersRequest) (*registry.GetAppProvidersResponse, error) {
c, err := pool.GetAppRegistryClient(s.c.AppRegistryEndpoint)
if err != nil {
err = errors.Wrap(err, "gateway: error calling GetAppRegistryClient")
return &registry.GetAppProvidersResponse{
Status: status.NewInternal(ctx, err, "error getting app registry client"),
Status: status.NewInternal(ctx, "error getting app registry client"),
}, nil
}

Expand All @@ -47,9 +46,8 @@ func (s *svc) GetAppProviders(ctx context.Context, req *registry.GetAppProviders
func (s *svc) AddAppProvider(ctx context.Context, req *registry.AddAppProviderRequest) (*registry.AddAppProviderResponse, error) {
c, err := pool.GetAppRegistryClient(s.c.AppRegistryEndpoint)
if err != nil {
err = errors.Wrap(err, "gateway: error calling GetAppRegistryClient")
return &registry.AddAppProviderResponse{
Status: status.NewInternal(ctx, err, "error getting app registry client"),
Status: status.NewInternal(ctx, "error getting app registry client"),
}, nil
}

Expand All @@ -64,9 +62,8 @@ func (s *svc) AddAppProvider(ctx context.Context, req *registry.AddAppProviderRe
func (s *svc) ListAppProviders(ctx context.Context, req *registry.ListAppProvidersRequest) (*registry.ListAppProvidersResponse, error) {
c, err := pool.GetAppRegistryClient(s.c.AppRegistryEndpoint)
if err != nil {
err = errors.Wrap(err, "gateway: error calling GetAppRegistryClient")
return &registry.ListAppProvidersResponse{
Status: status.NewInternal(ctx, err, "error getting app registry client"),
Status: status.NewInternal(ctx, "error getting app registry client"),
}, nil
}

Expand All @@ -81,9 +78,8 @@ func (s *svc) ListAppProviders(ctx context.Context, req *registry.ListAppProvide
func (s *svc) ListSupportedMimeTypes(ctx context.Context, req *registry.ListSupportedMimeTypesRequest) (*registry.ListSupportedMimeTypesResponse, error) {
c, err := pool.GetAppRegistryClient(s.c.AppRegistryEndpoint)
if err != nil {
err = errors.Wrap(err, "gateway: error calling GetAppRegistryClient")
return &registry.ListSupportedMimeTypesResponse{
Status: status.NewInternal(ctx, err, "error getting app registry client"),
Status: status.NewInternal(ctx, "error getting app registry client"),
}, nil
}

Expand All @@ -98,9 +94,8 @@ func (s *svc) ListSupportedMimeTypes(ctx context.Context, req *registry.ListSupp
func (s *svc) GetDefaultAppProviderForMimeType(ctx context.Context, req *registry.GetDefaultAppProviderForMimeTypeRequest) (*registry.GetDefaultAppProviderForMimeTypeResponse, error) {
c, err := pool.GetAppRegistryClient(s.c.AppRegistryEndpoint)
if err != nil {
err = errors.Wrap(err, "gateway: error calling GetAppRegistryClient")
return &registry.GetDefaultAppProviderForMimeTypeResponse{
Status: status.NewInternal(ctx, err, "error getting app registry client"),
Status: status.NewInternal(ctx, "error getting app registry client"),
}, nil
}

Expand All @@ -115,9 +110,8 @@ func (s *svc) GetDefaultAppProviderForMimeType(ctx context.Context, req *registr
func (s *svc) SetDefaultAppProviderForMimeType(ctx context.Context, req *registry.SetDefaultAppProviderForMimeTypeRequest) (*registry.SetDefaultAppProviderForMimeTypeResponse, error) {
c, err := pool.GetAppRegistryClient(s.c.AppRegistryEndpoint)
if err != nil {
err = errors.Wrap(err, "gateway: error calling GetAppRegistryClient")
return &registry.SetDefaultAppProviderForMimeTypeResponse{
Status: status.NewInternal(ctx, err, "error getting app registry client"),
Status: status.NewInternal(ctx, "error getting app registry client"),
}, nil
}

Expand Down
17 changes: 7 additions & 10 deletions internal/grpc/services/gateway/authprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ func (s *svc) Authenticate(ctx context.Context, req *gateway.AuthenticateRequest
// find auth provider
c, err := s.findAuthProvider(ctx, req.Type)
if err != nil {
err = errtypes.NotFound("gateway: error finding auth provider for type: " + req.Type)
return &gateway.AuthenticateResponse{
Status: status.NewInternal(ctx, err, "error getting auth provider client"),
Status: status.NewInternal(ctx, "error getting auth provider client"),
}, nil
}

Expand All @@ -64,7 +63,7 @@ func (s *svc) Authenticate(ctx context.Context, req *gateway.AuthenticateRequest
switch {
case err != nil:
return &gateway.AuthenticateResponse{
Status: status.NewInternal(ctx, err, fmt.Sprintf("gateway: error calling Authenticate for type: %s", req.Type)),
Status: status.NewInternal(ctx, fmt.Sprintf("gateway: error calling Authenticate for type: %s", req.Type)),
}, nil
case res.Status.Code == rpc.Code_CODE_PERMISSION_DENIED:
fallthrough
Expand All @@ -76,9 +75,8 @@ func (s *svc) Authenticate(ctx context.Context, req *gateway.AuthenticateRequest
Status: res.Status,
}, nil
case res.Status.Code != rpc.Code_CODE_OK:
err := status.NewErrorFromCode(res.Status.Code, "gateway")
return &gateway.AuthenticateResponse{
Status: status.NewInternal(ctx, err, fmt.Sprintf("error authenticating credentials to auth provider for type: %s", req.Type)),
Status: status.NewInternal(ctx, fmt.Sprintf("error authenticating credentials to auth provider for type: %s", req.Type)),
}, nil
}

Expand All @@ -87,15 +85,15 @@ func (s *svc) Authenticate(ctx context.Context, req *gateway.AuthenticateRequest
err := errtypes.NotFound("gateway: user after Authenticate is nil")
log.Err(err).Msg("user is nil")
return &gateway.AuthenticateResponse{
Status: status.NewInternal(ctx, err, "user is nil"),
Status: status.NewInternal(ctx, "user is nil"),
}, nil
}

if res.User.Id == nil {
err := errtypes.NotFound("gateway: uid after Authenticate is nil")
log.Err(err).Msg("user id is nil")
return &gateway.AuthenticateResponse{
Status: status.NewInternal(ctx, err, "user id is nil"),
Status: status.NewInternal(ctx, "user id is nil"),
}, nil
}

Expand All @@ -111,7 +109,6 @@ func (s *svc) Authenticate(ctx context.Context, req *gateway.AuthenticateRequest
// token obtained from the updated scope in the context.
token, err := s.tokenmgr.MintToken(ctx, &u, res.TokenScope)
if err != nil {
err = errors.Wrap(err, "authsvc: error in MintToken")
res := &gateway.AuthenticateResponse{
Status: status.NewUnauthenticated(ctx, err, "error creating access token"),
}
Expand Down Expand Up @@ -159,15 +156,15 @@ func (s *svc) Authenticate(ctx context.Context, req *gateway.AuthenticateRequest
if err != nil {
log.Err(err).Msg("error calling CreateHome")
return &gateway.AuthenticateResponse{
Status: status.NewInternal(ctx, err, "error creating user home"),
Status: status.NewInternal(ctx, "error creating user home"),
}, nil
}

if createHomeRes.Status.Code != rpc.Code_CODE_OK && createHomeRes.Status.Code != rpc.Code_CODE_ALREADY_EXISTS {
err := status.NewErrorFromCode(createHomeRes.Status.Code, "gateway")
log.Err(err).Msg("error calling Createhome")
return &gateway.AuthenticateResponse{
Status: status.NewInternal(ctx, err, "error creating user home"),
Status: status.NewInternal(ctx, "error creating user home"),
}, nil
}
if s.c.CreateHomeCacheTTL > 0 {
Expand Down
10 changes: 3 additions & 7 deletions internal/grpc/services/gateway/authregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,26 @@ import (
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
"github.com/cs3org/reva/pkg/rgrpc/status"
"github.com/cs3org/reva/pkg/rgrpc/todo/pool"
"github.com/pkg/errors"
)

func (s *svc) ListAuthProviders(ctx context.Context, req *registry.ListAuthProvidersRequest) (*gateway.ListAuthProvidersResponse, error) {
c, err := pool.GetAuthRegistryServiceClient(s.c.AuthRegistryEndpoint)
if err != nil {
err = errors.Wrap(err, "gateway: error getting auth registry client")
return &gateway.ListAuthProvidersResponse{
Status: status.NewInternal(ctx, err, "gateway"),
Status: status.NewInternal(ctx, "gateway"),
}, nil
}

res, err := c.ListAuthProviders(ctx, req)
if err != nil {
err = errors.Wrap(err, "gateway: error calling ListAuthProviders")
return &gateway.ListAuthProvidersResponse{
Status: status.NewInternal(ctx, err, "gateway"),
Status: status.NewInternal(ctx, "gateway"),
}, nil
}

if res.Status.Code != rpc.Code_CODE_OK {
err := status.NewErrorFromCode(res.Status.Code, "gateway")
return &gateway.ListAuthProvidersResponse{
Status: status.NewInternal(ctx, err, "gateway"),
Status: status.NewInternal(ctx, "gateway"),
}, nil
}

Expand Down
Loading

0 comments on commit 847eb39

Please sign in to comment.