refactoring verify and switching os.Stderr to use logrus which is set to output on stderr

This commit is contained in:
David Lawrence 2015-06-21 16:05:07 -07:00
parent 5efc8c0549
commit 779d3b687e
1 changed files with 8 additions and 23 deletions

View File

@ -373,28 +373,12 @@ func verify(cmd *cobra.Command, args []string) {
"json", "json",
"", "",
) )
rootJSON, err := remote.GetMeta("root", 5<<20)
if err != nil {
fmt.Println("Couldn't get initial root")
fatalf(err.Error())
}
root := &data.Signed{}
err = json.Unmarshal(rootJSON, root)
if err != nil {
fmt.Println("Couldn't parse initial root")
fatalf(err.Error())
}
// TODO: Validate the root file against the key store
err = repo.SetRoot(root)
if err != nil {
fatalf("Error setting root %v", err)
}
c := client.NewClient( c, err := bootstrapClient(remote, repo, kdb)
repo, if err != nil {
remote, logrus.Error("Unable to setup client.")
kdb, return
) }
err = c.Update() err = c.Update()
if err != nil { if err != nil {
@ -403,14 +387,15 @@ func verify(cmd *cobra.Command, args []string) {
} }
meta := c.TargetMeta(targetName) meta := c.TargetMeta(targetName)
if meta == nil { if meta == nil {
return logrus.Error("notary: data not present in the trusted collection.")
os.Exit(1)
} }
// Create hasher and hash data // Create hasher and hash data
stdinHash := fmt.Sprintf("sha256:%x", sha256.Sum256(payload)) stdinHash := fmt.Sprintf("sha256:%x", sha256.Sum256(payload))
serverHash := fmt.Sprintf("sha256:%s", meta.Hashes["sha256"]) serverHash := fmt.Sprintf("sha256:%s", meta.Hashes["sha256"])
if stdinHash != serverHash { if stdinHash != serverHash {
_, _ = os.Stderr.Write([]byte("notary: Data not present in the trusted collection.\n")) logrus.Error("notary: data not present in the trusted collection.")
os.Exit(1) os.Exit(1)
} else { } else {
_, _ = os.Stdout.Write(payload) _, _ = os.Stdout.Write(payload)