-
Notifications
You must be signed in to change notification settings - Fork 3
/
pcrs.go
56 lines (45 loc) · 1.2 KB
/
pcrs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package cmd
import (
"fmt"
"path"
"strings"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/capeprivacy/cli/pcrs"
)
// runCmd represents the get-prcs command
var getPCRsCmd = &cobra.Command{
Use: "get-pcrs",
Short: "returns the pcrs of a given runtime version",
Long: "",
RunE: getPCRs,
}
func init() {
rootCmd.AddCommand(getPCRsCmd)
getPCRsCmd.PersistentFlags().String("version", "release-434bd34", "the version of the runtime EIF to get PCRs for")
getPCRsCmd.PersistentFlags().StringP("bucket", "b", "user-eif-release-bucket", "the artifact source bucket in S3")
}
func getPCRs(cmd *cobra.Command, args []string) error {
version, err := cmd.Flags().GetString("version")
if err != nil {
return fmt.Errorf("error retrieving version flag %s", err)
}
bucket, err := cmd.Flags().GetString("bucket")
if err != nil {
return fmt.Errorf("error retrieving bucket flag %s", err)
}
p, err := pcrs.DownloadEIF(bucket, version)
if err != nil {
return err
}
info, err := pcrs.GetEIFInfo(path.Base(p))
if err != nil {
return err
}
for key, item := range info.Measurements {
if strings.HasPrefix(key, "PCR") {
log.Infof("%s:\t%s", key, item)
}
}
return nil
}