Skip to content

Commit 83ad0a6

Browse files
authored
measurements: add flag for generating event log (#115)
1 parent 560c53a commit 83ad0a6

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

measurements.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func newMeasurementsCmd() *cobra.Command {
2727
RunE: runMeasurements,
2828
}
2929
cmd.Flags().StringP("output-file", "o", "", "Output file for the precalculated measurements")
30+
cmd.Flags().StringP("eventlog-output", "e", "", "Output file for the event log. If not set, the event log is not written")
3031
cmd.Flags().StringP("uki-path", "u", measuredboot.UkiPath, "Path to the UKI file in the image")
3132

3233
return cmd
@@ -53,12 +54,20 @@ func runMeasurements(cmd *cobra.Command, args []string) error {
5354
cmd.Printf("Wrote precalculated measurements to %s\n", flags.outputFile)
5455
}
5556

57+
if flags.eventlogOutput != "" {
58+
if err := afero.WriteFile(fs, flags.eventlogOutput, []byte(simulator.String()), 0644); err != nil {
59+
return fmt.Errorf("creating event log output file: %w", err)
60+
}
61+
cmd.Printf("Wrote event log to %s\n", flags.eventlogOutput)
62+
}
63+
5664
return nil
5765
}
5866

5967
type measurementsFlags struct {
60-
outputFile string
61-
ukiPath string
68+
outputFile string
69+
eventlogOutput string
70+
ukiPath string
6271
}
6372

6473
func parseMeasurementsFlags(cmd *cobra.Command) (*measurementsFlags, error) {
@@ -70,9 +79,14 @@ func parseMeasurementsFlags(cmd *cobra.Command) (*measurementsFlags, error) {
7079
if err != nil {
7180
return nil, fmt.Errorf("getting uki-path flag: %w", err)
7281
}
82+
eventlogOutput, err := cmd.Flags().GetString("eventlog-output")
83+
if err != nil {
84+
return nil, fmt.Errorf("getting eventlog-output flag: %w", err)
85+
}
7386
return &measurementsFlags{
74-
outputFile: outputFile,
75-
ukiPath: ukiPath,
87+
outputFile: outputFile,
88+
ukiPath: ukiPath,
89+
eventlogOutput: eventlogOutput,
7690
}, nil
7791
}
7892

0 commit comments

Comments
 (0)