Skip to content

Commit

Permalink
Added debug method to internal logger (#24)
Browse files Browse the repository at this point in the history
* export GetMeasurementsFromTLS and make independent of proxy

* Added debug method to internal logger
  • Loading branch information
metachris authored Nov 18, 2024
1 parent 04abe8c commit da9d29a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
4 changes: 4 additions & 0 deletions internal/attestation/attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,17 @@ const (

// Logger is a logger used to print warnings and infos during attestation validation.
type Logger interface {
Debug(msg string, args ...any)
Info(msg string, args ...any)
Warn(msg string, args ...any)
}

// NOPLogger is a no-op implementation of [Logger].
type NOPLogger struct{}

// Debug is a no-op.
func (NOPLogger) Debug(string, ...interface{}) {}

// Info is a no-op.
func (NOPLogger) Info(string, ...interface{}) {}

Expand Down
9 changes: 0 additions & 9 deletions internal/attestation/azure/snp/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,6 @@ func (v *Validator) checkIDKeyDigest(ctx context.Context, report *spb.Attestatio
return nil
}

// nopAttestationLogger is a no-op implementation of AttestationLogger.
type nopAttestationLogger struct{}

// Infof is a no-op.
func (nopAttestationLogger) Info(string, ...interface{}) {}

// Warnf is a no-op.
func (nopAttestationLogger) Warn(string, ...interface{}) {}

type maaValidator interface {
validateToken(ctx context.Context, maaURL string, token string, extraData []byte) error
}
Expand Down
2 changes: 1 addition & 1 deletion internal/attestation/vtpm/attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func (v *Validator) Validate(ctx context.Context, attDocRaw []byte, nonce []byte
if err := json.Unmarshal(attDocRaw, &attDoc); err != nil {
return nil, fmt.Errorf("unmarshaling TPM attestation document: %w", err)
}
v.log.Warn(fmt.Sprintf("Attestation document: %s", string(attDocRaw)))
v.log.Debug(fmt.Sprintf("Attestation document: %s", string(attDocRaw)))

extraData := attestation.MakeExtraData(attDoc.UserData, nonce)

Expand Down
5 changes: 5 additions & 0 deletions internal/attestation/vtpm/attestation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,13 +478,18 @@ func TestGetSelectedMeasurements(t *testing.T) {

type testAttestationLogger struct {
infos []string
debugs []string
warnings []string
}

func (w *testAttestationLogger) Info(format string, args ...any) {
w.infos = append(w.infos, fmt.Sprintf(format, args...))
}

func (w *testAttestationLogger) Debug(format string, args ...any) {
w.debugs = append(w.debugs, fmt.Sprintf(format, args...))
}

func (w *testAttestationLogger) Warn(format string, args ...any) {
w.warnings = append(w.warnings, fmt.Sprintf(format, args...))
}
4 changes: 4 additions & 0 deletions proxy/atls_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ func (w AttestationLogger) Info(format string, args ...any) {
w.Log.Log(context.TODO(), slog.LevelInfo, fmt.Sprintf(format, args...))
}

func (w AttestationLogger) Debug(format string, args ...any) {
w.Log.Log(context.TODO(), slog.LevelDebug, fmt.Sprintf(format, args...))
}

func (w AttestationLogger) Warn(format string, args ...any) {
w.Log.Log(context.TODO(), slog.LevelWarn, fmt.Sprintf(format, args...))
}

0 comments on commit da9d29a

Please sign in to comment.