...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package app
17
18 import (
19 "fmt"
20 "os"
21 "path/filepath"
22
23 "github.com/digitorus/timestamp"
24 "github.com/sigstore/timestamp-authority/cmd/timestamp-cli/app/format"
25 "github.com/sigstore/timestamp-authority/pkg/log"
26 "github.com/spf13/cobra"
27 "github.com/spf13/viper"
28 )
29
30 func addInspectFlags(cmd *cobra.Command) {
31 cmd.Flags().Var(NewFlagValue(fileFlag, ""), "timestamp", "path to timestamp response to inspect")
32 cmd.MarkFlagRequired("timestamp")
33 }
34
35 type inspectCmdOutput struct {
36 TimestampResponse timestamp.Timestamp
37 }
38
39 func (t *inspectCmdOutput) String() string {
40 return fmt.Sprintf("%+v", t.TimestampResponse)
41 }
42
43 var inspectCmd = &cobra.Command{
44 Use: "inspect",
45 Short: "Inspect timestamp",
46 Long: "Inspect the signed timestamp response.",
47 PreRunE: func(cmd *cobra.Command, args []string) error {
48 if err := viper.BindPFlags(cmd.Flags()); err != nil {
49 log.CliLogger.Fatal("Error initializing cmd line args: ", err)
50 }
51 return nil
52 },
53 Run: format.WrapCmd(func(args []string) (interface{}, error) {
54 tsr := viper.GetString("timestamp")
55 tsrBytes, err := os.ReadFile(filepath.Clean(tsr))
56 if err != nil {
57 return nil, fmt.Errorf("Error reading request from TSR file: %w", err)
58 }
59
60 ts, err := timestamp.ParseResponse(tsrBytes)
61 if err != nil {
62 return nil, err
63 }
64
65 return &inspectCmdOutput{
66 TimestampResponse: *ts,
67 }, nil
68 }),
69 }
70
71 func init() {
72 initializePFlagMap()
73 addInspectFlags(inspectCmd)
74 rootCmd.AddCommand(inspectCmd)
75 }
76
View as plain text