Don't return nil, nil for API service methods. Add tests for updating w/ wrong version. (#396)
This commit is contained in:
1 parent
1adbe64160
commit
21f5cc274f
20 files changed
+71
-23
No files matched your search
@@ -129,7 +129,7 @@ func (s Service) DeleteAccount(ctx context.Context, req *pbs.DeleteAccountReques
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, nil
|
||||
return &pbs.DeleteAccountResponse{}, nil
|
||||
}
|
||||
|
||||
// ChangePassword implements the interface pbs.AccountServiceServer.
|
||||
|
||||
@@ -134,7 +134,7 @@ func (s Service) DeleteAuthMethod(ctx context.Context, req *pbs.DeleteAuthMethod
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, nil
|
||||
return &pbs.DeleteAuthMethodResponse{}, nil
|
||||
}
|
||||
|
||||
func (s Service) getFromRepo(ctx context.Context, id string) (*pb.AuthMethod, error) {
|
||||
|
||||
@@ -87,7 +87,7 @@ func (s Service) DeleteAuthToken(ctx context.Context, req *pbs.DeleteAuthTokenRe
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, nil
|
||||
return &pbs.DeleteAuthTokenResponse{}, nil
|
||||
}
|
||||
|
||||
func (s Service) getFromRepo(ctx context.Context, id string) (*pb.AuthToken, error) {
|
||||
|
||||
@@ -130,7 +130,7 @@ func (s Service) DeleteGroup(ctx context.Context, req *pbs.DeleteGroupRequest) (
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, nil
|
||||
return &pbs.DeleteGroupResponse{}, nil
|
||||
}
|
||||
|
||||
// AddGroupMembers implements the interface pbs.GroupServiceServer.
|
||||
|
||||
@@ -135,7 +135,7 @@ func (s Service) DeleteHostCatalog(ctx context.Context, req *pbs.DeleteHostCatal
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, nil
|
||||
return &pbs.DeleteHostCatalogResponse{}, nil
|
||||
}
|
||||
|
||||
func (s Service) getFromRepo(ctx context.Context, id string) (*pb.HostCatalog, error) {
|
||||
|
||||
@@ -130,7 +130,7 @@ func (s Service) DeleteHostSet(ctx context.Context, req *pbs.DeleteHostSetReques
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, nil
|
||||
return &pbs.DeleteHostSetResponse{}, nil
|
||||
}
|
||||
|
||||
// AddHostSetHosts implements the interface pbs.HostSetServiceServer.
|
||||
|
||||
@@ -132,7 +132,7 @@ func (s Service) DeleteHost(ctx context.Context, req *pbs.DeleteHostRequest) (*p
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, nil
|
||||
return &pbs.DeleteHostResponse{}, nil
|
||||
}
|
||||
|
||||
func (s Service) getFromRepo(ctx context.Context, id string) (*pb.Host, error) {
|
||||
|
||||
@@ -131,7 +131,7 @@ func (s Service) DeleteRole(ctx context.Context, req *pbs.DeleteRoleRequest) (*p
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, nil
|
||||
return &pbs.DeleteRoleResponse{}, nil
|
||||
}
|
||||
|
||||
// AddRolePrincipals implements the interface pbs.RoleServiceServer.
|
||||
|
||||
@@ -136,7 +136,7 @@ func (s Service) DeleteScope(ctx context.Context, req *pbs.DeleteScopeRequest) (
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, nil
|
||||
return &pbs.DeleteScopeResponse{}, nil
|
||||
}
|
||||
|
||||
func (s Service) getFromRepo(ctx context.Context, id string) (*pb.Scope, error) {
|
||||
|
||||
@@ -120,9 +120,6 @@ func (s Service) GetTarget(ctx context.Context, req *pbs.GetTargetRequest) (*pbs
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if u == nil {
|
||||
return nil, nil
|
||||
}
|
||||
u.Scope = authResults.Scope
|
||||
return &pbs.GetTargetResponse{Item: u}, nil
|
||||
}
|
||||
@@ -157,9 +154,6 @@ func (s Service) UpdateTarget(ctx context.Context, req *pbs.UpdateTargetRequest)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if u == nil {
|
||||
return nil, nil
|
||||
}
|
||||
u.Scope = authResults.Scope
|
||||
return &pbs.UpdateTargetResponse{Item: u}, nil
|
||||
}
|
||||
@@ -177,7 +171,7 @@ func (s Service) DeleteTarget(ctx context.Context, req *pbs.DeleteTargetRequest)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, nil
|
||||
return &pbs.DeleteTargetResponse{}, nil
|
||||
}
|
||||
|
||||
// AddTargetHostSets implements the interface pbs.TargetServiceServer.
|
||||
@@ -265,12 +259,12 @@ func (s Service) AuthorizeSession(ctx context.Context, req *pbs.AuthorizeSession
|
||||
t, hostSets, err := repo.LookupTarget(ctx, req.GetId())
|
||||
if err != nil {
|
||||
if errors.Is(err, db.ErrRecordNotFound) {
|
||||
return nil, nil
|
||||
return nil, handlers.NotFoundErrorf("Target %q not found.", req.GetId())
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
if t == nil {
|
||||
return nil, nil
|
||||
return nil, handlers.NotFoundErrorf("Target %q not found.", req.GetId())
|
||||
}
|
||||
|
||||
// Instantiate some repos
|
||||
@@ -427,12 +421,12 @@ func (s Service) getFromRepo(ctx context.Context, id string) (*pb.Target, error)
|
||||
u, m, err := repo.LookupTarget(ctx, id)
|
||||
if err != nil {
|
||||
if errors.Is(err, db.ErrRecordNotFound) {
|
||||
return nil, nil
|
||||
return nil, handlers.NotFoundErrorf("Target %q doesn't exist.", id)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
if u == nil {
|
||||
return nil, nil
|
||||
return nil, handlers.NotFoundErrorf("Target %q doesn't exist.", id)
|
||||
}
|
||||
return toProto(u, m)
|
||||
}
|
||||
@@ -513,7 +507,7 @@ func (s Service) updateInRepo(ctx context.Context, scopeId, id string, mask []st
|
||||
return nil, status.Errorf(codes.Internal, "Unable to update target: %v.", err)
|
||||
}
|
||||
if rowsUpdated == 0 {
|
||||
return nil, nil
|
||||
return nil, handlers.NotFoundErrorf("Target %q not found or incorrect version provided.", id)
|
||||
}
|
||||
return toProto(out, m)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user