Skip to content
Snippets Groups Projects
Unverified Commit ea7b6072 authored by dlorenc's avatar dlorenc Committed by GitHub
Browse files

Merge pull request #193 from dlorenc/morets

Add timestamps to the log_info output.
parents fb0b1f6e 4189e108
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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"))
......
......@@ -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"))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment