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

@ -17,6 +17,7 @@ import (
"errors"
"fmt"
"io/fs"
"log/slog"
"net"
"os"
"path/filepath"
@ -31,10 +32,8 @@ import (
"github.com/edgelesssys/constellation/v2/internal/constants"
"github.com/edgelesssys/constellation/v2/internal/crypto"
"github.com/edgelesssys/constellation/v2/internal/file"
"github.com/edgelesssys/constellation/v2/internal/logger"
"github.com/edgelesssys/constellation/v2/internal/nodestate"
"github.com/spf13/afero"
"go.uber.org/zap"
)
const (
@ -49,7 +48,7 @@ const (
// Manager handles formatting, mapping, mounting and unmounting of state disks.
type Manager struct {
log *logger.Logger
log *slog.Logger
csp string
diskPath string
fs afero.Afero
@ -60,7 +59,7 @@ type Manager struct {
}
// New initializes a SetupManager with the given parameters.
func New(log *logger.Logger, csp string, diskPath string, fs afero.Afero,
func New(log *slog.Logger, csp string, diskPath string, fs afero.Afero,
mapper DeviceMapper, mounter Mounter, openDevice vtpm.TPMOpenFunc,
) *Manager {
return &Manager{
@ -82,7 +81,7 @@ func (s *Manager) PrepareExistingDisk(recover RecoveryDoer) error {
if err != nil {
return err
}
s.log.With(zap.String("uuid", uuid)).Infof("Preparing existing state disk")
s.log.With(slog.String("uuid", uuid)).Info("Preparing existing state disk")
endpoint := net.JoinHostPort("0.0.0.0", strconv.Itoa(constants.RecoveryPort))
passphrase, measurementSecret, err := recover.Do(uuid, endpoint)
@ -128,7 +127,7 @@ func (s *Manager) PrepareExistingDisk(recover RecoveryDoer) error {
// PrepareNewDisk prepares an instances state disk by formatting the disk as a LUKS device using a random passphrase.
func (s *Manager) PrepareNewDisk() error {
uuid, _ := s.mapper.DiskUUID()
s.log.With(zap.String("uuid", uuid)).Infof("Preparing new state disk")
s.log.With(slog.String("uuid", uuid)).Info("Preparing new state disk")
// generate and save temporary passphrase
passphrase := make([]byte, crypto.RNGLengthDefault)
@ -192,12 +191,12 @@ func (s *Manager) LogDevices() error {
devices = append(devices, fileInfo)
}
s.log.Infof("List of all available block devices and partitions:")
s.log.Info("List of all available block devices and partitions:")
for _, device := range devices {
var stat syscall.Statfs_t
dev := "/dev/" + device.Name()
if err := syscall.Statfs(dev, &stat); err != nil {
s.log.With(zap.Error(err)).Errorf("failed to statfs %s", dev)
s.log.With(slog.Any("error", err)).Error(fmt.Sprintf("failed to statfs %s", dev))
continue
}
@ -206,7 +205,7 @@ func (s *Manager) LogDevices() error {
free := stat.Bfree * uint64(stat.Bsize)
avail := stat.Bavail * uint64(stat.Bsize)
s.log.Infof(
s.log.Info(fmt.Sprintf(
"Name: %-15s, Size: %-10d, Mode: %s, ModTime: %s, Size = %-10d, Free = %-10d, Available = %-10d\n",
dev,
device.Size(),
@ -214,7 +213,7 @@ func (s *Manager) LogDevices() error {
device.ModTime(),
size,
free,
avail)
avail))
}
return nil
}