diff --git a/bootstrapper/cmd/bootstrapper/main.go b/bootstrapper/cmd/bootstrapper/main.go index b39c93ac97..4866a2a664 100644 --- a/bootstrapper/cmd/bootstrapper/main.go +++ b/bootstrapper/cmd/bootstrapper/main.go @@ -7,111 +7,111 @@ SPDX-License-Identifier: AGPL-3.0-only package main import ( - "context" - "flag" - "io" - "log/slog" - "os" - "strconv" - "fmt" - - "github.com/spf13/afero" - - "github.com/edgelesssys/constellation/v2/bootstrapper/internal/kubernetes" - "github.com/edgelesssys/constellation/v2/bootstrapper/internal/kubernetes/k8sapi" - "github.com/edgelesssys/constellation/v2/bootstrapper/internal/kubernetes/kubewaiter" - "github.com/edgelesssys/constellation/v2/bootstrapper/internal/logging" - "github.com/edgelesssys/constellation/v2/internal/attestation/choose" - "github.com/edgelesssys/constellation/v2/internal/attestation/simulator" - "github.com/edgelesssys/constellation/v2/internal/attestation/tdx" - "github.com/edgelesssys/constellation/v2/internal/attestation/variant" - "github.com/edgelesssys/constellation/v2/internal/attestation/vtpm" - awscloud "github.com/edgelesssys/constellation/v2/internal/cloud/aws" - azurecloud "github.com/edgelesssys/constellation/v2/internal/cloud/azure" - "github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider" - gcpcloud "github.com/edgelesssys/constellation/v2/internal/cloud/gcp" - openstackcloud "github.com/edgelesssys/constellation/v2/internal/cloud/openstack" - qemucloud "github.com/edgelesssys/constellation/v2/internal/cloud/qemu" - "github.com/edgelesssys/constellation/v2/internal/constants" - "github.com/edgelesssys/constellation/v2/internal/file" - "github.com/edgelesssys/constellation/v2/internal/kubernetes/kubectl" - "github.com/edgelesssys/constellation/v2/internal/logger" + "context" + "flag" + "fmt" + "io" + "log/slog" + "os" + "strconv" + + "github.com/spf13/afero" + + "github.com/edgelesssys/constellation/v2/bootstrapper/internal/kubernetes" + "github.com/edgelesssys/constellation/v2/bootstrapper/internal/kubernetes/k8sapi" + "github.com/edgelesssys/constellation/v2/bootstrapper/internal/kubernetes/kubewaiter" + "github.com/edgelesssys/constellation/v2/bootstrapper/internal/logging" + "github.com/edgelesssys/constellation/v2/internal/attestation/choose" + "github.com/edgelesssys/constellation/v2/internal/attestation/simulator" + "github.com/edgelesssys/constellation/v2/internal/attestation/tdx" + "github.com/edgelesssys/constellation/v2/internal/attestation/variant" + "github.com/edgelesssys/constellation/v2/internal/attestation/vtpm" + awscloud "github.com/edgelesssys/constellation/v2/internal/cloud/aws" + azurecloud "github.com/edgelesssys/constellation/v2/internal/cloud/azure" + "github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider" + gcpcloud "github.com/edgelesssys/constellation/v2/internal/cloud/gcp" + openstackcloud "github.com/edgelesssys/constellation/v2/internal/cloud/openstack" + qemucloud "github.com/edgelesssys/constellation/v2/internal/cloud/qemu" + "github.com/edgelesssys/constellation/v2/internal/constants" + "github.com/edgelesssys/constellation/v2/internal/file" + "github.com/edgelesssys/constellation/v2/internal/kubernetes/kubectl" + "github.com/edgelesssys/constellation/v2/internal/logger" ) const ( - // constellationCSP is the environment variable stating which Cloud Service Provider Constellation is running on. - constellationCSP = "CONSTEL_CSP" + // constellationCSP is the environment variable stating which Cloud Service Provider Constellation is running on. + constellationCSP = "CONSTEL_CSP" ) func main() { - gRPCDebug := flag.Bool("debug", false, "Enable gRPC debug logging") - verbosity := flag.Int("v", 0, logger.CmdLineVerbosityDescription) - flag.Parse() - log := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: logger.VerbosityFromInt(*verbosity)})).WithGroup("bootstrapper") - - if *gRPCDebug { - logger.ReplaceGRPCLogger(log.WithGroup("gRPC")) - } else { - logger.ReplaceGRPCLogger(slog.New(logger.NewLevelHandler(slog.LevelWarn, log.Handler())).WithGroup("gRPC")) - } - - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - - bindIP := "0.0.0.0" - bindPort := strconv.Itoa(constants.BootstrapperPort) - var clusterInitJoiner clusterInitJoiner - var metadataAPI metadataAPI - var cloudLogger logging.CloudLogger - var openDevice vtpm.TPMOpenFunc - var fs afero.Fs - - attestVariant, err := variant.FromString(os.Getenv(constants.AttestationVariant)) - if err != nil { - log.With(slog.Any("error", err)).Error("Failed to parse attestation variant") - os.Exit(1) - } - issuer, err := choose.Issuer(attestVariant, log) - if err != nil { - log.With(slog.Any("error", err)).Error("Failed to select issuer") - os.Exit(1) - } - - switch cloudprovider.FromString(os.Getenv(constellationCSP)) { - case cloudprovider.AWS: - metadata, err := awscloud.New(ctx) - if err != nil { - log.With(slog.Any("error", err)).Error("Failed to set up AWS metadata API") - os.Exit(1) - } - metadataAPI = metadata - - cloudLogger, err = awscloud.NewLogger(ctx) - if err != nil { - log.With(slog.Any("error", err)).Error("Failed to set up cloud logger") - os.Exit(1) - } - - clusterInitJoiner = kubernetes.New( - "aws", k8sapi.NewKubernetesUtil(), &k8sapi.KubdeadmConfiguration{}, kubectl.NewUninitialized(), - metadata, &kubewaiter.CloudKubeAPIWaiter{}, - ) - openDevice = vtpm.OpenVTPM - fs = afero.NewOsFs() - - case cloudprovider.GCP: - metadata, err := gcpcloud.New(ctx) - if err != nil { - log.With(slog.Any("error", err)).Error("Failed to create GCP metadata client") - os.Exit(1) - } - defer metadata.Close() - - cloudLogger, err = gcpcloud.NewLogger(ctx, "constellation-boot-log") - if err != nil { - log.With(slog.Any("error", err)).Error("Failed to set up cloud logger") - os.Exit(1) - } + gRPCDebug := flag.Bool("debug", false, "Enable gRPC debug logging") + verbosity := flag.Int("v", 0, logger.CmdLineVerbosityDescription) + flag.Parse() + log := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: logger.VerbosityFromInt(*verbosity)})).WithGroup("bootstrapper") + + if *gRPCDebug { + logger.ReplaceGRPCLogger(log.WithGroup("gRPC")) + } else { + logger.ReplaceGRPCLogger(slog.New(logger.NewLevelHandler(slog.LevelWarn, log.Handler())).WithGroup("gRPC")) + } + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + bindIP := "0.0.0.0" + bindPort := strconv.Itoa(constants.BootstrapperPort) + var clusterInitJoiner clusterInitJoiner + var metadataAPI metadataAPI + var cloudLogger logging.CloudLogger + var openDevice vtpm.TPMOpenFunc + var fs afero.Fs + + attestVariant, err := variant.FromString(os.Getenv(constants.AttestationVariant)) + if err != nil { + log.With(slog.Any("error", err)).Error("Failed to parse attestation variant") + os.Exit(1) + } + issuer, err := choose.Issuer(attestVariant, log) + if err != nil { + log.With(slog.Any("error", err)).Error("Failed to select issuer") + os.Exit(1) + } + + switch cloudprovider.FromString(os.Getenv(constellationCSP)) { + case cloudprovider.AWS: + metadata, err := awscloud.New(ctx) + if err != nil { + log.With(slog.Any("error", err)).Error("Failed to set up AWS metadata API") + os.Exit(1) + } + metadataAPI = metadata + + cloudLogger, err = awscloud.NewLogger(ctx) + if err != nil { + log.With(slog.Any("error", err)).Error("Failed to set up cloud logger") + os.Exit(1) + } + + clusterInitJoiner = kubernetes.New( + "aws", k8sapi.NewKubernetesUtil(), &k8sapi.KubdeadmConfiguration{}, kubectl.NewUninitialized(), + metadata, &kubewaiter.CloudKubeAPIWaiter{}, + ) + openDevice = vtpm.OpenVTPM + fs = afero.NewOsFs() + + case cloudprovider.GCP: + metadata, err := gcpcloud.New(ctx) + if err != nil { + log.With(slog.Any("error", err)).Error("Failed to create GCP metadata client") + os.Exit(1) + } + defer metadata.Close() + + cloudLogger, err = gcpcloud.NewLogger(ctx, "constellation-boot-log") + if err != nil { + log.With(slog.Any("error", err)).Error("Failed to set up cloud logger") + os.Exit(1) + } metadataAPI = metadata clusterInitJoiner = kubernetes.New( @@ -121,77 +121,77 @@ func main() { openDevice = vtpm.OpenVTPM fs = afero.NewOsFs() - case cloudprovider.Azure: - metadata, err := azurecloud.New(ctx) - if err != nil { - log.With(slog.Any("error", err)).Error("Failed to create Azure metadata client") - os.Exit(1) - } - cloudLogger, err = azurecloud.NewLogger(ctx) - if err != nil { - log.With(slog.Any("error", err)).Error("Failed to set up cloud logger") - os.Exit(1) - } - if err := metadata.PrepareControlPlaneNode(ctx, log); err != nil { - log.With(slog.Any("error", err)).Error("Failed to prepare Azure control plane node") - os.Exit(1) - } - - metadataAPI = metadata - clusterInitJoiner = kubernetes.New( - "azure", k8sapi.NewKubernetesUtil(), &k8sapi.KubdeadmConfiguration{}, kubectl.NewUninitialized(), - metadata, &kubewaiter.CloudKubeAPIWaiter{}, - ) - - openDevice = vtpm.OpenVTPM - fs = afero.NewOsFs() - - case cloudprovider.QEMU: - cloudLogger = qemucloud.NewLogger() - metadata := qemucloud.New() - clusterInitJoiner = kubernetes.New( - "qemu", k8sapi.NewKubernetesUtil(), &k8sapi.KubdeadmConfiguration{}, kubectl.NewUninitialized(), - metadata, &kubewaiter.CloudKubeAPIWaiter{}, - ) - metadataAPI = metadata - - switch attestVariant { - case variant.QEMUVTPM{}: - openDevice = vtpm.OpenVTPM - case variant.QEMUTDX{}: - openDevice = func() (io.ReadWriteCloser, error) { - return tdx.Open() - } - default: - log.Error(fmt.Sprintf("Unsupported attestation variant: %s", attestVariant)) - os.Exit(1) - } - fs = afero.NewOsFs() - case cloudprovider.OpenStack: - cloudLogger = &logging.NopLogger{} - metadata, err := openstackcloud.New(ctx) - if err != nil { - log.With(slog.Any("error", err)).Error("Failed to create OpenStack metadata client") - os.Exit(1) - } - clusterInitJoiner = kubernetes.New( - "openstack", k8sapi.NewKubernetesUtil(), &k8sapi.KubdeadmConfiguration{}, kubectl.NewUninitialized(), - metadata, &kubewaiter.CloudKubeAPIWaiter{}, - ) - metadataAPI = metadata - openDevice = vtpm.OpenVTPM - fs = afero.NewOsFs() - default: - clusterInitJoiner = &clusterFake{} - metadataAPI = &providerMetadataFake{} - cloudLogger = &logging.NopLogger{} - var simulatedTPMCloser io.Closer - openDevice, simulatedTPMCloser = simulator.NewSimulatedTPMOpenFunc() - defer simulatedTPMCloser.Close() - fs = afero.NewMemMapFs() - } - - fileHandler := file.NewHandler(fs) - - run(issuer, openDevice, fileHandler, clusterInitJoiner, metadataAPI, bindIP, bindPort, log, cloudLogger) + case cloudprovider.Azure: + metadata, err := azurecloud.New(ctx) + if err != nil { + log.With(slog.Any("error", err)).Error("Failed to create Azure metadata client") + os.Exit(1) + } + cloudLogger, err = azurecloud.NewLogger(ctx) + if err != nil { + log.With(slog.Any("error", err)).Error("Failed to set up cloud logger") + os.Exit(1) + } + if err := metadata.PrepareControlPlaneNode(ctx, log); err != nil { + log.With(slog.Any("error", err)).Error("Failed to prepare Azure control plane node") + os.Exit(1) + } + + metadataAPI = metadata + clusterInitJoiner = kubernetes.New( + "azure", k8sapi.NewKubernetesUtil(), &k8sapi.KubdeadmConfiguration{}, kubectl.NewUninitialized(), + metadata, &kubewaiter.CloudKubeAPIWaiter{}, + ) + + openDevice = vtpm.OpenVTPM + fs = afero.NewOsFs() + + case cloudprovider.QEMU: + cloudLogger = qemucloud.NewLogger() + metadata := qemucloud.New() + clusterInitJoiner = kubernetes.New( + "qemu", k8sapi.NewKubernetesUtil(), &k8sapi.KubdeadmConfiguration{}, kubectl.NewUninitialized(), + metadata, &kubewaiter.CloudKubeAPIWaiter{}, + ) + metadataAPI = metadata + + switch attestVariant { + case variant.QEMUVTPM{}: + openDevice = vtpm.OpenVTPM + case variant.QEMUTDX{}: + openDevice = func() (io.ReadWriteCloser, error) { + return tdx.Open() + } + default: + log.Error(fmt.Sprintf("Unsupported attestation variant: %s", attestVariant)) + os.Exit(1) + } + fs = afero.NewOsFs() + case cloudprovider.OpenStack: + cloudLogger = &logging.NopLogger{} + metadata, err := openstackcloud.New(ctx) + if err != nil { + log.With(slog.Any("error", err)).Error("Failed to create OpenStack metadata client") + os.Exit(1) + } + clusterInitJoiner = kubernetes.New( + "openstack", k8sapi.NewKubernetesUtil(), &k8sapi.KubdeadmConfiguration{}, kubectl.NewUninitialized(), + metadata, &kubewaiter.CloudKubeAPIWaiter{}, + ) + metadataAPI = metadata + openDevice = vtpm.OpenVTPM + fs = afero.NewOsFs() + default: + clusterInitJoiner = &clusterFake{} + metadataAPI = &providerMetadataFake{} + cloudLogger = &logging.NopLogger{} + var simulatedTPMCloser io.Closer + openDevice, simulatedTPMCloser = simulator.NewSimulatedTPMOpenFunc() + defer simulatedTPMCloser.Close() + fs = afero.NewMemMapFs() + } + + fileHandler := file.NewHandler(fs) + + run(issuer, openDevice, fileHandler, clusterInitJoiner, metadataAPI, bindIP, bindPort, log, cloudLogger) } diff --git a/bootstrapper/cmd/bootstrapper/run.go b/bootstrapper/cmd/bootstrapper/run.go index 09c8032ffe..571f7bd4c6 100644 --- a/bootstrapper/cmd/bootstrapper/run.go +++ b/bootstrapper/cmd/bootstrapper/run.go @@ -28,80 +28,80 @@ import ( ) func run(issuer atls.Issuer, openDevice vtpm.TPMOpenFunc, fileHandler file.Handler, -kube clusterInitJoiner, metadata metadataAPI, -bindIP, bindPort string, log *slog.Logger, -cloudLogger logging.CloudLogger, + kube clusterInitJoiner, metadata metadataAPI, + bindIP, bindPort string, log *slog.Logger, + cloudLogger logging.CloudLogger, ) { - defer cloudLogger.Close() - - log.With(slog.String("version", constants.BinaryVersion().String())).Info("Starting bootstrapper") - cloudLogger.Disclose("bootstrapper started running...") - - uuid, err := getDiskUUID() - if err != nil { - log.With(slog.Any("error", err)).Error("Failed to get disk UUID") - cloudLogger.Disclose("Failed to get disk UUID") - } else { - log.Info(fmt.Sprintf("Disk UUID: %s", uuid)) - cloudLogger.Disclose("Disk UUID: " + uuid) - } - - nodeBootstrapped, err := initialize.IsNodeBootstrapped(openDevice) - if err != nil { - log.With(slog.Any("error", err)).Error("Failed to check if node was previously bootstrapped") - os.Exit(1) - } - - if nodeBootstrapped { - if err := kube.StartKubelet(); err != nil { - log.With(slog.Any("error", err)).Error("Failed to restart kubelet") - os.Exit(1) - } - return - } - - nodeLock := nodelock.New(openDevice) - initServer, err := initserver.New(context.Background(), nodeLock, kube, issuer, fileHandler, metadata, log) - if err != nil { - log.With(slog.Any("error", err)).Error("Failed to create init server") - os.Exit(1) - } - - dialer := dialer.New(issuer, nil, &net.Dialer{}) - joinClient := joinclient.New(nodeLock, dialer, kube, metadata, log) - - cleaner := clean.New().With(initServer).With(joinClient) - go cleaner.Start() - defer cleaner.Done() - - joinClient.Start(cleaner) - - if err := initServer.Serve(bindIP, bindPort, cleaner); err != nil { - log.With(slog.Any("error", err)).Error("Failed to serve init server") - os.Exit(1) - } - - log.Info("bootstrapper done") - cloudLogger.Disclose("bootstrapper done") + defer cloudLogger.Close() + + log.With(slog.String("version", constants.BinaryVersion().String())).Info("Starting bootstrapper") + cloudLogger.Disclose("bootstrapper started running...") + + uuid, err := getDiskUUID() + if err != nil { + log.With(slog.Any("error", err)).Error("Failed to get disk UUID") + cloudLogger.Disclose("Failed to get disk UUID") + } else { + log.Info(fmt.Sprintf("Disk UUID: %s", uuid)) + cloudLogger.Disclose("Disk UUID: " + uuid) + } + + nodeBootstrapped, err := initialize.IsNodeBootstrapped(openDevice) + if err != nil { + log.With(slog.Any("error", err)).Error("Failed to check if node was previously bootstrapped") + os.Exit(1) + } + + if nodeBootstrapped { + if err := kube.StartKubelet(); err != nil { + log.With(slog.Any("error", err)).Error("Failed to restart kubelet") + os.Exit(1) + } + return + } + + nodeLock := nodelock.New(openDevice) + initServer, err := initserver.New(context.Background(), nodeLock, kube, issuer, fileHandler, metadata, log) + if err != nil { + log.With(slog.Any("error", err)).Error("Failed to create init server") + os.Exit(1) + } + + dialer := dialer.New(issuer, nil, &net.Dialer{}) + joinClient := joinclient.New(nodeLock, dialer, kube, metadata, log) + + cleaner := clean.New().With(initServer).With(joinClient) + go cleaner.Start() + defer cleaner.Done() + + joinClient.Start(cleaner) + + if err := initServer.Serve(bindIP, bindPort, cleaner); err != nil { + log.With(slog.Any("error", err)).Error("Failed to serve init server") + os.Exit(1) + } + + log.Info("bootstrapper done") + cloudLogger.Disclose("bootstrapper done") } func getDiskUUID() (string, error) { - disk := diskencryption.New() - free, err := disk.Open() - if err != nil { - return "", err - } - defer free() - return disk.UUID() + disk := diskencryption.New() + free, err := disk.Open() + if err != nil { + return "", err + } + defer free() + return disk.UUID() } type clusterInitJoiner interface { - joinclient.ClusterJoiner - initserver.ClusterInitializer - StartKubelet() error + joinclient.ClusterJoiner + initserver.ClusterInitializer + StartKubelet() error } type metadataAPI interface { - joinclient.MetadataAPI - initserver.MetadataAPI + joinclient.MetadataAPI + initserver.MetadataAPI } diff --git a/bootstrapper/internal/initserver/initserver_test.go b/bootstrapper/internal/initserver/initserver_test.go index 4fc71f4acd..c38470ffd6 100644 --- a/bootstrapper/internal/initserver/initserver_test.go +++ b/bootstrapper/internal/initserver/initserver_test.go @@ -11,14 +11,13 @@ import ( "context" "errors" "io" + "log/slog" "net" "strings" "sync" "testing" "time" - "log/slog" - "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/edgelesssys/constellation/v2/bootstrapper/initproto" "github.com/edgelesssys/constellation/v2/internal/atls" "github.com/edgelesssys/constellation/v2/internal/attestation/variant" @@ -26,6 +25,7 @@ import ( "github.com/edgelesssys/constellation/v2/internal/file" kmssetup "github.com/edgelesssys/constellation/v2/internal/kms/setup" "github.com/edgelesssys/constellation/v2/internal/kms/uri" + "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/edgelesssys/constellation/v2/internal/versions/components" "github.com/spf13/afero" "github.com/stretchr/testify/assert" @@ -66,7 +66,7 @@ func TestNew(t *testing.T) { t.Run(name, func(t *testing.T) { assert := assert.New(t) - server, err := New(context.TODO(), newFakeLock(), &stubClusterInitializer{}, atls.NewFakeIssuer(variant.Dummy{}), fh, &tc.metadata, slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil))) + server, err := New(context.TODO(), newFakeLock(), &stubClusterInitializer{}, atls.NewFakeIssuer(variant.Dummy{}), fh, &tc.metadata, slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil))) if tc.wantErr { assert.Error(err) return @@ -214,7 +214,7 @@ func TestInit(t *testing.T) { initializer: tc.initializer, disk: tc.disk, fileHandler: tc.fileHandler, - log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), grpcServer: serveStopper, cleaner: &fakeCleaner{serveStopper: serveStopper}, initSecretHash: tc.initSecretHash, diff --git a/bootstrapper/internal/joinclient/joinclient_test.go b/bootstrapper/internal/joinclient/joinclient_test.go index 90c519fc13..2c80973cb3 100644 --- a/bootstrapper/internal/joinclient/joinclient_test.go +++ b/bootstrapper/internal/joinclient/joinclient_test.go @@ -16,13 +16,13 @@ import ( "testing" "time" - "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/edgelesssys/constellation/v2/internal/cloud/metadata" "github.com/edgelesssys/constellation/v2/internal/constants" "github.com/edgelesssys/constellation/v2/internal/file" "github.com/edgelesssys/constellation/v2/internal/grpc/atlscredentials" "github.com/edgelesssys/constellation/v2/internal/grpc/dialer" "github.com/edgelesssys/constellation/v2/internal/grpc/testdialer" + "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/edgelesssys/constellation/v2/internal/role" "github.com/edgelesssys/constellation/v2/internal/versions/components" "github.com/edgelesssys/constellation/v2/joinservice/joinproto" @@ -221,7 +221,7 @@ func TestClient(t *testing.T) { fileHandler: fileHandler, metadataAPI: metadataAPI, clock: clock, - log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), } serverCreds := atlscredentials.New(nil, nil) @@ -276,7 +276,7 @@ func TestClientConcurrentStartStop(t *testing.T) { fileHandler: file.NewHandler(afero.NewMemMapFs()), metadataAPI: &stubRepeaterMetadataAPI{}, clock: testclock.NewFakeClock(time.Now()), - log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), } wg := sync.WaitGroup{} diff --git a/bootstrapper/internal/kubernetes/kubernetes_test.go b/bootstrapper/internal/kubernetes/kubernetes_test.go index c2816501d7..1121b11838 100644 --- a/bootstrapper/internal/kubernetes/kubernetes_test.go +++ b/bootstrapper/internal/kubernetes/kubernetes_test.go @@ -14,12 +14,12 @@ import ( "strconv" "testing" - "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/edgelesssys/constellation/v2/bootstrapper/internal/kubernetes/k8sapi" "github.com/edgelesssys/constellation/v2/bootstrapper/internal/kubernetes/kubewaiter" "github.com/edgelesssys/constellation/v2/internal/cloud/metadata" "github.com/edgelesssys/constellation/v2/internal/constants" "github.com/edgelesssys/constellation/v2/internal/kubernetes" + "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/edgelesssys/constellation/v2/internal/role" "github.com/edgelesssys/constellation/v2/internal/versions" "github.com/edgelesssys/constellation/v2/internal/versions/components" @@ -188,7 +188,7 @@ func TestInitCluster(t *testing.T) { _, err := kube.InitCluster( context.Background(), string(tc.k8sVersion), "kubernetes", - false, nil, nil, "", slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + false, nil, nil, "", slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), ) if tc.wantErr { diff --git a/cli/internal/cmd/apply_test.go b/cli/internal/cmd/apply_test.go index 36a676b5b5..a503cc4996 100644 --- a/cli/internal/cmd/apply_test.go +++ b/cli/internal/cmd/apply_test.go @@ -18,7 +18,6 @@ import ( "testing" "time" - "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/edgelesssys/constellation/v2/internal/atls" "github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider" "github.com/edgelesssys/constellation/v2/internal/cloud/gcpshared" @@ -29,6 +28,7 @@ import ( "github.com/edgelesssys/constellation/v2/internal/constellation/state" "github.com/edgelesssys/constellation/v2/internal/file" "github.com/edgelesssys/constellation/v2/internal/kms/uri" + "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/edgelesssys/constellation/v2/internal/versions" "github.com/spf13/afero" "github.com/spf13/pflag" @@ -197,7 +197,7 @@ func TestBackupHelmCharts(t *testing.T) { applier: &stubConstellApplier{ stubKubernetesUpgrader: tc.backupClient, }, - log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), } err := a.backupHelmCharts(context.Background(), tc.helmApplier, tc.includesUpgrades, "") @@ -443,7 +443,7 @@ func TestValidateInputs(t *testing.T) { cmd.SetIn(bytes.NewBufferString(tc.stdin)) a := applyCmd{ - log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), fileHandler: fileHandler, flags: tc.flags, } diff --git a/cli/internal/cmd/configfetchmeasurements_test.go b/cli/internal/cmd/configfetchmeasurements_test.go index 9611d6afb1..80d8b38e80 100644 --- a/cli/internal/cmd/configfetchmeasurements_test.go +++ b/cli/internal/cmd/configfetchmeasurements_test.go @@ -13,7 +13,6 @@ import ( "net/url" "testing" - "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/edgelesssys/constellation/v2/internal/api/attestationconfigapi" "github.com/edgelesssys/constellation/v2/internal/api/versionsapi" "github.com/edgelesssys/constellation/v2/internal/attestation/measurements" @@ -22,6 +21,7 @@ import ( "github.com/edgelesssys/constellation/v2/internal/config" "github.com/edgelesssys/constellation/v2/internal/constants" "github.com/edgelesssys/constellation/v2/internal/file" + "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/spf13/afero" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -181,7 +181,7 @@ func TestConfigFetchMeasurements(t *testing.T) { err := fileHandler.WriteYAML(constants.ConfigFilename, gcpConfig, file.OptMkdirAll) require.NoError(err) fetcher := stubVerifyFetcher{err: tc.err} - cfm := &configFetchMeasurementsCmd{canFetchMeasurements: true, log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), verifyFetcher: fetcher} + cfm := &configFetchMeasurementsCmd{canFetchMeasurements: true, log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), verifyFetcher: fetcher} cfm.flags.insecure = tc.insecureFlag cfm.flags.force = true diff --git a/cli/internal/cmd/configgenerate_test.go b/cli/internal/cmd/configgenerate_test.go index 2d6cb47744..417d4f1765 100644 --- a/cli/internal/cmd/configgenerate_test.go +++ b/cli/internal/cmd/configgenerate_test.go @@ -12,13 +12,13 @@ import ( "strings" "testing" - "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/edgelesssys/constellation/v2/internal/attestation/variant" "github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider" "github.com/edgelesssys/constellation/v2/internal/config" "github.com/edgelesssys/constellation/v2/internal/constants" "github.com/edgelesssys/constellation/v2/internal/constellation/state" "github.com/edgelesssys/constellation/v2/internal/file" + "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/edgelesssys/constellation/v2/internal/versions" "github.com/spf13/afero" "github.com/stretchr/testify/assert" @@ -93,7 +93,7 @@ func TestConfigGenerateDefault(t *testing.T) { cmd := newConfigGenerateCmd() cg := &configGenerateCmd{ - log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), flags: generateFlags{ attestationVariant: variant.Dummy{}, k8sVersion: versions.Default, @@ -145,7 +145,7 @@ func TestConfigGenerateDefaultProviderSpecific(t *testing.T) { wantConf.RemoveProviderAndAttestationExcept(tc.provider) cg := &configGenerateCmd{ - log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), flags: generateFlags{ attestationVariant: variant.Dummy{}, k8sVersion: versions.Default, @@ -178,7 +178,7 @@ func TestConfigGenerateDefaultExists(t *testing.T) { cmd := newConfigGenerateCmd() cg := &configGenerateCmd{ - log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), flags: generateFlags{attestationVariant: variant.Dummy{}}, } require.Error(cg.configGenerate(cmd, fileHandler, cloudprovider.Unknown, "")) diff --git a/cli/internal/cmd/create_test.go b/cli/internal/cmd/create_test.go index 64b19f280a..fbb525b10d 100644 --- a/cli/internal/cmd/create_test.go +++ b/cli/internal/cmd/create_test.go @@ -12,12 +12,12 @@ import ( "log/slog" "testing" - "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider" "github.com/edgelesssys/constellation/v2/internal/config" "github.com/edgelesssys/constellation/v2/internal/constants" "github.com/edgelesssys/constellation/v2/internal/constellation/state" "github.com/edgelesssys/constellation/v2/internal/file" + "github.com/edgelesssys/constellation/v2/internal/logger" consemver "github.com/edgelesssys/constellation/v2/internal/semver" "github.com/spf13/afero" "github.com/stretchr/testify/assert" @@ -228,7 +228,7 @@ func TestCreate(t *testing.T) { skipPhases: newPhases(skipInitPhase, skipAttestationConfigPhase, skipCertSANsPhase, skipHelmPhase, skipImagePhase, skipK8sPhase), }, - log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), spinner: &nopSpinner{}, newInfraApplier: func(_ context.Context) (cloudApplier, func(), error) { @@ -296,7 +296,7 @@ func TestCheckDirClean(t *testing.T) { for _, f := range tc.existingFiles { require.NoError(fh.Write(f, []byte{1, 2, 3}, file.OptNone)) } - a := &applyCmd{log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), fileHandler: fh} + a := &applyCmd{log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), fileHandler: fh} err := a.checkInitFilesClean() if tc.wantErr { diff --git a/cli/internal/cmd/iamcreate_test.go b/cli/internal/cmd/iamcreate_test.go index 7775f4cfc3..62303dee25 100644 --- a/cli/internal/cmd/iamcreate_test.go +++ b/cli/internal/cmd/iamcreate_test.go @@ -12,12 +12,12 @@ import ( "strings" "testing" - "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/edgelesssys/constellation/v2/cli/internal/cloudcmd" "github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider" "github.com/edgelesssys/constellation/v2/internal/config" "github.com/edgelesssys/constellation/v2/internal/constants" "github.com/edgelesssys/constellation/v2/internal/file" + "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/spf13/afero" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -210,7 +210,7 @@ func TestIAMCreateAWS(t *testing.T) { iamCreator := &iamCreator{ cmd: cmd, - log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), spinner: &nopSpinner{}, creator: tc.creator, fileHandler: fileHandler, @@ -386,7 +386,7 @@ func TestIAMCreateAzure(t *testing.T) { iamCreator := &iamCreator{ cmd: cmd, - log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), spinner: &nopSpinner{}, creator: tc.creator, fileHandler: fileHandler, @@ -577,7 +577,7 @@ func TestIAMCreateGCP(t *testing.T) { iamCreator := &iamCreator{ cmd: cmd, - log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), spinner: &nopSpinner{}, creator: tc.creator, fileHandler: fileHandler, diff --git a/cli/internal/cmd/iamdestroy_test.go b/cli/internal/cmd/iamdestroy_test.go index e5203920bf..d9271b0893 100644 --- a/cli/internal/cmd/iamdestroy_test.go +++ b/cli/internal/cmd/iamdestroy_test.go @@ -10,10 +10,10 @@ import ( "log/slog" "testing" - "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/edgelesssys/constellation/v2/internal/cloud/gcpshared" "github.com/edgelesssys/constellation/v2/internal/constants" "github.com/edgelesssys/constellation/v2/internal/file" + "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/spf13/afero" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -107,7 +107,7 @@ func TestIAMDestroy(t *testing.T) { cmd.SetErr(&bytes.Buffer{}) cmd.SetIn(bytes.NewBufferString(tc.stdin)) - c := &destroyCmd{log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), flags: iamDestroyFlags{ + c := &destroyCmd{log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), flags: iamDestroyFlags{ yes: tc.yesFlag, }} @@ -197,7 +197,7 @@ func TestDeleteGCPServiceAccountKeyFile(t *testing.T) { cmd.SetErr(&bytes.Buffer{}) cmd.SetIn(bytes.NewBufferString(tc.stdin)) - c := &destroyCmd{log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil))} + c := &destroyCmd{log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil))} proceed, err := c.deleteGCPServiceAccountKeyFile(cmd, tc.destroyer, tc.fsHandler) if tc.wantErr { diff --git a/cli/internal/cmd/iamupgradeapply_test.go b/cli/internal/cmd/iamupgradeapply_test.go index 709d591131..e4c2bbd2a8 100644 --- a/cli/internal/cmd/iamupgradeapply_test.go +++ b/cli/internal/cmd/iamupgradeapply_test.go @@ -13,7 +13,6 @@ import ( "strings" "testing" - "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/edgelesssys/constellation/v2/cli/internal/terraform" "github.com/edgelesssys/constellation/v2/internal/api/attestationconfigapi" "github.com/edgelesssys/constellation/v2/internal/attestation/variant" @@ -21,6 +20,7 @@ import ( "github.com/edgelesssys/constellation/v2/internal/config" "github.com/edgelesssys/constellation/v2/internal/constants" "github.com/edgelesssys/constellation/v2/internal/file" + "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/spf13/afero" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -132,7 +132,7 @@ func TestIamUpgradeApply(t *testing.T) { iamUpgradeApplyCmd := &iamUpgradeApplyCmd{ fileHandler: tc.fh, - log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), configFetcher: tc.configFetcher, flags: iamUpgradeApplyFlags{ yes: tc.yesFlag, diff --git a/cli/internal/cmd/init_test.go b/cli/internal/cmd/init_test.go index 79e2c402ee..ecd8ca26bf 100644 --- a/cli/internal/cmd/init_test.go +++ b/cli/internal/cmd/init_test.go @@ -10,12 +10,11 @@ import ( "bytes" "context" "fmt" + "log/slog" "strings" "testing" "time" - "log/slog" - "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/edgelesssys/constellation/v2/bootstrapper/initproto" "github.com/edgelesssys/constellation/v2/cli/internal/cmd/pathprefix" "github.com/edgelesssys/constellation/v2/internal/attestation/measurements" @@ -28,6 +27,7 @@ import ( "github.com/edgelesssys/constellation/v2/internal/constellation/state" "github.com/edgelesssys/constellation/v2/internal/file" "github.com/edgelesssys/constellation/v2/internal/kms/uri" + "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/edgelesssys/constellation/v2/internal/semver" "github.com/edgelesssys/constellation/v2/internal/versions" "github.com/spf13/afero" diff --git a/cli/internal/cmd/maapatch_test.go b/cli/internal/cmd/maapatch_test.go index 47a7892007..ab92e26fd9 100644 --- a/cli/internal/cmd/maapatch_test.go +++ b/cli/internal/cmd/maapatch_test.go @@ -11,7 +11,7 @@ import ( "log/slog" "testing" - "github.com/edgelesssys/constellation/v2/internal/logger" + "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/spf13/cobra" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -39,7 +39,7 @@ func TestMAAPatch(t *testing.T) { t.Run(name, func(t *testing.T) { require := require.New(t) - c := &maaPatchCmd{log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), patcher: tc.patcher} + c := &maaPatchCmd{log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), patcher: tc.patcher} err := c.patchMAA(&cobra.Command{}, tc.attestationURL) if tc.wantErr { require.Error(err) diff --git a/cli/internal/cmd/recover_test.go b/cli/internal/cmd/recover_test.go index f2a0d55c10..b1cd9f2853 100644 --- a/cli/internal/cmd/recover_test.go +++ b/cli/internal/cmd/recover_test.go @@ -16,7 +16,6 @@ import ( "testing" "time" - "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/edgelesssys/constellation/v2/disk-mapper/recoverproto" "github.com/edgelesssys/constellation/v2/internal/atls" "github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider" @@ -29,6 +28,7 @@ import ( "github.com/edgelesssys/constellation/v2/internal/grpc/dialer" "github.com/edgelesssys/constellation/v2/internal/grpc/testdialer" "github.com/edgelesssys/constellation/v2/internal/kms/uri" + "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/spf13/afero" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -165,7 +165,7 @@ func TestRecover(t *testing.T) { newDialer := func(atls.Validator) *dialer.Dialer { return nil } r := &recoverCmd{ - log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), configFetcher: stubAttestationFetcher{}, flags: recoverFlags{ rootFlags: rootFlags{force: true}, @@ -219,7 +219,7 @@ func TestDoRecovery(t *testing.T) { go recoverServer.Serve(listener) defer recoverServer.GracefulStop() - r := &recoverCmd{log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil))} + r := &recoverCmd{log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil))} recoverDoer := &recoverDoer{ dialer: dialer.New(nil, nil, netDialer), endpoint: addr, diff --git a/cli/internal/cmd/terminate_test.go b/cli/internal/cmd/terminate_test.go index 1eab82b03f..0fbfaff86a 100644 --- a/cli/internal/cmd/terminate_test.go +++ b/cli/internal/cmd/terminate_test.go @@ -12,10 +12,10 @@ import ( "log/slog" "testing" - "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/edgelesssys/constellation/v2/internal/constants" "github.com/edgelesssys/constellation/v2/internal/constellation/state" "github.com/edgelesssys/constellation/v2/internal/file" + "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/spf13/afero" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -140,7 +140,7 @@ func TestTerminate(t *testing.T) { fileHandler := file.NewHandler(tc.setupFs(require, tc.stateFile)) tCmd := &terminateCmd{ - log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), fileHandler: fileHandler, flags: terminateFlags{ yes: tc.yesFlag, diff --git a/cli/internal/cmd/upgradeapply_test.go b/cli/internal/cmd/upgradeapply_test.go index 0f200de2f7..2eaf0e9f77 100644 --- a/cli/internal/cmd/upgradeapply_test.go +++ b/cli/internal/cmd/upgradeapply_test.go @@ -12,7 +12,6 @@ import ( "log/slog" "testing" - "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/edgelesssys/constellation/v2/cli/internal/cloudcmd" "github.com/edgelesssys/constellation/v2/internal/attestation/variant" "github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider" @@ -23,6 +22,7 @@ import ( "github.com/edgelesssys/constellation/v2/internal/constellation/state" "github.com/edgelesssys/constellation/v2/internal/file" "github.com/edgelesssys/constellation/v2/internal/kms/uri" + "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/edgelesssys/constellation/v2/internal/semver" "github.com/edgelesssys/constellation/v2/internal/versions" "github.com/spf13/afero" @@ -252,7 +252,7 @@ func TestUpgradeApply(t *testing.T) { upgrader := &applyCmd{ fileHandler: fh, flags: tc.flags, - log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), spinner: &nopSpinner{}, merger: &stubMerger{}, newInfraApplier: func(ctx context.Context) (cloudApplier, func(), error) { diff --git a/cli/internal/cmd/upgradecheck_test.go b/cli/internal/cmd/upgradecheck_test.go index 1c1b91e579..7fa7e16003 100644 --- a/cli/internal/cmd/upgradecheck_test.go +++ b/cli/internal/cmd/upgradecheck_test.go @@ -16,7 +16,6 @@ import ( "strings" "testing" - "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/edgelesssys/constellation/v2/internal/api/versionsapi" "github.com/edgelesssys/constellation/v2/internal/attestation/measurements" "github.com/edgelesssys/constellation/v2/internal/attestation/variant" @@ -24,6 +23,7 @@ import ( "github.com/edgelesssys/constellation/v2/internal/config" "github.com/edgelesssys/constellation/v2/internal/constants" "github.com/edgelesssys/constellation/v2/internal/file" + "github.com/edgelesssys/constellation/v2/internal/logger" consemver "github.com/edgelesssys/constellation/v2/internal/semver" "github.com/spf13/afero" "github.com/stretchr/testify/assert" @@ -140,7 +140,7 @@ func TestGetCompatibleImageMeasurements(t *testing.T) { } }) - upgrades, err := getCompatibleImageMeasurements(context.Background(), &bytes.Buffer{}, client, &stubCosignVerifier{}, singleUUIDVerifier(), csp, attestationVariant, versionZero, slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil))) + upgrades, err := getCompatibleImageMeasurements(context.Background(), &bytes.Buffer{}, client, &stubCosignVerifier{}, singleUUIDVerifier(), csp, attestationVariant, versionZero, slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil))) assert.NoError(err) for _, measurement := range upgrades { @@ -216,7 +216,7 @@ func TestUpgradeCheck(t *testing.T) { collect: &tc.collector, terraformChecker: tc.checker, fileHandler: fileHandler, - log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), } cmd := newUpgradeCheckCmd() diff --git a/cli/internal/cmd/verify_test.go b/cli/internal/cmd/verify_test.go index 3bae93e271..56d34623cd 100644 --- a/cli/internal/cmd/verify_test.go +++ b/cli/internal/cmd/verify_test.go @@ -14,13 +14,12 @@ import ( "encoding/base64" "encoding/json" "errors" + "log/slog" "net" "strconv" "strings" "testing" - "log/slog" - "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/edgelesssys/constellation/v2/internal/atls" "github.com/edgelesssys/constellation/v2/internal/attestation/measurements" "github.com/edgelesssys/constellation/v2/internal/attestation/variant" @@ -31,6 +30,7 @@ import ( "github.com/edgelesssys/constellation/v2/internal/file" "github.com/edgelesssys/constellation/v2/internal/grpc/dialer" "github.com/edgelesssys/constellation/v2/internal/grpc/testdialer" + "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/edgelesssys/constellation/v2/verify/verifyproto" tpmProto "github.com/google/go-tpm-tools/proto/tpm" "github.com/spf13/afero" diff --git a/debugd/internal/debugd/deploy/download_test.go b/debugd/internal/debugd/deploy/download_test.go index 3049bd75a4..a5084e3872 100644 --- a/debugd/internal/debugd/deploy/download_test.go +++ b/debugd/internal/debugd/deploy/download_test.go @@ -14,11 +14,11 @@ import ( "strconv" "testing" - "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/edgelesssys/constellation/v2/debugd/internal/filetransfer" pb "github.com/edgelesssys/constellation/v2/debugd/service" "github.com/edgelesssys/constellation/v2/internal/constants" "github.com/edgelesssys/constellation/v2/internal/grpc/testdialer" + "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/stretchr/testify/assert" "go.uber.org/goleak" "google.golang.org/grpc" @@ -117,7 +117,7 @@ func TestDownloadDeployment(t *testing.T) { defer grpcServ.GracefulStop() download := &Download{ - log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), dialer: dialer, transfer: transfer, serviceManager: serviceMgr, @@ -189,7 +189,7 @@ func TestDownloadInfo(t *testing.T) { defer grpcServer.GracefulStop() download := &Download{ - log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), dialer: dialer, info: &tc.infoSetter, } diff --git a/debugd/internal/debugd/deploy/service_test.go b/debugd/internal/debugd/deploy/service_test.go index eef9a43ada..d2c67becdf 100644 --- a/debugd/internal/debugd/deploy/service_test.go +++ b/debugd/internal/debugd/deploy/service_test.go @@ -14,7 +14,7 @@ import ( "sync" "testing" - "github.com/edgelesssys/constellation/v2/internal/logger" + "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/spf13/afero" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -103,7 +103,7 @@ func TestSystemdAction(t *testing.T) { fs := afero.NewMemMapFs() manager := ServiceManager{ - log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), dbus: &tc.dbus, fs: fs, systemdUnitFilewriteLock: sync.Mutex{}, @@ -182,7 +182,7 @@ func TestWriteSystemdUnitFile(t *testing.T) { fs = afero.NewReadOnlyFs(fs) } manager := ServiceManager{ - log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), dbus: &tc.dbus, fs: fs, systemdUnitFilewriteLock: sync.Mutex{}, @@ -295,7 +295,7 @@ func TestOverrideServiceUnitExecStart(t *testing.T) { fs = afero.NewReadOnlyFs(fs) } manager := ServiceManager{ - log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), dbus: &tc.dbus, fs: fs, systemdUnitFilewriteLock: sync.Mutex{}, diff --git a/debugd/internal/debugd/logcollector/logcollector.go b/debugd/internal/debugd/logcollector/logcollector.go index 7389b60251..82dd2e6c06 100644 --- a/debugd/internal/debugd/logcollector/logcollector.go +++ b/debugd/internal/debugd/logcollector/logcollector.go @@ -304,7 +304,7 @@ type cmdLogger struct { } func (c *cmdLogger) Write(p []byte) (n int, err error) { - c.logger.Info(fmt.Sprintf("%s", p)) + c.logger.Info(fmt.Sprintf("%s", p)) return len(p), nil } diff --git a/debugd/internal/debugd/metadata/scheduler_test.go b/debugd/internal/debugd/metadata/scheduler_test.go index 24e5f6d5ed..2ccad35acc 100644 --- a/debugd/internal/debugd/metadata/scheduler_test.go +++ b/debugd/internal/debugd/metadata/scheduler_test.go @@ -9,12 +9,12 @@ package metadata import ( "context" "errors" + "log/slog" "sync" "testing" "time" - "log/slog" - "github.com/edgelesssys/constellation/v2/internal/logger" + "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/stretchr/testify/assert" "go.uber.org/goleak" ) diff --git a/debugd/internal/debugd/server/server.go b/debugd/internal/debugd/server/server.go index 6bacf62d87..aeae7c4a18 100644 --- a/debugd/internal/debugd/server/server.go +++ b/debugd/internal/debugd/server/server.go @@ -167,7 +167,7 @@ func Start(log *slog.Logger, wg *sync.WaitGroup, serv pb.DebugdServer) { lis, err := net.Listen("tcp", net.JoinHostPort("0.0.0.0", strconv.Itoa(constants.DebugdPort))) if err != nil { log.With(slog.Any("error", err)).Error("Listening failed") - os.Exit(1) + os.Exit(1) } log.Info("gRPC server is waiting for connections") grpcServer.Serve(lis) diff --git a/debugd/internal/debugd/server/server_test.go b/debugd/internal/debugd/server/server_test.go index 1fcac8171d..a3fcead8bb 100644 --- a/debugd/internal/debugd/server/server_test.go +++ b/debugd/internal/debugd/server/server_test.go @@ -10,18 +10,18 @@ import ( "context" "errors" "io" + "log/slog" "net" "strconv" "testing" - "log/slog" - "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/edgelesssys/constellation/v2/debugd/internal/debugd/deploy" "github.com/edgelesssys/constellation/v2/debugd/internal/debugd/info" "github.com/edgelesssys/constellation/v2/debugd/internal/filetransfer" pb "github.com/edgelesssys/constellation/v2/debugd/service" "github.com/edgelesssys/constellation/v2/internal/constants" "github.com/edgelesssys/constellation/v2/internal/grpc/testdialer" + "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.uber.org/goleak" diff --git a/debugd/internal/filetransfer/filetransfer.go b/debugd/internal/filetransfer/filetransfer.go index 079148e14b..04c784be19 100644 --- a/debugd/internal/filetransfer/filetransfer.go +++ b/debugd/internal/filetransfer/filetransfer.go @@ -9,8 +9,8 @@ SPDX-License-Identifier: AGPL-3.0-only package filetransfer import ( - "fmt" "errors" + "fmt" "io" "io/fs" "log/slog" diff --git a/debugd/internal/filetransfer/filetransfer_test.go b/debugd/internal/filetransfer/filetransfer_test.go index fb28deaaff..0369de8ed0 100644 --- a/debugd/internal/filetransfer/filetransfer_test.go +++ b/debugd/internal/filetransfer/filetransfer_test.go @@ -9,12 +9,12 @@ package filetransfer import ( "errors" "io" + "log/slog" "testing" - "log/slog" - "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/edgelesssys/constellation/v2/debugd/internal/filetransfer/streamer" pb "github.com/edgelesssys/constellation/v2/debugd/service" + "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.uber.org/goleak" diff --git a/disk-mapper/cmd/main.go b/disk-mapper/cmd/main.go index b5c46dbeb6..f773c56924 100644 --- a/disk-mapper/cmd/main.go +++ b/disk-mapper/cmd/main.go @@ -9,12 +9,12 @@ package main import ( "context" "flag" + "fmt" "io" "log/slog" "net" "os" "path/filepath" - "fmt" "github.com/edgelesssys/constellation/v2/disk-mapper/internal/diskencryption" "github.com/edgelesssys/constellation/v2/disk-mapper/internal/recoveryserver" @@ -60,12 +60,12 @@ func main() { attestVariant, err := variant.FromString(os.Getenv(constants.AttestationVariant)) if err != nil { log.With(slog.Any("error", err)).Error("Failed to parse attestation variant") - os.Exit(1) + os.Exit(1) } issuer, err := choose.Issuer(attestVariant, log) if err != nil { log.With(slog.Any("error", err)).Error("Failed to select issuer") - os.Exit(1) + os.Exit(1) } // set up metadata API @@ -78,36 +78,36 @@ func main() { diskPath, err = filepath.EvalSymlinks(awsStateDiskPath) if err != nil { log.With(slog.Any("error", err)).Error("Unable to resolve Azure state disk path") - os.Exit(1) + os.Exit(1) } metadataClient, err = awscloud.New(context.Background()) if err != nil { log.With(slog.Any("error", err)).Error("Failed to set up AWS metadata client") - os.Exit(1) + os.Exit(1) } case cloudprovider.Azure: diskPath, err = filepath.EvalSymlinks(azureStateDiskPath) if err != nil { log.With(slog.Any("error", err)).Error("Unable to resolve Azure state disk path") - os.Exit(1) + os.Exit(1) } metadataClient, err = azurecloud.New(context.Background()) if err != nil { log.With(slog.Any("error", err)).Error("Failed to set up Azure metadata client") - os.Exit(1) + os.Exit(1) } case cloudprovider.GCP: diskPath, err = filepath.EvalSymlinks(gcpStateDiskPath) if err != nil { log.With(slog.Any("error", err)).Error("Unable to resolve GCP state disk path") - os.Exit(1) + os.Exit(1) } gcpMeta, err := gcpcloud.New(context.Background()) if err != nil { log.With(slog.Any("error", err)).Error(("Failed to create GCP metadata client")) - os.Exit(1) + os.Exit(1) } defer gcpMeta.Close() metadataClient = gcpMeta @@ -117,7 +117,7 @@ func main() { metadataClient, err = openstack.New(context.Background()) if err != nil { log.With(slog.Any("error", err)).Error(("Failed to create OpenStack metadata client")) - os.Exit(1) + os.Exit(1) } case cloudprovider.QEMU: @@ -126,7 +126,7 @@ func main() { default: log.Error(fmt.Sprintf("CSP %s is not supported by Constellation", *csp)) - os.Exit(1) + os.Exit(1) } // initialize device mapper @@ -166,7 +166,7 @@ func main() { self, err = metadataClient.Self(context.Background()) if err != nil { log.With(slog.Any("error", err)).Error(("Failed to get self metadata")) - os.Exit(1) + os.Exit(1) } rejoinClient := rejoinclient.New( dialer.New(issuer, nil, &net.Dialer{}), diff --git a/disk-mapper/internal/recoveryserver/recoveryserver_test.go b/disk-mapper/internal/recoveryserver/recoveryserver_test.go index 75754d52ee..294eaa25de 100644 --- a/disk-mapper/internal/recoveryserver/recoveryserver_test.go +++ b/disk-mapper/internal/recoveryserver/recoveryserver_test.go @@ -14,13 +14,13 @@ import ( "testing" "time" - "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/edgelesssys/constellation/v2/disk-mapper/recoverproto" "github.com/edgelesssys/constellation/v2/internal/atls" "github.com/edgelesssys/constellation/v2/internal/attestation/variant" "github.com/edgelesssys/constellation/v2/internal/grpc/dialer" "github.com/edgelesssys/constellation/v2/internal/grpc/testdialer" "github.com/edgelesssys/constellation/v2/internal/kms/kms" + "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.uber.org/goleak" @@ -35,7 +35,7 @@ func TestMain(m *testing.M) { func TestServe(t *testing.T) { assert := assert.New(t) - log := slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)) + log := slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)) uuid := "uuid" server := New(atls.NewFakeIssuer(variant.Dummy{}), newStubKMS(nil, nil), log) dialer := testdialer.NewBufconnDialer() @@ -106,7 +106,7 @@ func TestRecover(t *testing.T) { ctx := context.Background() serverUUID := "uuid" - server := New(atls.NewFakeIssuer(variant.Dummy{}), tc.factory, slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil))) + server := New(atls.NewFakeIssuer(variant.Dummy{}), tc.factory, slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil))) netDialer := testdialer.NewBufconnDialer() listener := netDialer.GetListener("192.0.2.1:1234") diff --git a/disk-mapper/internal/rejoinclient/rejoinclient_test.go b/disk-mapper/internal/rejoinclient/rejoinclient_test.go index 5447061730..6c09ce7aa3 100644 --- a/disk-mapper/internal/rejoinclient/rejoinclient_test.go +++ b/disk-mapper/internal/rejoinclient/rejoinclient_test.go @@ -16,12 +16,12 @@ import ( "testing" "time" - "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/edgelesssys/constellation/v2/internal/cloud/metadata" "github.com/edgelesssys/constellation/v2/internal/constants" "github.com/edgelesssys/constellation/v2/internal/grpc/atlscredentials" "github.com/edgelesssys/constellation/v2/internal/grpc/dialer" "github.com/edgelesssys/constellation/v2/internal/grpc/testdialer" + "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/edgelesssys/constellation/v2/internal/role" "github.com/edgelesssys/constellation/v2/joinservice/joinproto" "github.com/stretchr/testify/assert" @@ -57,7 +57,7 @@ func TestStartCancel(t *testing.T) { dialer: dialer, nodeInfo: metadata.InstanceMetadata{Role: role.Worker}, metadataAPI: metaAPI, - log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), timeout: time.Second * 30, interval: time.Second, clock: clock, @@ -217,7 +217,7 @@ func TestGetJoinEndpoints(t *testing.T) { t.Run(name, func(t *testing.T) { assert := assert.New(t) - client := New(nil, tc.nodeInfo, tc.meta, slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil))) + client := New(nil, tc.nodeInfo, tc.meta, slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil))) endpoints, err := client.getJoinEndpoints() if tc.wantErr { @@ -293,7 +293,7 @@ func TestStart(t *testing.T) { }, } - client := New(dialer, tc.nodeInfo, meta, slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil))) + client := New(dialer, tc.nodeInfo, meta, slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil))) passphrase, secret := client.Start(context.Background(), "uuid") assert.Equal(diskKey, passphrase) diff --git a/disk-mapper/internal/setup/setup_test.go b/disk-mapper/internal/setup/setup_test.go index 661eea1df6..e930cd843e 100644 --- a/disk-mapper/internal/setup/setup_test.go +++ b/disk-mapper/internal/setup/setup_test.go @@ -17,10 +17,10 @@ import ( "sync" "testing" - "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/edgelesssys/constellation/v2/internal/attestation/vtpm" "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" "github.com/stretchr/testify/assert" @@ -137,7 +137,7 @@ func TestPrepareExistingDisk(t *testing.T) { } setupManager := &Manager{ - log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), csp: "test", diskPath: "disk-path", fs: fs, @@ -215,7 +215,7 @@ func TestPrepareNewDisk(t *testing.T) { assert := assert.New(t) setupManager := &Manager{ - log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), csp: "test", diskPath: "disk-path", fs: tc.fs, @@ -271,7 +271,7 @@ func TestReadMeasurementSalt(t *testing.T) { require.NoError(handler.WriteJSON("test-state.json", state, file.OptMkdirAll)) } - setupManager := New(slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), "test", "disk-path", fs, nil, nil, nil) + setupManager := New(slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), "test", "disk-path", fs, nil, nil, nil) measurementSalt, err := setupManager.readMeasurementSalt("test-state.json") if tc.wantErr { diff --git a/disk-mapper/internal/test/benchmark_test.go b/disk-mapper/internal/test/benchmark_test.go index d4a574a9df..79a6f747fa 100644 --- a/disk-mapper/internal/test/benchmark_test.go +++ b/disk-mapper/internal/test/benchmark_test.go @@ -10,9 +10,9 @@ package integration import ( "fmt" + "log/slog" "math" "testing" - "log/slog" "github.com/edgelesssys/constellation/v2/disk-mapper/internal/diskencryption" "github.com/martinjungblut/go-cryptsetup" @@ -38,7 +38,7 @@ func BenchmarkMapper(b *testing.B) { } passphrase := "benchmark" - mapper, free, err := diskencryption.New(testPath, slog.New(slog.NewPlainTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelInfo}))) + mapper, free, err := diskencryption.New(testPath, slog.New(slog.NewPlainTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelInfo}))) if err != nil { b.Fatal("Failed to create mapper:", err) } diff --git a/e2e/internal/upgrade/helm.go b/e2e/internal/upgrade/helm.go index c86db9d25b..ea1c33b3b4 100644 --- a/e2e/internal/upgrade/helm.go +++ b/e2e/internal/upgrade/helm.go @@ -21,7 +21,7 @@ import ( func servicesVersion(t *testing.T) (semver.Semver, error) { t.Helper() - log := slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)) + log := slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)) settings := cli.New() settings.KubeConfig = "constellation-admin.conf" actionConfig := &action.Configuration{} diff --git a/e2e/malicious-join/malicious-join.go b/e2e/malicious-join/malicious-join.go index 21d41ec3db..e643d6b4f0 100644 --- a/e2e/malicious-join/malicious-join.go +++ b/e2e/malicious-join/malicious-join.go @@ -89,7 +89,7 @@ func main() { } default: log.With(slog.String("testcase", name)).Error("invalid result") - os.Exit(1) + os.Exit(1) } } diff --git a/hack/bazel-deps-mirror/check.go b/hack/bazel-deps-mirror/check.go index 5b5a15f0b9..6751366f2e 100644 --- a/hack/bazel-deps-mirror/check.go +++ b/hack/bazel-deps-mirror/check.go @@ -9,9 +9,9 @@ package main import ( "context" "errors" + "fmt" "log/slog" "os" - "fmt" "github.com/edgelesssys/constellation/v2/hack/bazel-deps-mirror/internal/bazelfiles" "github.com/edgelesssys/constellation/v2/hack/bazel-deps-mirror/internal/issues" diff --git a/hack/bazel-deps-mirror/fix.go b/hack/bazel-deps-mirror/fix.go index 89cae98287..4b2c130ce8 100644 --- a/hack/bazel-deps-mirror/fix.go +++ b/hack/bazel-deps-mirror/fix.go @@ -9,9 +9,9 @@ package main import ( "context" "errors" + "fmt" "log/slog" "os" - "fmt" "github.com/bazelbuild/buildtools/build" "github.com/edgelesssys/constellation/v2/hack/bazel-deps-mirror/internal/bazelfiles" diff --git a/hack/bazel-deps-mirror/internal/mirror/mirror_test.go b/hack/bazel-deps-mirror/internal/mirror/mirror_test.go index eb10258106..a6d40fb815 100644 --- a/hack/bazel-deps-mirror/internal/mirror/mirror_test.go +++ b/hack/bazel-deps-mirror/internal/mirror/mirror_test.go @@ -11,14 +11,14 @@ import ( "context" "io" "log" + "log/slog" "net/http" "testing" - "log/slog" - "github.com/edgelesssys/constellation/v2/internal/logger" s3manager "github.com/aws/aws-sdk-go-v2/feature/s3/manager" "github.com/aws/aws-sdk-go-v2/service/s3" "github.com/aws/aws-sdk-go-v2/service/s3/types" + "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.uber.org/goleak" diff --git a/hack/bazel-deps-mirror/upgrade.go b/hack/bazel-deps-mirror/upgrade.go index cc9982d0de..ccdc132cd0 100644 --- a/hack/bazel-deps-mirror/upgrade.go +++ b/hack/bazel-deps-mirror/upgrade.go @@ -9,9 +9,9 @@ package main import ( "context" "errors" + "fmt" "log/slog" "os" - "fmt" "github.com/bazelbuild/buildtools/build" "github.com/edgelesssys/constellation/v2/hack/bazel-deps-mirror/internal/bazelfiles" diff --git a/hack/cli-k8s-compatibility/main.go b/hack/cli-k8s-compatibility/main.go index 5965df9a00..b8a82b072f 100644 --- a/hack/cli-k8s-compatibility/main.go +++ b/hack/cli-k8s-compatibility/main.go @@ -20,54 +20,54 @@ import ( ) var ( - refFlag = flag.String("ref", "", "the reference name of the image") - streamFlag = flag.String("stream", "", "the stream name of the image") - versionFlag = flag.String("version", "", "the version of the image") + refFlag = flag.String("ref", "", "the reference name of the image") + streamFlag = flag.String("stream", "", "the stream name of the image") + versionFlag = flag.String("version", "", "the version of the image") ) func main() { - log := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug})) - ctx := context.Background() + log := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug})) + ctx := context.Background() - flag.Parse() - if *refFlag == "" { - log.Error("ref must be set") - os.Exit(1) - } - if *streamFlag == "" { - log.Error("stream must be set") - os.Exit(1) - } - if *versionFlag == "" { - log.Error("version must be set") - os.Exit(1) - } + flag.Parse() + if *refFlag == "" { + log.Error("ref must be set") + os.Exit(1) + } + if *streamFlag == "" { + log.Error("stream must be set") + os.Exit(1) + } + if *versionFlag == "" { + log.Error("version must be set") + os.Exit(1) + } - cliInfo := versionsapi.CLIInfo{ - Ref: *refFlag, - Stream: *streamFlag, - Version: *versionFlag, - Kubernetes: []string{}, - } + cliInfo := versionsapi.CLIInfo{ + Ref: *refFlag, + Stream: *streamFlag, + Version: *versionFlag, + Kubernetes: []string{}, + } - for _, v := range versions.VersionConfigs { - cliInfo.Kubernetes = append(cliInfo.Kubernetes, v.ClusterVersion) - } + for _, v := range versions.VersionConfigs { + cliInfo.Kubernetes = append(cliInfo.Kubernetes, v.ClusterVersion) + } - c, cclose, err := versionsapi.NewClient(ctx, "eu-central-1", "cdn-constellation-backend", constants.CDNDefaultDistributionID, false, log) - if err != nil { - log.Error(fmt.Sprintf("creating s3 client: %s", err)) - os.Exit(1) - } - defer func() { - if err := cclose(ctx); err != nil { - log.Error(fmt.Sprintf("invalidating cache: %s", err)) - os.Exit(1) - } - }() + c, cclose, err := versionsapi.NewClient(ctx, "eu-central-1", "cdn-constellation-backend", constants.CDNDefaultDistributionID, false, log) + if err != nil { + log.Error(fmt.Sprintf("creating s3 client: %s", err)) + os.Exit(1) + } + defer func() { + if err := cclose(ctx); err != nil { + log.Error(fmt.Sprintf("invalidating cache: %s", err)) + os.Exit(1) + } + }() - if err := c.UpdateCLIInfo(ctx, cliInfo); err != nil { - log.Error(fmt.Sprintf("updating cli info: %s", err)) - os.Exit(1) - } + if err := c.UpdateCLIInfo(ctx, cliInfo); err != nil { + log.Error(fmt.Sprintf("updating cli info: %s", err)) + os.Exit(1) + } } diff --git a/hack/oci-pin/codegen.go b/hack/oci-pin/codegen.go index ac4ea297ef..c389f1eaf4 100644 --- a/hack/oci-pin/codegen.go +++ b/hack/oci-pin/codegen.go @@ -91,7 +91,7 @@ func runCodegen(cmd *cobra.Command, _ []string) error { return fmt.Errorf("rendering Go code: %w", err) } - log.Debug(fmt.Sprintf("Go code created at %q 🤖", flags.output)) + log.Debug(fmt.Sprintf("Go code created at %q 🤖", flags.output)) return nil } diff --git a/hack/qemu-metadata-api/main.go b/hack/qemu-metadata-api/main.go index 0cbc0213cf..96742b9148 100644 --- a/hack/qemu-metadata-api/main.go +++ b/hack/qemu-metadata-api/main.go @@ -9,34 +9,34 @@ SPDX-License-Identifier: AGPL-3.0-only package main import ( - "flag" - "log/slog" - "os" + "flag" + "log/slog" + "os" - "github.com/edgelesssys/constellation/v2/hack/qemu-metadata-api/server" - "github.com/edgelesssys/constellation/v2/hack/qemu-metadata-api/virtwrapper" - "libvirt.org/go/libvirt" + "github.com/edgelesssys/constellation/v2/hack/qemu-metadata-api/server" + "github.com/edgelesssys/constellation/v2/hack/qemu-metadata-api/virtwrapper" + "libvirt.org/go/libvirt" ) func main() { - bindPort := flag.String("port", "8080", "Port to bind to") - targetNetwork := flag.String("network", "constellation-network", "Name of the network in QEMU to use") - libvirtURI := flag.String("libvirt-uri", "qemu:///system", "URI of the libvirt connection") - initSecretHash := flag.String("initsecrethash", "", "brcypt hash of the init secret") - flag.Parse() - - log := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelInfo})) - - conn, err := libvirt.NewConnect(*libvirtURI) - if err != nil { - log.With(slog.Any("error", err)).Error("Failed to connect to libvirt") - os.Exit(1) - } - defer conn.Close() - - serv := server.New(log, *targetNetwork, *initSecretHash, &virtwrapper.Connect{Conn: conn}) - if err := serv.ListenAndServe(*bindPort); err != nil { - log.With(slog.Any("error", err)).Error("Failed to serve") - os.Exit(1) - } + bindPort := flag.String("port", "8080", "Port to bind to") + targetNetwork := flag.String("network", "constellation-network", "Name of the network in QEMU to use") + libvirtURI := flag.String("libvirt-uri", "qemu:///system", "URI of the libvirt connection") + initSecretHash := flag.String("initsecrethash", "", "brcypt hash of the init secret") + flag.Parse() + + log := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelInfo})) + + conn, err := libvirt.NewConnect(*libvirtURI) + if err != nil { + log.With(slog.Any("error", err)).Error("Failed to connect to libvirt") + os.Exit(1) + } + defer conn.Close() + + serv := server.New(log, *targetNetwork, *initSecretHash, &virtwrapper.Connect{Conn: conn}) + if err := serv.ListenAndServe(*bindPort); err != nil { + log.With(slog.Any("error", err)).Error("Failed to serve") + os.Exit(1) + } } diff --git a/hack/qemu-metadata-api/server/server_test.go b/hack/qemu-metadata-api/server/server_test.go index 477c02bdf0..bf88116f62 100644 --- a/hack/qemu-metadata-api/server/server_test.go +++ b/hack/qemu-metadata-api/server/server_test.go @@ -69,7 +69,7 @@ func TestListAll(t *testing.T) { t.Run(name, func(t *testing.T) { assert := assert.New(t) - server := New(slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), "test", "initSecretHash", tc.connect) + server := New(slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), "test", "initSecretHash", tc.connect) res, err := server.listAll() @@ -140,7 +140,7 @@ func TestListSelf(t *testing.T) { assert := assert.New(t) require := require.New(t) - server := New(slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), "test", "initSecretHash", tc.connect) + server := New(slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), "test", "initSecretHash", tc.connect) req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, "http://192.0.0.1/self", nil) require.NoError(err) @@ -200,7 +200,7 @@ func TestListPeers(t *testing.T) { assert := assert.New(t) require := require.New(t) - server := New(slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), "test", "initSecretHash", tc.connect) + server := New(slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), "test", "initSecretHash", tc.connect) req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, "http://192.0.0.1/peers", nil) require.NoError(err) @@ -255,7 +255,7 @@ func TestPostLog(t *testing.T) { assert := assert.New(t) require := require.New(t) - server := New(slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), "test", "initSecretHash", &stubConnect{}) + server := New(slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), "test", "initSecretHash", &stubConnect{}) req, err := http.NewRequestWithContext(context.Background(), tc.method, "http://192.0.0.1/logs", tc.message) require.NoError(err) @@ -304,7 +304,7 @@ func TestInitSecretHash(t *testing.T) { assert := assert.New(t) require := require.New(t) - server := New(slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), "test", tc.wantHash, defaultConnect) + server := New(slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), "test", tc.wantHash, defaultConnect) req, err := http.NewRequestWithContext(context.Background(), tc.method, "http://192.0.0.1/initsecrethash", nil) require.NoError(err) diff --git a/image/upload/internal/cmd/flags.go b/image/upload/internal/cmd/flags.go index 12f8849e9c..26b159b44a 100644 --- a/image/upload/internal/cmd/flags.go +++ b/image/upload/internal/cmd/flags.go @@ -272,9 +272,9 @@ func parseUplosiFlags(cmd *cobra.Command) (uplosiFlags, error) { return uplosiFlags{}, err } logLevel := slog.LevelInfo - if verbose { + if verbose { logLevel = slog.LevelDebug - } + } return uplosiFlags{ rawImage: rawImage, diff --git a/image/upload/internal/cmd/info.go b/image/upload/internal/cmd/info.go index 45b80d41a1..830e05c62a 100644 --- a/image/upload/internal/cmd/info.go +++ b/image/upload/internal/cmd/info.go @@ -50,7 +50,7 @@ func runInfo(cmd *cobra.Command, args []string) error { } log := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: flags.logLevel})) - log.Debug(fmt.Sprintf("Parsed flags: %+v", flags)) + log.Debug(fmt.Sprintf("Parsed flags: %+v", flags)) info, err := readInfoArgs(args) if err != nil { return err diff --git a/image/upload/internal/cmd/uplosi.go b/image/upload/internal/cmd/uplosi.go index f16224a0bf..12b361a4a5 100644 --- a/image/upload/internal/cmd/uplosi.go +++ b/image/upload/internal/cmd/uplosi.go @@ -58,8 +58,8 @@ func runUplosi(cmd *cobra.Command, _ []string) error { if err != nil { return err } - log := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: flags.logLevel})) - log.Debug(fmt.Sprintf("Parsed flags: %+v", flags)) + log := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: flags.logLevel})) + log.Debug(fmt.Sprintf("Parsed flags: %+v", flags)) archiveC, archiveCClose, err := archive.New(cmd.Context(), flags.region, flags.bucket, flags.distributionID, log) if err != nil { diff --git a/internal/api/versionsapi/cli/list.go b/internal/api/versionsapi/cli/list.go index 9196517e34..18620f37fd 100644 --- a/internal/api/versionsapi/cli/list.go +++ b/internal/api/versionsapi/cli/list.go @@ -11,8 +11,8 @@ import ( "encoding/json" "errors" "fmt" - "os" "log/slog" + "os" "github.com/spf13/cobra" "golang.org/x/mod/semver" @@ -43,7 +43,7 @@ func runList(cmd *cobra.Command, _ []string) (retErr error) { if err != nil { return err } - log := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: flags.logLevel})) + log := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: flags.logLevel})) log.Debug(fmt.Sprintf("Parsed flags: %+v", flags)) log.Debug("Validating flags") diff --git a/internal/attestation/aws/snp/validator_test.go b/internal/attestation/aws/snp/validator_test.go index 50261781bd..4330faf8f3 100644 --- a/internal/attestation/aws/snp/validator_test.go +++ b/internal/attestation/aws/snp/validator_test.go @@ -162,7 +162,7 @@ func TestValidateSNPReport(t *testing.T) { require.NoError(err) v := awsValidator{httpsGetter: newStubHTTPSGetter(&urlResponseMatcher{}, nil), verifier: tc.verifier, validator: tc.validator} - err = v.validate(vtpm.AttestationDocument{InstanceInfo: infoMarshalled}, ask, ark, [64]byte(hash), config.DefaultForAWSSEVSNP(), slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil))) + err = v.validate(vtpm.AttestationDocument{InstanceInfo: infoMarshalled}, ask, ark, [64]byte(hash), config.DefaultForAWSSEVSNP(), slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil))) if tc.wantErr { assert.Error(err) } else { diff --git a/internal/attestation/azure/snp/validator_test.go b/internal/attestation/azure/snp/validator_test.go index 3284c8129c..da58a9f174 100644 --- a/internal/attestation/azure/snp/validator_test.go +++ b/internal/attestation/azure/snp/validator_test.go @@ -16,10 +16,10 @@ import ( "encoding/json" "errors" "fmt" + "log/slog" "os" "regexp" "testing" - "log/slog" "github.com/edgelesssys/constellation/v2/internal/attestation" "github.com/edgelesssys/constellation/v2/internal/attestation/idkeydigest" diff --git a/internal/attestation/azure/trustedlaunch/trustedlaunch_test.go b/internal/attestation/azure/trustedlaunch/trustedlaunch_test.go index fb55e1e558..f8929604ee 100644 --- a/internal/attestation/azure/trustedlaunch/trustedlaunch_test.go +++ b/internal/attestation/azure/trustedlaunch/trustedlaunch_test.go @@ -190,7 +190,7 @@ func TestGetAttestationCert(t *testing.T) { )) require.NoError(tpm2.NVWrite(tpm, tpm2.HandleOwner, tpmAkCertIdx, "", akCert, 0)) - issuer := NewIssuer(slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil))) + issuer := NewIssuer(slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil))) issuer.hClient = newTestClient(tc.crlServer) certs, err := issuer.getAttestationCert(context.Background(), tpm, nil) diff --git a/internal/attestation/snp/snp_test.go b/internal/attestation/snp/snp_test.go index 9603d8d826..eb53a894de 100644 --- a/internal/attestation/snp/snp_test.go +++ b/internal/attestation/snp/snp_test.go @@ -10,10 +10,10 @@ import ( "crypto/x509" "encoding/hex" "fmt" + "log/slog" "regexp" "strings" "testing" - "log/slog" "github.com/edgelesssys/constellation/v2/internal/attestation/snp/testdata" "github.com/edgelesssys/constellation/v2/internal/config" diff --git a/internal/attestation/vtpm/attestation_test.go b/internal/attestation/vtpm/attestation_test.go index b4f1429745..baec89a163 100644 --- a/internal/attestation/vtpm/attestation_test.go +++ b/internal/attestation/vtpm/attestation_test.go @@ -13,9 +13,9 @@ import ( "errors" "fmt" "io" + "log/slog" "os" "testing" - "log/slog" tpmclient "github.com/google/go-tpm-tools/client" "github.com/google/go-tpm-tools/proto/attest" diff --git a/internal/constellation/apply_test.go b/internal/constellation/apply_test.go index 1466dcaa28..fb943d0594 100644 --- a/internal/constellation/apply_test.go +++ b/internal/constellation/apply_test.go @@ -8,8 +8,8 @@ package constellation import ( "context" + "log/slog" "testing" - "log/slog" "github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider" "github.com/edgelesssys/constellation/v2/internal/crypto" diff --git a/internal/constellation/applyinit_test.go b/internal/constellation/applyinit_test.go index 14bd02e6e3..f05c871172 100644 --- a/internal/constellation/applyinit_test.go +++ b/internal/constellation/applyinit_test.go @@ -12,11 +12,11 @@ import ( "encoding/json" "errors" "io" + "log/slog" "net" "strconv" "testing" "time" - "log/slog" "github.com/edgelesssys/constellation/v2/bootstrapper/initproto" "github.com/edgelesssys/constellation/v2/internal/atls" diff --git a/internal/constellation/helm/actionfactory_test.go b/internal/constellation/helm/actionfactory_test.go index 8dc617d5e0..33527caf8f 100644 --- a/internal/constellation/helm/actionfactory_test.go +++ b/internal/constellation/helm/actionfactory_test.go @@ -241,7 +241,7 @@ func TestAppendNewAction(t *testing.T) { assert := assert.New(t) actions := []applyAction{} - actionFactory := newActionFactory(nil, tc.lister, &action.Configuration{}, slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil))) + actionFactory := newActionFactory(nil, tc.lister, &action.Configuration{}, slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil))) err := actionFactory.appendNewAction(tc.release, tc.configTargetVersion, tc.force, tc.allowDestructive, time.Second, &actions) if tc.wantErr { diff --git a/internal/constellation/helm/helm_test.go b/internal/constellation/helm/helm_test.go index 45f1173d66..4283579349 100644 --- a/internal/constellation/helm/helm_test.go +++ b/internal/constellation/helm/helm_test.go @@ -174,7 +174,7 @@ func TestHelmApply(t *testing.T) { }, } - log := slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)) + log := slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)) options := Options{ DeployCSIDriver: true, Conformance: false, diff --git a/internal/constellation/helm/retryaction_test.go b/internal/constellation/helm/retryaction_test.go index c228e10e1c..7b51979d1c 100644 --- a/internal/constellation/helm/retryaction_test.go +++ b/internal/constellation/helm/retryaction_test.go @@ -65,7 +65,7 @@ func TestRetryApply(t *testing.T) { t.Run(name, func(t *testing.T) { assert := assert.New(t) - err := retryApply(context.Background(), tc.applier, time.Millisecond, slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil))) + err := retryApply(context.Background(), tc.applier, time.Millisecond, slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil))) if tc.wantErr { assert.Error(err) } else { diff --git a/internal/constellation/kubecmd/kubecmd_test.go b/internal/constellation/kubecmd/kubecmd_test.go index 805bf245bd..bc7fde6629 100644 --- a/internal/constellation/kubecmd/kubecmd_test.go +++ b/internal/constellation/kubecmd/kubecmd_test.go @@ -11,10 +11,10 @@ import ( "encoding/json" "errors" "fmt" + "log/slog" "strings" "testing" "time" - "log/slog" "github.com/edgelesssys/constellation/v2/internal/attestation/measurements" "github.com/edgelesssys/constellation/v2/internal/compatibility" diff --git a/internal/logger/cmdline.go b/internal/logger/cmdline.go index 85dfb41ab4..e63b811e65 100644 --- a/internal/logger/cmdline.go +++ b/internal/logger/cmdline.go @@ -7,7 +7,7 @@ SPDX-License-Identifier: AGPL-3.0-only package logger import ( - "log/slog" + "log/slog" ) // CmdLineVerbosityDescription explains numeric log levels. diff --git a/internal/logger/grpclogger.go b/internal/logger/grpclogger.go index 8116626d2f..86589537db 100644 --- a/internal/logger/grpclogger.go +++ b/internal/logger/grpclogger.go @@ -19,7 +19,7 @@ import ( func replaceGRPCLogger(log *slog.Logger) { gl := &grpcLogger{ - logger: log.With(slog.String("system", "grpc"), slog.Bool("grpc_log", true)), + logger: log.With(slog.String("system", "grpc"), slog.Bool("grpc_log", true)), verbosity: 0, } grpclog.SetLoggerV2(gl) @@ -31,90 +31,90 @@ type grpcLogger struct { } func (l *grpcLogger) Info(args ...interface{}) { - var pcs [1]uintptr - runtime.Callers(2, pcs[:]) - r := slog.NewRecord(time.Now(), slog.LevelInfo, fmt.Sprint(args...), pcs[0]) - _ = l.logger.Handler().Handle(context.Background(), r) + var pcs [1]uintptr + runtime.Callers(2, pcs[:]) + r := slog.NewRecord(time.Now(), slog.LevelInfo, fmt.Sprint(args...), pcs[0]) + _ = l.logger.Handler().Handle(context.Background(), r) } func (l *grpcLogger) Infoln(args ...interface{}) { var pcs [1]uintptr - runtime.Callers(2, pcs[:]) - r := slog.NewRecord(time.Now(), slog.LevelInfo, fmt.Sprint(args...), pcs[0]) - _ = l.logger.Handler().Handle(context.Background(), r) + runtime.Callers(2, pcs[:]) + r := slog.NewRecord(time.Now(), slog.LevelInfo, fmt.Sprint(args...), pcs[0]) + _ = l.logger.Handler().Handle(context.Background(), r) } func (l *grpcLogger) Infof(format string, args ...interface{}) { var pcs [1]uintptr - runtime.Callers(2, pcs[:]) - r := slog.NewRecord(time.Now(), slog.LevelInfo, fmt.Sprintf(format, args...), pcs[0]) - _ = l.logger.Handler().Handle(context.Background(), r) + runtime.Callers(2, pcs[:]) + r := slog.NewRecord(time.Now(), slog.LevelInfo, fmt.Sprintf(format, args...), pcs[0]) + _ = l.logger.Handler().Handle(context.Background(), r) } func (l *grpcLogger) Warning(args ...interface{}) { var pcs [1]uintptr - runtime.Callers(2, pcs[:]) - r := slog.NewRecord(time.Now(), slog.LevelWarn, fmt.Sprint(args...), pcs[0]) - _ = l.logger.Handler().Handle(context.Background(), r) + runtime.Callers(2, pcs[:]) + r := slog.NewRecord(time.Now(), slog.LevelWarn, fmt.Sprint(args...), pcs[0]) + _ = l.logger.Handler().Handle(context.Background(), r) } func (l *grpcLogger) Warningln(args ...interface{}) { var pcs [1]uintptr - runtime.Callers(2, pcs[:]) - r := slog.NewRecord(time.Now(), slog.LevelWarn, fmt.Sprint(args...), pcs[0]) - _ = l.logger.Handler().Handle(context.Background(), r) + runtime.Callers(2, pcs[:]) + r := slog.NewRecord(time.Now(), slog.LevelWarn, fmt.Sprint(args...), pcs[0]) + _ = l.logger.Handler().Handle(context.Background(), r) } func (l *grpcLogger) Warningf(format string, args ...interface{}) { var pcs [1]uintptr - runtime.Callers(2, pcs[:]) - r := slog.NewRecord(time.Now(), slog.LevelWarn, fmt.Sprintf(format, args...), pcs[0]) - _ = l.logger.Handler().Handle(context.Background(), r) + runtime.Callers(2, pcs[:]) + r := slog.NewRecord(time.Now(), slog.LevelWarn, fmt.Sprintf(format, args...), pcs[0]) + _ = l.logger.Handler().Handle(context.Background(), r) } func (l *grpcLogger) Error(args ...interface{}) { var pcs [1]uintptr - runtime.Callers(2, pcs[:]) - r := slog.NewRecord(time.Now(), slog.LevelError, fmt.Sprint(args...), pcs[0]) - _ = l.logger.Handler().Handle(context.Background(), r) + runtime.Callers(2, pcs[:]) + r := slog.NewRecord(time.Now(), slog.LevelError, fmt.Sprint(args...), pcs[0]) + _ = l.logger.Handler().Handle(context.Background(), r) } func (l *grpcLogger) Errorln(args ...interface{}) { var pcs [1]uintptr - runtime.Callers(2, pcs[:]) - r := slog.NewRecord(time.Now(), slog.LevelError, fmt.Sprint(args...), pcs[0]) - _ = l.logger.Handler().Handle(context.Background(), r) + runtime.Callers(2, pcs[:]) + r := slog.NewRecord(time.Now(), slog.LevelError, fmt.Sprint(args...), pcs[0]) + _ = l.logger.Handler().Handle(context.Background(), r) } func (l *grpcLogger) Errorf(format string, args ...interface{}) { var pcs [1]uintptr - runtime.Callers(2, pcs[:]) - r := slog.NewRecord(time.Now(), slog.LevelError, fmt.Sprintf(format, args...), pcs[0]) - _ = l.logger.Handler().Handle(context.Background(), r) + runtime.Callers(2, pcs[:]) + r := slog.NewRecord(time.Now(), slog.LevelError, fmt.Sprintf(format, args...), pcs[0]) + _ = l.logger.Handler().Handle(context.Background(), r) } func (l *grpcLogger) Fatal(args ...interface{}) { var pcs [1]uintptr - runtime.Callers(2, pcs[:]) - r := slog.NewRecord(time.Now(), slog.LevelError, fmt.Sprint(args...), pcs[0]) - _ = l.logger.Handler().Handle(context.Background(), r) - os.Exit(1) + runtime.Callers(2, pcs[:]) + r := slog.NewRecord(time.Now(), slog.LevelError, fmt.Sprint(args...), pcs[0]) + _ = l.logger.Handler().Handle(context.Background(), r) + os.Exit(1) } func (l *grpcLogger) Fatalln(args ...interface{}) { var pcs [1]uintptr - runtime.Callers(2, pcs[:]) - r := slog.NewRecord(time.Now(), slog.LevelError, fmt.Sprint(args...), pcs[0]) - _ = l.logger.Handler().Handle(context.Background(), r) - os.Exit(1) + runtime.Callers(2, pcs[:]) + r := slog.NewRecord(time.Now(), slog.LevelError, fmt.Sprint(args...), pcs[0]) + _ = l.logger.Handler().Handle(context.Background(), r) + os.Exit(1) } func (l *grpcLogger) Fatalf(format string, args ...interface{}) { var pcs [1]uintptr - runtime.Callers(2, pcs[:]) - r := slog.NewRecord(time.Now(), slog.LevelError, fmt.Sprintf(format, args...), pcs[0]) - _ = l.logger.Handler().Handle(context.Background(), r) - os.Exit(1) + runtime.Callers(2, pcs[:]) + r := slog.NewRecord(time.Now(), slog.LevelError, fmt.Sprintf(format, args...), pcs[0]) + _ = l.logger.Handler().Handle(context.Background(), r) + os.Exit(1) } func (l *grpcLogger) V(level int) bool { diff --git a/internal/logger/log.go b/internal/logger/log.go index ca326270cc..937ee9a968 100644 --- a/internal/logger/log.go +++ b/internal/logger/log.go @@ -87,23 +87,23 @@ func middlewareLogger(l *slog.Logger) logging.Logger { } } - var pcs [1]uintptr - runtime.Callers(2, pcs[:]) // skip [Callers, LoggerFunc] - r := slog.Record{} + var pcs [1]uintptr + runtime.Callers(2, pcs[:]) // skip [Callers, LoggerFunc] + r := slog.Record{} switch lvl { case logging.LevelDebug: - r = slog.NewRecord(time.Now(), slog.LevelDebug, fmt.Sprintf(msg, fields...), pcs[0]) + r = slog.NewRecord(time.Now(), slog.LevelDebug, fmt.Sprintf(msg, fields...), pcs[0]) case logging.LevelInfo: - r = slog.NewRecord(time.Now(), slog.LevelInfo, fmt.Sprintf(msg, fields...), pcs[0]) + r = slog.NewRecord(time.Now(), slog.LevelInfo, fmt.Sprintf(msg, fields...), pcs[0]) case logging.LevelWarn: - r = slog.NewRecord(time.Now(), slog.LevelWarn, fmt.Sprintf(msg, fields...), pcs[0]) + r = slog.NewRecord(time.Now(), slog.LevelWarn, fmt.Sprintf(msg, fields...), pcs[0]) case logging.LevelError: - r = slog.NewRecord(time.Now(), slog.LevelError, fmt.Sprintf(msg, fields...), pcs[0]) + r = slog.NewRecord(time.Now(), slog.LevelError, fmt.Sprintf(msg, fields...), pcs[0]) default: panic(fmt.Sprintf("unknown level %v", lvl)) } - _ = l.Handler().Handle(context.Background(), r) + _ = l.Handler().Handle(context.Background(), r) }) } @@ -154,11 +154,11 @@ func (h *LevelHandler) Handler() slog.Handler { // TestWriter is a writer to a testing.T used in tests for logging with slog. type TestWriter struct { - T *testing.T + T *testing.T } func (t TestWriter) Write(p []byte) (int, error) { - t.T.Helper() - t.T.Log(string(p)) - return len(p), nil + t.T.Helper() + t.T.Log(string(p)) + return len(p), nil } diff --git a/internal/osimage/archive/archive.go b/internal/osimage/archive/archive.go index 8ea2841821..f42b48e4c1 100644 --- a/internal/osimage/archive/archive.go +++ b/internal/osimage/archive/archive.go @@ -8,8 +8,8 @@ SPDX-License-Identifier: AGPL-3.0-only package archive import ( - "fmt" "context" + "fmt" "io" "log/slog" "net/url" diff --git a/internal/osimage/nop/nop.go b/internal/osimage/nop/nop.go index d28c0aa9b0..5618acf038 100644 --- a/internal/osimage/nop/nop.go +++ b/internal/osimage/nop/nop.go @@ -9,8 +9,8 @@ package nop import ( "context" + "fmt" "log/slog" - "fmt" "github.com/edgelesssys/constellation/v2/internal/api/versionsapi" "github.com/edgelesssys/constellation/v2/internal/osimage" diff --git a/internal/staticupload/staticupload_test.go b/internal/staticupload/staticupload_test.go index 0c6ecdd3ab..38d5d06671 100644 --- a/internal/staticupload/staticupload_test.go +++ b/internal/staticupload/staticupload_test.go @@ -107,7 +107,7 @@ func TestUpload(t *testing.T) { distributionID: "test-distribution-id", cacheInvalidationStrategy: tc.cacheInvalidationStrategy, cacheInvalidationWaitTimeout: tc.cacheInvalidationWaitTimeout, - logger: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + logger: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), } _, err := client.Upload(context.Background(), tc.in) @@ -219,7 +219,7 @@ func TestDeleteObject(t *testing.T) { distributionID: "test-distribution-id", cacheInvalidationStrategy: tc.cacheInvalidationStrategy, cacheInvalidationWaitTimeout: tc.cacheInvalidationWaitTimeout, - logger: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + logger: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), } _, err := client.DeleteObject(context.Background(), newObjectInput(tc.nilInput, tc.nilKey)) @@ -258,7 +258,7 @@ func TestDeleteObject(t *testing.T) { distributionID: "test-distribution-id", cacheInvalidationStrategy: tc.cacheInvalidationStrategy, cacheInvalidationWaitTimeout: tc.cacheInvalidationWaitTimeout, - logger: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + logger: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), } _, err := client.DeleteObjects(context.Background(), newObjectsInput(tc.nilInput, tc.nilKey)) @@ -400,7 +400,7 @@ func TestFlush(t *testing.T) { cacheInvalidationWaitTimeout: tc.cacheInvalidationWaitTimeout, dirtyKeys: tc.dirtyKeys, invalidationIDs: tc.invalidationIDs, - logger: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + logger: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), } err := client.Flush(context.Background()) @@ -438,7 +438,7 @@ func TestConcurrency(t *testing.T) { uploadClient: uploadClient, distributionID: "test-distribution-id", cacheInvalidationWaitTimeout: 50 * time.Millisecond, - logger: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + logger: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), } var wg sync.WaitGroup diff --git a/internal/verify/verify_test.go b/internal/verify/verify_test.go index 0a4d9a45cc..738189b908 100644 --- a/internal/verify/verify_test.go +++ b/internal/verify/verify_test.go @@ -6,9 +6,9 @@ SPDX-License-Identifier: AGPL-3.0-only package verify import ( + "log/slog" "strings" "testing" - "log/slog" "github.com/edgelesssys/constellation/v2/internal/attestation/snp/testdata" "github.com/edgelesssys/constellation/v2/internal/logger" diff --git a/joinservice/cmd/main.go b/joinservice/cmd/main.go index 26670c27c0..1709db3706 100644 --- a/joinservice/cmd/main.go +++ b/joinservice/cmd/main.go @@ -10,13 +10,13 @@ import ( "context" "errors" "flag" + "fmt" "log/slog" "net" "os" "path/filepath" "strconv" "time" - "fmt" "github.com/edgelesssys/constellation/v2/internal/atls" "github.com/edgelesssys/constellation/v2/internal/attestation/variant" @@ -51,7 +51,7 @@ func main() { verbosity := flag.Int("v", 0, logger.CmdLineVerbosityDescription) flag.Parse() - log := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: logger.VerbosityFromInt(*verbosity)})) + log := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: logger.VerbosityFromInt(*verbosity)})) log.With( slog.String("version", constants.BinaryVersion().String()), slog.String("cloudProvider", *provider), @@ -63,27 +63,27 @@ func main() { kubeClient, err := kubernetes.New() if err != nil { log.With(slog.Any("error", err)).Error("Failed to create Kubernetes client") - os.Exit(1) + os.Exit(1) } attVariant, err := variant.FromString(*attestationVariant) if err != nil { log.With(slog.Any("error", err)).Error("Failed to parse attestation variant") - os.Exit(1) + os.Exit(1) } certCacheClient := certcache.NewClient(log.WithGroup("certcache"), kubeClient, attVariant) cachedCerts, err := certCacheClient.CreateCertChainCache(context.Background()) if err != nil { log.With(slog.Any("error", err)).Error("Failed to create certificate chain cache") - os.Exit(1) + os.Exit(1) } validator, err := watcher.NewValidator(log.WithGroup("validator"), attVariant, handler, cachedCerts) if err != nil { flag.Usage() log.With(slog.Any("error", err)).Error("Failed to create validator") - os.Exit(1) + os.Exit(1) } creds := atlscredentials.New(nil, []atls.Validator{validator}) @@ -94,7 +94,7 @@ func main() { vpcIP, err := getVPCIP(vpcCtx, *provider) if err != nil { log.With(slog.Any("error", err)).Error("Failed to get IP in VPC") - os.Exit(1) + os.Exit(1) } apiServerEndpoint := net.JoinHostPort(vpcIP, strconv.Itoa(constants.KubernetesPort)) kubeadm, err := kubeadm.New(apiServerEndpoint, log.WithGroup("kubeadm")) @@ -106,7 +106,7 @@ func main() { measurementSalt, err := handler.Read(filepath.Join(constants.ServiceBasePath, constants.MeasurementSaltFilename)) if err != nil { log.With(slog.Any("error", err)).Error("Failed to read measurement salt") - os.Exit(1) + os.Exit(1) } server, err := server.New( @@ -119,13 +119,13 @@ func main() { ) if err != nil { log.With(slog.Any("error", err)).Error("Failed to create server") - os.Exit(1) + os.Exit(1) } watcher, err := watcher.New(log.WithGroup("fileWatcher"), validator) if err != nil { log.With(slog.Any("error", err)).Error("Failed to create watcher for measurements updates") - os.Exit(1) + os.Exit(1) } defer watcher.Close() @@ -133,13 +133,13 @@ func main() { log.Info(fmt.Sprintf("starting file watcher for measurements file %s", filepath.Join(constants.ServiceBasePath, constants.AttestationConfigFilename))) if err := watcher.Watch(filepath.Join(constants.ServiceBasePath, constants.AttestationConfigFilename)); err != nil { log.With(slog.Any("error", err)).Error("Failed to watch measurements file") - os.Exit(1) + os.Exit(1) } }() if err := server.Run(creds, strconv.Itoa(constants.JoinServicePort)); err != nil { log.With(slog.Any("error", err)).Error("Failed to run server") - os.Exit(1) + os.Exit(1) } } diff --git a/joinservice/internal/certcache/amdkds/amdkds_test.go b/joinservice/internal/certcache/amdkds/amdkds_test.go index 7658eb3c8b..65dd034086 100644 --- a/joinservice/internal/certcache/amdkds/amdkds_test.go +++ b/joinservice/internal/certcache/amdkds/amdkds_test.go @@ -7,9 +7,9 @@ SPDX-License-Identifier: AGPL-3.0-only package amdkds import ( - "fmt" + "fmt" + "log/slog" "testing" - "log/slog" "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/edgelesssys/constellation/v2/joinservice/internal/certcache/amdkds/testdata" diff --git a/joinservice/internal/certcache/certcache_test.go b/joinservice/internal/certcache/certcache_test.go index 05059a9496..0baa9b1f41 100644 --- a/joinservice/internal/certcache/certcache_test.go +++ b/joinservice/internal/certcache/certcache_test.go @@ -121,7 +121,7 @@ func TestCreateCertChainCache(t *testing.T) { c := &Client{ attVariant: variant.Dummy{}, - log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), kubeClient: tc.kubeClient, kdsClient: tc.kdsClient, } @@ -207,7 +207,7 @@ func TestGetCertChainCache(t *testing.T) { ctx := context.Background() - c := NewClient(slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), tc.kubeClient, variant.Dummy{}) + c := NewClient(slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), tc.kubeClient, variant.Dummy{}) ask, ark, err := c.getCertChainCache(ctx) if tc.wantErr { diff --git a/joinservice/internal/kms/kms_test.go b/joinservice/internal/kms/kms_test.go index d6f9a78913..740b284188 100644 --- a/joinservice/internal/kms/kms_test.go +++ b/joinservice/internal/kms/kms_test.go @@ -55,7 +55,7 @@ func TestGetDataKey(t *testing.T) { defer listener.Close() client := New( - slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), listener.Addr().String(), ) diff --git a/joinservice/internal/kubeadm/kubeadm_test.go b/joinservice/internal/kubeadm/kubeadm_test.go index f88da4a254..580068a531 100644 --- a/joinservice/internal/kubeadm/kubeadm_test.go +++ b/joinservice/internal/kubeadm/kubeadm_test.go @@ -86,7 +86,7 @@ kind: Config`, require := require.New(t) client := &Kubeadm{ - log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), file: file.NewHandler(afero.NewMemMapFs()), client: fake.NewSimpleClientset(), } @@ -150,7 +150,7 @@ func TestGetControlPlaneCertificatesAndKeys(t *testing.T) { require := require.New(t) client := &Kubeadm{ - log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), file: file.NewHandler(afero.NewMemMapFs()), client: fake.NewSimpleClientset(), } diff --git a/joinservice/internal/kubernetesca/kubernetesca_test.go b/joinservice/internal/kubernetesca/kubernetesca_test.go index b76d68ad7b..636abe8b72 100644 --- a/joinservice/internal/kubernetesca/kubernetesca_test.go +++ b/joinservice/internal/kubernetesca/kubernetesca_test.go @@ -186,7 +186,7 @@ Q29uc3RlbGxhdGlvbg== } ca := New( - slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), fileHandler, ) diff --git a/joinservice/internal/server/server_test.go b/joinservice/internal/server/server_test.go index 6d9457ba88..76340407b1 100644 --- a/joinservice/internal/server/server_test.go +++ b/joinservice/internal/server/server_test.go @@ -13,8 +13,8 @@ import ( "testing" "time" - "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/edgelesssys/constellation/v2/internal/attestation" + "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/edgelesssys/constellation/v2/internal/versions/components" "github.com/edgelesssys/constellation/v2/joinservice/joinproto" "github.com/stretchr/testify/assert" @@ -163,7 +163,7 @@ func TestIssueJoinTicket(t *testing.T) { joinTokenGetter: tc.kubeadm, dataKeyGetter: tc.kms, kubeClient: &tc.kubeClient, - log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), } req := &joinproto.IssueJoinTicketRequest{ @@ -228,7 +228,7 @@ func TestIssueRejoinTicker(t *testing.T) { ca: stubCA{}, joinTokenGetter: stubTokenGetter{}, dataKeyGetter: tc.keyGetter, - log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), } req := &joinproto.IssueRejoinTicketRequest{ diff --git a/joinservice/internal/watcher/validator.go b/joinservice/internal/watcher/validator.go index 85b65b133f..6bf43635ee 100644 --- a/joinservice/internal/watcher/validator.go +++ b/joinservice/internal/watcher/validator.go @@ -11,9 +11,9 @@ import ( "crypto/x509" "encoding/asn1" "fmt" + "log/slog" "path/filepath" "sync" - "log/slog" "github.com/edgelesssys/constellation/v2/internal/atls" "github.com/edgelesssys/constellation/v2/internal/attestation/choose" diff --git a/joinservice/internal/watcher/validator_test.go b/joinservice/internal/watcher/validator_test.go index e69b36b5a3..37fd5d019b 100644 --- a/joinservice/internal/watcher/validator_test.go +++ b/joinservice/internal/watcher/validator_test.go @@ -87,7 +87,7 @@ func TestNewUpdateableValidator(t *testing.T) { } _, err := NewValidator( - slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), tc.variant, handler, tc.snpCerts, @@ -118,7 +118,7 @@ func TestUpdate(t *testing.T) { // create server validator := &Updatable{ - log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), variant: variant.Dummy{}, fileHandler: handler, } @@ -178,7 +178,7 @@ func TestOIDConcurrency(t *testing.T) { // create server validator := &Updatable{ - log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), variant: variant.Dummy{}, fileHandler: handler, } @@ -207,7 +207,7 @@ func TestUpdateConcurrency(t *testing.T) { handler := file.NewHandler(afero.NewMemMapFs()) validator := &Updatable{ - log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), fileHandler: handler, variant: variant.Dummy{}, } diff --git a/joinservice/internal/watcher/watcher_test.go b/joinservice/internal/watcher/watcher_test.go index 0562b9111f..a605a1f278 100644 --- a/joinservice/internal/watcher/watcher_test.go +++ b/joinservice/internal/watcher/watcher_test.go @@ -107,7 +107,7 @@ func TestWatcher(t *testing.T) { assert := assert.New(t) watcher := &FileWatcher{ - log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), updater: tc.updater, watcher: tc.watcher, done: make(chan struct{}, 1), diff --git a/keyservice/cmd/main.go b/keyservice/cmd/main.go index ed45618328..1031d35c2e 100644 --- a/keyservice/cmd/main.go +++ b/keyservice/cmd/main.go @@ -10,12 +10,12 @@ import ( "context" "errors" "flag" + "fmt" "log/slog" "os" "path/filepath" "strconv" "time" - "fmt" "github.com/edgelesssys/constellation/v2/internal/constants" "github.com/edgelesssys/constellation/v2/internal/crypto" @@ -44,20 +44,20 @@ func main() { masterKey, err := file.Read(*masterSecretPath) if err != nil { log.With(slog.Any("error", err)).Error("Failed to read master secret") - os.Exit(1) + os.Exit(1) } if len(masterKey) < 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) + os.Exit(1) } salt, err := file.Read(*saltPath) if err != nil { log.With(slog.Any("error", err)).Error("Failed to read salt") - os.Exit(1) + os.Exit(1) } if len(salt) < crypto.RNGLengthDefault { 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) + os.Exit(1) } masterSecret := uri.MasterSecret{Key: masterKey, Salt: salt} @@ -67,12 +67,12 @@ func main() { conKMS, err := setup.KMS(ctx, uri.NoStoreURI, masterSecret.EncodeToURI()) if err != nil { log.With(slog.Any("error", err)).Error("Failed to setup KMS") - os.Exit(1) + os.Exit(1) } defer conKMS.Close() 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) + os.Exit(1) } } diff --git a/keyservice/internal/server/server_test.go b/keyservice/internal/server/server_test.go index e310bbb2a9..6320d04878 100644 --- a/keyservice/internal/server/server_test.go +++ b/keyservice/internal/server/server_test.go @@ -28,7 +28,7 @@ func TestGetDataKey(t *testing.T) { assert := assert.New(t) require := require.New(t) - log := slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)) + log := slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)) kms := &stubKMS{derivedKey: []byte{0x0, 0x1, 0x2, 0x3, 0x4, 0x5}} api := New(log, kms) diff --git a/measurement-reader/cmd/main.go b/measurement-reader/cmd/main.go index f3b483b328..3f0e449017 100644 --- a/measurement-reader/cmd/main.go +++ b/measurement-reader/cmd/main.go @@ -24,7 +24,7 @@ func main() { attestationVariant, err := variant.FromString(variantString) if err != nil { log.With(slog.Any("error", err)).Error("Failed to parse attestation variant") - os.Exit(1) + os.Exit(1) } var m []sorted.Measurement @@ -33,17 +33,17 @@ func main() { m, err = tpm.Measurements() if err != nil { log.With(slog.Any("error", err)).Error("Failed to read TPM measurements") - os.Exit(1) + os.Exit(1) } case variant.QEMUTDX{}: m, err = tdx.Measurements() if err != nil { log.With(slog.Any("error", err)).Error("Failed to read Intel TDX measurements") - os.Exit(1) + os.Exit(1) } default: log.With(slog.String("attestationVariant", variantString)).Error("Unsupported attestation variant") - os.Exit(1) + os.Exit(1) } fmt.Println("Measurements:") diff --git a/s3proxy/internal/kms/kms_test.go b/s3proxy/internal/kms/kms_test.go index d6f9a78913..740b284188 100644 --- a/s3proxy/internal/kms/kms_test.go +++ b/s3proxy/internal/kms/kms_test.go @@ -55,7 +55,7 @@ func TestGetDataKey(t *testing.T) { defer listener.Close() client := New( - slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), listener.Addr().String(), ) diff --git a/upgrade-agent/cmd/main.go b/upgrade-agent/cmd/main.go index 29945451d7..586d6d2259 100644 --- a/upgrade-agent/cmd/main.go +++ b/upgrade-agent/cmd/main.go @@ -39,12 +39,12 @@ func main() { server, err := server.New(log, handler) if err != nil { log.With(slog.Any("error", err)).Error("Failed to create update server") - os.Exit(1) + os.Exit(1) } err = server.Run(protocol, constants.UpgradeAgentSocketPath) if err != nil { log.With(slog.Any("error", err)).Error("Failed to start update server") - os.Exit(1) + os.Exit(1) } } diff --git a/verify/cmd/main.go b/verify/cmd/main.go index 7f2ff9f317..2519469b51 100644 --- a/verify/cmd/main.go +++ b/verify/cmd/main.go @@ -7,56 +7,56 @@ SPDX-License-Identifier: AGPL-3.0-only package main import ( - "flag" - "log/slog" - "net" - "os" - "strconv" - - "github.com/edgelesssys/constellation/v2/internal/attestation/choose" - "github.com/edgelesssys/constellation/v2/internal/attestation/variant" - "github.com/edgelesssys/constellation/v2/internal/constants" - "github.com/edgelesssys/constellation/v2/internal/logger" - "github.com/edgelesssys/constellation/v2/verify/server" + "flag" + "log/slog" + "net" + "os" + "strconv" + + "github.com/edgelesssys/constellation/v2/internal/attestation/choose" + "github.com/edgelesssys/constellation/v2/internal/attestation/variant" + "github.com/edgelesssys/constellation/v2/internal/constants" + "github.com/edgelesssys/constellation/v2/internal/logger" + "github.com/edgelesssys/constellation/v2/verify/server" ) func main() { - attestationVariant := flag.String("attestation-variant", "", "attestation variant to use for aTLS connections") - verbosity := flag.Int("v", 0, logger.CmdLineVerbosityDescription) - - flag.Parse() - log := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: logger.VerbosityFromInt(*verbosity)})) - - log.With(slog.String("version", constants.BinaryVersion().String()), slog.String("attestationVariant", *attestationVariant)). - Info("Constellation Verification Service") - - variant, err := variant.FromString(*attestationVariant) - if err != nil { - log.With(slog.Any("error", err)).Error("Failed to parse attestation variant") - os.Exit(1) - } - issuer, err := choose.Issuer(variant, log.WithGroup("issuer")) - if err != nil { - log.With(slog.Any("error", err)).Error("Failed to create issuer") - os.Exit(1) - } - - server := server.New(log.WithGroup("server"), issuer) - httpListener, err := net.Listen("tcp", net.JoinHostPort("", strconv.Itoa(constants.VerifyServicePortHTTP))) - if err != nil { - log.With(slog.Any("error", err), slog.Int("port", constants.VerifyServicePortHTTP)). - Error("Failed to listen") - os.Exit(1) - } - grpcListener, err := net.Listen("tcp", net.JoinHostPort("", strconv.Itoa(constants.VerifyServicePortGRPC))) - if err != nil { - log.With(slog.Any("error", err), slog.Int("port", constants.VerifyServicePortGRPC)). - Error("Failed to listen") - os.Exit(1) - } - - if err := server.Run(httpListener, grpcListener); err != nil { - log.With(slog.Any("error", err)).Error("Failed to run server") - os.Exit(1) - } + attestationVariant := flag.String("attestation-variant", "", "attestation variant to use for aTLS connections") + verbosity := flag.Int("v", 0, logger.CmdLineVerbosityDescription) + + flag.Parse() + log := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: logger.VerbosityFromInt(*verbosity)})) + + log.With(slog.String("version", constants.BinaryVersion().String()), slog.String("attestationVariant", *attestationVariant)). + Info("Constellation Verification Service") + + variant, err := variant.FromString(*attestationVariant) + if err != nil { + log.With(slog.Any("error", err)).Error("Failed to parse attestation variant") + os.Exit(1) + } + issuer, err := choose.Issuer(variant, log.WithGroup("issuer")) + if err != nil { + log.With(slog.Any("error", err)).Error("Failed to create issuer") + os.Exit(1) + } + + server := server.New(log.WithGroup("server"), issuer) + httpListener, err := net.Listen("tcp", net.JoinHostPort("", strconv.Itoa(constants.VerifyServicePortHTTP))) + if err != nil { + log.With(slog.Any("error", err), slog.Int("port", constants.VerifyServicePortHTTP)). + Error("Failed to listen") + os.Exit(1) + } + grpcListener, err := net.Listen("tcp", net.JoinHostPort("", strconv.Itoa(constants.VerifyServicePortGRPC))) + if err != nil { + log.With(slog.Any("error", err), slog.Int("port", constants.VerifyServicePortGRPC)). + Error("Failed to listen") + os.Exit(1) + } + + if err := server.Run(httpListener, grpcListener); err != nil { + log.With(slog.Any("error", err)).Error("Failed to run server") + os.Exit(1) + } } diff --git a/verify/server/server_test.go b/verify/server/server_test.go index c02d7edfa4..3a36b7949a 100644 --- a/verify/server/server_test.go +++ b/verify/server/server_test.go @@ -20,8 +20,8 @@ import ( "testing" "github.com/edgelesssys/constellation/v2/internal/grpc/testdialer" + "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/edgelesssys/constellation/v2/verify/verifyproto" - "github.com/edgelesssys/constellation/v2/internal/logger" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.uber.org/goleak" @@ -38,7 +38,7 @@ func TestRun(t *testing.T) { var err error var wg sync.WaitGroup s := &Server{ - log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), issuer: stubIssuer{attestation: []byte("quote")}, } @@ -105,7 +105,7 @@ func TestGetAttestationGRPC(t *testing.T) { assert := assert.New(t) server := &Server{ - log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), issuer: tc.issuer, } @@ -158,7 +158,7 @@ func TestGetAttestationHTTP(t *testing.T) { require := require.New(t) server := &Server{ - log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), + log: slog.New(slog.NewTextHandler(logger.TestWriter{T: t}, nil)), issuer: tc.issuer, }