Skip to content
Snippets Groups Projects
Commit dd5382c9 authored by Dan Lorenc's avatar Dan Lorenc
Browse files

Fix get with --uuid.

parent 3fa05602
No related branches found
No related tags found
No related merge requests found
...@@ -30,6 +30,17 @@ import ( ...@@ -30,6 +30,17 @@ import (
"github.com/spf13/viper" "github.com/spf13/viper"
) )
type getCmdOutput struct {
Body []byte
LogIndex int
}
func (g *getCmdOutput) String() string {
s := fmt.Sprintf("%d\n", g.LogIndex)
s += fmt.Sprintf("%s\n", g.Body)
return s
}
// getCmd represents the get command // getCmd represents the get command
var getCmd = &cobra.Command{ var getCmd = &cobra.Command{
Use: "get", Use: "get",
...@@ -60,11 +71,7 @@ var getCmd = &cobra.Command{ ...@@ -60,11 +71,7 @@ var getCmd = &cobra.Command{
if err != nil { if err != nil {
return nil, err return nil, err
} }
for _, entry := range resp.Payload {
for k, entry := range resp.Payload {
if k != logIndex {
continue
}
return parseEntry(entry) return parseEntry(entry)
} }
} }
...@@ -97,15 +104,12 @@ func parseEntry(e models.LogEntryAnon) (interface{}, error) { ...@@ -97,15 +104,12 @@ func parseEntry(e models.LogEntryAnon) (interface{}, error) {
return nil, err return nil, err
} }
// Now parse that back into JSON in the format "body, logindex" // Now parse that back into JSON in the format "body, logindex"
obj := struct { obj := getCmdOutput{}
Body []byte
LogIndex int
}{}
if err := json.Unmarshal(bytes, &obj); err != nil { if err := json.Unmarshal(bytes, &obj); err != nil {
return nil, err return nil, err
} }
return obj, nil return &obj, nil
} }
func init() { func init() {
......
...@@ -33,14 +33,14 @@ import ( ...@@ -33,14 +33,14 @@ import (
"github.com/spf13/viper" "github.com/spf13/viper"
) )
type getCmdOutput struct { type logInfoCmdOutput struct {
TreeSize int64 TreeSize int64
RootHash string RootHash string
} }
func (g *getCmdOutput) String() string { func (l *logInfoCmdOutput) String() string {
// Verification is always successful if we return an object. // Verification is always successful if we return an object.
return fmt.Sprintf("Verification Successful!\nTree Size: %v\nRoot Hash: %s\n", g.TreeSize, g.RootHash) return fmt.Sprintf("Verification Successful!\nTree Size: %v\nRoot Hash: %s\n", l.TreeSize, l.RootHash)
} }
// logInfoCmd represents the current information about the transparency log // logInfoCmd represents the current information about the transparency log
...@@ -60,7 +60,7 @@ var logInfoCmd = &cobra.Command{ ...@@ -60,7 +60,7 @@ var logInfoCmd = &cobra.Command{
} }
logInfo := result.GetPayload() logInfo := result.GetPayload()
cmdOutput := &getCmdOutput{ cmdOutput := &logInfoCmdOutput{
TreeSize: *logInfo.TreeSize, TreeSize: *logInfo.TreeSize,
RootHash: *logInfo.RootHash, RootHash: *logInfo.RootHash,
} }
......
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"encoding/json" "encoding/json"
"io/ioutil" "io/ioutil"
"path/filepath" "path/filepath"
"strconv"
"strings" "strings"
"testing" "testing"
"time" "time"
...@@ -95,7 +96,7 @@ func TestGet(t *testing.T) { ...@@ -95,7 +96,7 @@ func TestGet(t *testing.T) {
splitUrl := strings.Split(url, "/") splitUrl := strings.Split(url, "/")
uuid := splitUrl[len(splitUrl)-1] uuid := splitUrl[len(splitUrl)-1]
out = runCli(t, "get", "--uuid", uuid) out = runCli(t, "get", "--format=json", "--uuid", uuid)
// The output here should be in JSON with this structure: // The output here should be in JSON with this structure:
g := struct { g := struct {
Body string Body string
...@@ -104,7 +105,8 @@ func TestGet(t *testing.T) { ...@@ -104,7 +105,8 @@ func TestGet(t *testing.T) {
if err := json.Unmarshal([]byte(out), &g); err != nil { if err := json.Unmarshal([]byte(out), &g); err != nil {
t.Error(err) t.Error(err)
} }
// TODO: check the actual data in here. // Get it with the logindex as well
runCli(t, "get", "--format=json", "--log-index", strconv.Itoa(g.LogIndex))
// check index via the file and public key to ensure that the index has updated correctly // check index via the file and public key to ensure that the index has updated correctly
out = runCli(t, "search", "--artifact", artifactPath) out = runCli(t, "search", "--artifact", artifactPath)
......
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