mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-08-15 10:15:33 -04:00
deps: convert zap to slog (#2825)
This commit is contained in:
parent
3765cb0762
commit
54cce77bab
182 changed files with 1474 additions and 1509 deletions
|
@ -10,6 +10,7 @@ package server
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"net"
|
||||
|
||||
"github.com/edgelesssys/constellation/v2/internal/crypto"
|
||||
|
@ -17,8 +18,6 @@ import (
|
|||
"github.com/edgelesssys/constellation/v2/internal/kms/kms"
|
||||
"github.com/edgelesssys/constellation/v2/internal/logger"
|
||||
"github.com/edgelesssys/constellation/v2/keyservice/keyserviceproto"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
|
@ -28,13 +27,13 @@ import (
|
|||
// The server serves aTLS for cluster external requests
|
||||
// and plain gRPC for cluster internal requests.
|
||||
type Server struct {
|
||||
log *logger.Logger
|
||||
log *slog.Logger
|
||||
conKMS kms.CloudKMS
|
||||
keyserviceproto.UnimplementedAPIServer
|
||||
}
|
||||
|
||||
// New creates a new Server.
|
||||
func New(log *logger.Logger, conKMS kms.CloudKMS) *Server {
|
||||
func New(log *slog.Logger, conKMS kms.CloudKMS) *Server {
|
||||
return &Server{
|
||||
log: log,
|
||||
conKMS: conKMS,
|
||||
|
@ -49,12 +48,12 @@ func (s *Server) Run(port string) error {
|
|||
return fmt.Errorf("failed to listen on port %s: %v", port, err)
|
||||
}
|
||||
|
||||
server := grpc.NewServer(s.log.Named("gRPC").GetServerUnaryInterceptor())
|
||||
server := grpc.NewServer(logger.GetServerUnaryInterceptor(s.log.WithGroup("gRPC")))
|
||||
keyserviceproto.RegisterAPIServer(server, s)
|
||||
s.log.Named("gRPC").WithIncreasedLevel(zapcore.WarnLevel).ReplaceGRPCLogger()
|
||||
logger.ReplaceGRPCLogger(slog.New(logger.NewLevelHandler(slog.LevelWarn, s.log.Handler())).WithGroup("gRPC"))
|
||||
|
||||
// start the server
|
||||
s.log.Infof("Starting Constellation key management service on %s", listener.Addr().String())
|
||||
s.log.Info(fmt.Sprintf("Starting Constellation key management service on %s", listener.Addr().String()))
|
||||
return server.Serve(listener)
|
||||
}
|
||||
|
||||
|
@ -64,19 +63,19 @@ func (s *Server) GetDataKey(ctx context.Context, in *keyserviceproto.GetDataKeyR
|
|||
|
||||
// Error on 0 key length
|
||||
if in.Length == 0 {
|
||||
log.Errorf("Requested key length is zero")
|
||||
log.Error("Requested key length is zero")
|
||||
return nil, status.Error(codes.InvalidArgument, "can't derive key with length zero")
|
||||
}
|
||||
|
||||
// Error on empty DataKeyId
|
||||
if in.DataKeyId == "" {
|
||||
log.Errorf("No data key ID specified")
|
||||
log.Error("No data key ID specified")
|
||||
return nil, status.Error(codes.InvalidArgument, "no data key ID specified")
|
||||
}
|
||||
|
||||
key, err := s.conKMS.GetDEK(ctx, crypto.DEKPrefix+in.DataKeyId, int(in.Length))
|
||||
if err != nil {
|
||||
log.With(zap.Error(err)).Errorf("Failed to get data key")
|
||||
log.With(slog.Any("error", err)).Error("Failed to get data key")
|
||||
return nil, status.Errorf(codes.Internal, "%v", err)
|
||||
}
|
||||
return &keyserviceproto.GetDataKeyResponse{DataKey: key}, nil
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue