1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-29 01:12:24 +08:00

code review improvements

change core.IpfsNode as first arg

check keylookup err to propagate validation errors from lower levels

License: MIT
Signed-off-by: Kerem Gocen <keremgocen@gmail.com>
This commit is contained in:
Kerem
2017-04-27 21:00:48 +03:00
parent 39ece86484
commit 76e227d499

View File

@ -10,6 +10,7 @@ import (
cmds "github.com/ipfs/go-ipfs/commands"
core "github.com/ipfs/go-ipfs/core"
keystore "github.com/ipfs/go-ipfs/keystore"
path "github.com/ipfs/go-ipfs/path"
crypto "gx/ipfs/QmP1DfoUjiWH2ZBo1PBH6FupdBucbDepx3HpWmEY6JMUpY/go-libp2p-crypto"
@ -121,7 +122,7 @@ Alternatively, publish an <ipfs-path> using a valid PeerID(as listed by 'ipfs ke
}
kname, _, _ := req.Option("key").String()
k, err := keylookup(kname, n)
k, err := keylookup(n, kname)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
@ -182,13 +183,17 @@ func publish(ctx context.Context, n *core.IpfsNode, k crypto.PrivKey, ref path.P
}, nil
}
func keylookup(k string, n *core.IpfsNode) (crypto.PrivKey, error) {
func keylookup(n *core.IpfsNode, k string) (crypto.PrivKey, error) {
res, err := n.GetKey(k)
if res != nil {
return res, nil
}
if err != nil && err != keystore.ErrNoSuchKey {
return nil, err
}
keys, err := n.Repo.Keystore().List()
if err != nil {
return nil, err