Replace logging with default logging interface (#233)

* Add test logger

* Refactor access manager logging

* Refactor activation service logging

* Refactor debugd logging

* Refactor kms server logging

* Refactor disk-mapper logging

Signed-off-by: Daniel Weiße <dw@edgeless.systems>
This commit is contained in:
Daniel Weiße 2022-06-28 16:51:30 +02:00 committed by GitHub
parent e3f78a5bff
commit b10b13b173
42 changed files with 513 additions and 328 deletions

View file

@ -3,11 +3,12 @@ package ssh
import (
"context"
"fmt"
"log"
"os"
"sync"
"github.com/edgelesssys/constellation/internal/deploy/user"
"github.com/edgelesssys/constellation/internal/logger"
"go.uber.org/zap"
)
// UserKey describes an user that should be created with a corresponding public SSH key.
@ -18,14 +19,16 @@ type UserKey struct {
// Access reads SSH public keys from a channel, creates the specified users if required and writes the public keys to the users authorized_keys file.
type Access struct {
log *logger.Logger
userManager user.LinuxUserManager
authorized map[string]bool
mux sync.Mutex
}
// NewAccess creates a new Access.
func NewAccess(userManager user.LinuxUserManager) *Access {
func NewAccess(log *logger.Logger, userManager user.LinuxUserManager) *Access {
return &Access{
log: log,
userManager: userManager,
mux: sync.Mutex{},
authorized: map[string]bool{},
@ -51,7 +54,7 @@ func (s *Access) DeployAuthorizedKey(ctx context.Context, sshKey UserKey) error
if s.alreadyAuthorized(sshKey) {
return nil
}
log.Printf("Trying to deploy ssh key for %s\n", sshKey.Username)
s.log.With(zap.String("username", sshKey.Username)).Infof("Trying to deploy ssh key for user")
user, err := s.userManager.EnsureLinuxUserExists(ctx, sshKey.Username)
if err != nil {
return err
@ -87,6 +90,6 @@ func (s *Access) DeployAuthorizedKey(ctx context.Context, sshKey UserKey) error
return err
}
s.rememberAuthorized(sshKey)
log.Printf("Successfully authorized %s\n", sshKey.Username)
s.log.With(zap.String("username", sshKey.Username)).Infof("Successfully authorized user")
return nil
}

View file

@ -6,6 +6,7 @@ import (
"testing"
"github.com/edgelesssys/constellation/internal/deploy/user"
"github.com/edgelesssys/constellation/internal/logger"
"github.com/spf13/afero"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -66,6 +67,7 @@ func TestDeploySSHAuthorizedKey(t *testing.T) {
authorized["user:ssh-rsa testkey"] = true
}
sshAccess := Access{
log: logger.NewTest(t),
userManager: userManager,
mux: sync.Mutex{},
authorized: authorized,