deps: convert zap to slog (#2825)

This commit is contained in:
miampf 2024-02-08 14:20:01 +00:00 committed by GitHub
parent 3765cb0762
commit 54cce77bab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
182 changed files with 1474 additions and 1509 deletions

View file

@ -10,6 +10,9 @@ import (
"context"
"errors"
"flag"
"fmt"
"log/slog"
"os"
"path/filepath"
"strconv"
"time"
@ -22,7 +25,6 @@ import (
"github.com/edgelesssys/constellation/v2/internal/logger"
"github.com/edgelesssys/constellation/v2/keyservice/internal/server"
"github.com/spf13/afero"
"go.uber.org/zap"
)
func main() {
@ -32,26 +34,30 @@ func main() {
verbosity := flag.Int("v", 0, logger.CmdLineVerbosityDescription)
flag.Parse()
log := logger.New(logger.JSONLog, logger.VerbosityFromInt(*verbosity))
log := logger.NewTextLogger(logger.VerbosityFromInt(*verbosity))
log.With(zap.String("version", constants.BinaryVersion().String())).
Infof("Constellation Key Management Service")
log.With(slog.String("version", constants.BinaryVersion().String())).
Info("Constellation Key Management Service")
// read master secret and salt
file := file.NewHandler(afero.NewOsFs())
masterKey, err := file.Read(*masterSecretPath)
if err != nil {
log.With(zap.Error(err)).Fatalf("Failed to read master secret")
log.With(slog.Any("error", err)).Error("Failed to read master secret")
os.Exit(1)
}
if len(masterKey) < crypto.MasterSecretLengthMin {
log.With(zap.Error(errors.New("invalid key length"))).Fatalf("Provided master secret is smaller than the required minimum of %d bytes", crypto.MasterSecretLengthMin)
log.With(slog.Any("error", errors.New("invalid key length"))).Error(fmt.Sprintf("Provided master secret is smaller than the required minimum of %d bytes", crypto.MasterSecretLengthMin))
os.Exit(1)
}
salt, err := file.Read(*saltPath)
if err != nil {
log.With(zap.Error(err)).Fatalf("Failed to read salt")
log.With(slog.Any("error", err)).Error("Failed to read salt")
os.Exit(1)
}
if len(salt) < crypto.RNGLengthDefault {
log.With(zap.Error(errors.New("invalid salt length"))).Fatalf("Expected salt to be %d bytes, but got %d", crypto.RNGLengthDefault, len(salt))
log.With(slog.Any("error", errors.New("invalid salt length"))).Error(fmt.Sprintf("Expected salt to be %d bytes, but got %d", crypto.RNGLengthDefault, len(salt)))
os.Exit(1)
}
masterSecret := uri.MasterSecret{Key: masterKey, Salt: salt}
@ -60,11 +66,13 @@ func main() {
defer cancel()
conKMS, err := setup.KMS(ctx, uri.NoStoreURI, masterSecret.EncodeToURI())
if err != nil {
log.With(zap.Error(err)).Fatalf("Failed to setup KMS")
log.With(slog.Any("error", err)).Error("Failed to setup KMS")
os.Exit(1)
}
defer conKMS.Close()
if err := server.New(log.Named("keyService"), conKMS).Run(*port); err != nil {
log.With(zap.Error(err)).Fatalf("Failed to run key-service server")
if err := server.New(log.WithGroup("keyService"), conKMS).Run(*port); err != nil {
log.With(slog.Any("error", err)).Error("Failed to run key-service server")
os.Exit(1)
}
}