Skip to content

Commit

Permalink
added .String() to measurements.M
Browse files Browse the repository at this point in the history
  • Loading branch information
miampf committed Apr 3, 2024
1 parent 8924c9f commit cb11701
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 17 deletions.
7 changes: 1 addition & 6 deletions cli/internal/cmd/configfetchmeasurements.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package cmd

import (
"context"
"encoding/hex"
"errors"
"fmt"
"net/http"
Expand Down Expand Up @@ -153,11 +152,7 @@ func (cfm *configFetchMeasurementsCmd) configFetchMeasurements(
return fmt.Errorf("fetching and verifying measurements: %w", err)
}
}
measurementsToPrint := ""
for i, measurement := range fetchedMeasurements {
measurementsToPrint += fmt.Sprintf("\t%d: 0x%s\n", i, hex.EncodeToString(measurement.Expected))
}
cfm.log.Debug(fmt.Sprintf("Measurements:\n%s", measurementsToPrint))
cfm.log.Debug(fmt.Sprintf("Measurements:\n%s", fetchedMeasurements.String()))

cfm.log.Debug("Updating measurements in configuration")
conf.UpdateMeasurements(fetchedMeasurements)
Expand Down
6 changes: 1 addition & 5 deletions cli/internal/cmd/upgradecheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package cmd

import (
"context"
"encoding/hex"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -367,10 +366,7 @@ func (v *versionCollector) newMeasurements(ctx context.Context, csp cloudprovide
}
compatibleMeasurements := ""
for path, measurements := range upgrades {
compatibleMeasurement := ""
for i, measurement := range measurements {
compatibleMeasurement += fmt.Sprintf("\t\t%d: 0x%s\n", i, hex.EncodeToString(measurement.Expected))
}
compatibleMeasurement := measurements.String()
compatibleMeasurements += fmt.Sprintf("\t%q:\n%s", path, compatibleMeasurement)
}
v.log.Debug(fmt.Sprintf("Compatible image measurements are:\n%s", compatibleMeasurements))
Expand Down
9 changes: 9 additions & 0 deletions internal/attestation/measurements/measurements.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,15 @@ func (m *M) UnmarshalYAML(unmarshal func(any) error) error {
return nil
}

// String returns a string represantation of the measurements.
func (m M) String() string {
returnString := ""
for i, measurement := range m {
returnString += fmt.Sprintf("%d: 0x%s\n", i, hex.EncodeToString(measurement.Expected))
}
return returnString
}

func (m *M) fromImageMeasurementsV2(
measurements ImageMeasurementsV2, wantVersion versionsapi.Version,
csp cloudprovider.Provider, attestationVariant variant.Variant,
Expand Down
7 changes: 1 addition & 6 deletions joinservice/internal/watcher/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"context"
"crypto/x509"
"encoding/asn1"
"encoding/hex"
"fmt"
"log/slog"
"path/filepath"
Expand Down Expand Up @@ -80,11 +79,7 @@ func (u *Updatable) Update() error {
if err != nil {
return fmt.Errorf("unmarshaling config: %w", err)
}
measurementsToPrint := ""
for i, measurement := range cfg.GetMeasurements() {
measurementsToPrint += fmt.Sprintf("\t%d: 0x%s\n", i, hex.EncodeToString(measurement.Expected))
}
u.log.Debug(fmt.Sprintf("New expected measurements:\n%s", measurementsToPrint))
u.log.Debug(fmt.Sprintf("New expected measurements:\n%s", cfg.GetMeasurements().String()))

cfgWithCerts, err := u.configWithCerts(cfg)
if err != nil {
Expand Down

0 comments on commit cb11701

Please sign in to comment.