Skip to content

Commit acea8d1

Browse files
authored
fix: cleanup left over status.Error in favor of connect.NewError (#1751)
### Proposed Changes * ### Checklist - [ ] I have added or updated unit tests - [ ] I have added or updated integration tests (if appropriate) - [ ] I have added or updated documentation ### Testing Instructions
1 parent 4b239b1 commit acea8d1

File tree

5 files changed

+16
-17
lines changed

5 files changed

+16
-17
lines changed

service/health/health.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ package health
22

33
import (
44
"context"
5+
"errors"
56
"log/slog"
67

8+
"connectrpc.com/connect"
79
"connectrpc.com/grpchealth"
810
"github.com/opentdf/platform/service/logger"
911
"github.com/opentdf/platform/service/pkg/serviceregistry"
10-
"google.golang.org/grpc/codes"
1112
healthpb "google.golang.org/grpc/health/grpc_health_v1"
12-
"google.golang.org/grpc/status"
1313
)
1414

1515
var serviceHealthChecks = make(map[string]func(context.Context) error)
@@ -75,12 +75,12 @@ func (s HealthService) Check(ctx context.Context, req *grpchealth.CheckRequest)
7575
}
7676

7777
func (s HealthService) Watch(_ *healthpb.HealthCheckRequest, _ healthpb.Health_WatchServer) error {
78-
return status.Error(codes.Unimplemented, "unimplemented")
78+
return connect.NewError(connect.CodeUnimplemented, errors.New("unimplemented"))
7979
}
8080

8181
func RegisterReadinessCheck(namespace string, service func(context.Context) error) error {
8282
if _, ok := serviceHealthChecks[namespace]; ok {
83-
return status.Error(codes.AlreadyExists, "readiness check already registered")
83+
return errors.New("readiness check already registered")
8484
}
8585
serviceHealthChecks[namespace] = service
8686

service/internal/auth/authn.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"crypto/sha256"
77
"encoding/base64"
88
"encoding/json"
9+
"errors"
910
"fmt"
1011
"log/slog"
1112
"net/http"
@@ -23,8 +24,6 @@ import (
2324

2425
sdkAudit "github.com/opentdf/platform/sdk/audit"
2526
"github.com/opentdf/platform/service/logger"
26-
"google.golang.org/grpc/codes"
27-
"google.golang.org/grpc/status"
2827
)
2928

3029
const (
@@ -279,7 +278,7 @@ func (a Authentication) ConnectUnaryServerInterceptor() connect.UnaryInterceptor
279278

280279
header := req.Header()["Authorization"]
281280
if len(header) < 1 {
282-
return nil, status.Error(codes.Unauthenticated, "missing authorization header")
281+
return nil, connect.NewError(connect.CodeUnauthenticated, errors.New("missing authorization header"))
283282
}
284283

285284
// parse the rpc method
@@ -297,19 +296,19 @@ func (a Authentication) ConnectUnaryServerInterceptor() connect.UnaryInterceptor
297296
req.Header()["Dpop"],
298297
)
299298
if err != nil {
300-
return nil, status.Errorf(codes.Unauthenticated, "unauthenticated")
299+
return nil, connect.NewError(connect.CodeUnauthenticated, errors.New("unauthenticated"))
301300
}
302301

303302
// Check if the token is allowed to access the resource
304303
if allowed, err := a.enforcer.Enforce(token, resource, action); err != nil {
305304
if err.Error() == "permission denied" {
306305
a.logger.Warn("permission denied", slog.String("azp", token.Subject()), slog.String("error", err.Error()))
307-
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
306+
return nil, connect.NewError(connect.CodePermissionDenied, errors.New("permission denied"))
308307
}
309308
return nil, err
310309
} else if !allowed {
311310
a.logger.Warn("permission denied", slog.String("azp", token.Subject()))
312-
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
311+
return nil, connect.NewError(connect.CodePermissionDenied, errors.New("permission denied"))
313312
}
314313

315314
return next(newCtx, req)

service/internal/auth/authn_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,10 @@ func (s *AuthSuite) Test_UnaryServerInterceptor_When_Authorization_Header_Missin
243243
})(context.Background(), req)
244244

245245
s.Require().Error(err)
246-
s.Require().ErrorIs(err, status.Error(codes.Unauthenticated, "missing authorization header"))
246+
247+
connectErr := connect.NewError(connect.CodeUnauthenticated, errors.New("missing authorization header"))
248+
249+
s.Require().ErrorAs(err, &connectErr)
247250
}
248251

249252
func (s *AuthSuite) Test_CheckToken_When_Authorization_Header_Invalid_Expect_Error() {

service/kas/access/publicKey.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111
"connectrpc.com/connect"
1212
kaspb "github.com/opentdf/platform/protocol/go/kas"
1313
"github.com/opentdf/platform/service/internal/security"
14-
"google.golang.org/grpc/codes"
15-
"google.golang.org/grpc/status"
1614
wrapperspb "google.golang.org/protobuf/types/known/wrapperspb"
1715
)
1816

@@ -116,7 +114,7 @@ func (p Provider) PublicKey(ctx context.Context, req *connect.Request[kaspb.Publ
116114
return r(rsaPublicKeyPem, kid, err)
117115
}
118116
}
119-
return nil, status.Error(codes.NotFound, "invalid algorithm or format")
117+
return nil, connect.NewError(connect.CodeNotFound, errors.New("invalid algorithm or format"))
120118
}
121119

122120
func exportRsaPublicKeyAsPemStr(pubkey *rsa.PublicKey) (string, error) {

service/wellknownconfiguration/wellknown_configuration.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package wellknownconfiguration
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"log/slog"
78
"sync"
@@ -11,8 +12,6 @@ import (
1112
"github.com/opentdf/platform/protocol/go/wellknownconfiguration/wellknownconfigurationconnect"
1213
"github.com/opentdf/platform/service/logger"
1314
"github.com/opentdf/platform/service/pkg/serviceregistry"
14-
"google.golang.org/grpc/codes"
15-
"google.golang.org/grpc/status"
1615
"google.golang.org/protobuf/types/known/structpb"
1716
)
1817

@@ -56,7 +55,7 @@ func (s WellKnownService) GetWellKnownConfiguration(_ context.Context, _ *connec
5655
rwMutex.RUnlock()
5756
if err != nil {
5857
s.logger.Error("failed to create struct for wellknown configuration", slog.String("error", err.Error()))
59-
return nil, status.Error(codes.Internal, "failed to create struct for wellknown configuration")
58+
return nil, connect.NewError(connect.CodeInternal, errors.New("failed to create struct for wellknown configuration"))
6059
}
6160

6261
rsp := &wellknown.GetWellKnownConfigurationResponse{

0 commit comments

Comments
 (0)