diff --git a/cmd/cli/app/log_info.go b/cmd/cli/app/log_info.go index 4212291e6d893a1104cb666ed9416fd557f36404..a46983c894836f6bb71e306ab451755945a93b99 100644 --- a/cmd/cli/app/log_info.go +++ b/cmd/cli/app/log_info.go @@ -25,6 +25,7 @@ import ( "errors" "fmt" "strings" + "time" "github.com/sigstore/rekor/cmd/cli/app/state" @@ -42,13 +43,19 @@ import ( ) type logInfoCmdOutput struct { - TreeSize int64 - RootHash string + TreeSize int64 + RootHash string + TimestampNanos uint64 } func (l *logInfoCmdOutput) String() string { // Verification is always successful if we return an object. - return fmt.Sprintf("Verification Successful!\nTree Size: %v\nRoot Hash: %s\n", l.TreeSize, l.RootHash) + ts := time.Unix(0, int64(l.TimestampNanos)).UTC().Format(time.RFC3339) + return fmt.Sprintf(`Verification Successful! +Tree Size: %v +Root Hash: %s +Timestamp: %s +`, l.TreeSize, l.RootHash, ts) } // logInfoCmd represents the current information about the transparency log @@ -113,6 +120,11 @@ var logInfoCmd = &cobra.Command{ if err != nil { return nil, err } + cmdOutput := &logInfoCmdOutput{ + TreeSize: *logInfo.TreeSize, + RootHash: *logInfo.RootHash, + TimestampNanos: lr.TimestampNanos, + } if lr.TreeSize != uint64(*logInfo.TreeSize) { return nil, errors.New("tree size in signed tree head does not match value returned in API call") @@ -122,11 +134,6 @@ var logInfoCmd = &cobra.Command{ return nil, errors.New("root hash in signed tree head does not match value returned in API call") } - cmdOutput := &logInfoCmdOutput{ - TreeSize: int64(lr.TreeSize), - RootHash: hex.EncodeToString(lr.RootHash), - } - oldState := state.Load(serverURL) if oldState != nil { persistedSize := oldState.TreeSize diff --git a/cmd/cli/app/log_proof.go b/cmd/cli/app/log_proof.go index 1add13bc8ce8a558e751c6bc8bce7c38ab0088a0..f39c3ec3e023595000033b83aa95b71d3731198d 100644 --- a/cmd/cli/app/log_proof.go +++ b/cmd/cli/app/log_proof.go @@ -16,12 +16,12 @@ limitations under the License. package app import ( + "errors" "fmt" "os" "github.com/sigstore/rekor/cmd/cli/app/format" "github.com/sigstore/rekor/pkg/generated/client/tlog" - "github.com/sigstore/rekor/pkg/log" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -50,23 +50,21 @@ var logProofCmd = &cobra.Command{ Use: "logproof", Short: "Rekor logproof command", Long: `Prints information required to compute the consistency proof of the transparency log`, - PreRun: func(cmd *cobra.Command, args []string) { + PreRunE: func(cmd *cobra.Command, args []string) error { // these are bound here so that they are not overwritten by other commands if err := viper.BindPFlags(cmd.Flags()); err != nil { - log.Logger.Fatal("Error initializing cmd line args: ", err) + return fmt.Errorf("Error initializing cmd line args: %s", err) } if viper.GetUint64("first-size") > viper.GetUint64("last-size") { - log.Logger.Error("last-size must be >= to first-size") - os.Exit(1) + return errors.New("last-size must be >= to first-size") } if viper.GetUint64("first-size") == 0 { - log.Logger.Error("first-size must be > 0") - os.Exit(1) + return errors.New("first-size must be > 0") } if viper.GetUint64("last-size") == 0 { - log.Logger.Error("last-size must be > 0") - os.Exit(1) + return errors.New("last-size must be > 0") } + return nil }, Run: format.WrapCmd(func(args []string) (interface{}, error) { rekorClient, err := GetRekorClient(viper.GetString("rekor_server")) diff --git a/cmd/cli/app/verify.go b/cmd/cli/app/verify.go index e886b0c9ccbfbec1877493ac34901d66f91cecdd..cd47543d32d53c28609b641f850cc56b703581c0 100644 --- a/cmd/cli/app/verify.go +++ b/cmd/cli/app/verify.go @@ -20,7 +20,6 @@ import ( "errors" "fmt" "math/bits" - "os" "strconv" "github.com/google/trillian/merkle/logverifier" @@ -73,16 +72,16 @@ var verifyCmd = &cobra.Command{ Use: "verify", Short: "Rekor verify command", Long: `Verifies an entry exists in the transparency log through an inclusion proof`, - PreRun: func(cmd *cobra.Command, args []string) { + PreRunE: func(cmd *cobra.Command, args []string) error { // these are bound here so that they are not overwritten by other commands if err := viper.BindPFlags(cmd.Flags()); err != nil { - log.Logger.Fatal("Error initializing cmd line args: ", err) + return fmt.Errorf("Error initializing cmd line args: %s", err) } if err := validateArtifactPFlags(true, true); err != nil { - log.Logger.Error(err) _ = cmd.Help() - os.Exit(1) + return err } + return nil }, Run: format.WrapCmd(func(args []string) (interface{}, error) { rekorClient, err := GetRekorClient(viper.GetString("rekor_server"))