mirror of
https://github.com/ipfs/kubo.git
synced 2025-08-06 19:44:01 +08:00
fixes to routing put command (#10205)
* fix(commands): routing put command returns the IPNS ID rather than the host's ID * fix(commands): routing put command errors with the allow-offline hint if the error is an offline error * fix: test expects correct error message --------- Co-authored-by: Henrique Dias <hacdias@gmail.com>
This commit is contained in:
@ -14,6 +14,7 @@ import (
|
||||
iface "github.com/ipfs/boxo/coreiface"
|
||||
"github.com/ipfs/boxo/coreiface/options"
|
||||
dag "github.com/ipfs/boxo/ipld/merkledag"
|
||||
"github.com/ipfs/boxo/ipns"
|
||||
cid "github.com/ipfs/go-cid"
|
||||
cmds "github.com/ipfs/go-ipfs-cmds"
|
||||
ipld "github.com/ipfs/go-ipld-format"
|
||||
@ -451,12 +452,12 @@ identified by QmFoo.
|
||||
options.Put.AllowOffline(allowOffline),
|
||||
}
|
||||
|
||||
err = api.Routing().Put(req.Context, req.Arguments[0], data, opts...)
|
||||
ipnsName, err := ipns.NameFromString(req.Arguments[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
id, err := api.Key().Self(req.Context)
|
||||
err = api.Routing().Put(req.Context, req.Arguments[0], data, opts...)
|
||||
if err != nil {
|
||||
if err == iface.ErrOffline {
|
||||
err = errAllowOffline
|
||||
@ -466,7 +467,7 @@ identified by QmFoo.
|
||||
|
||||
return res.Emit(routing.QueryEvent{
|
||||
Type: routing.Value,
|
||||
ID: id.ID(),
|
||||
ID: ipnsName.Peer(),
|
||||
})
|
||||
},
|
||||
Encoders: cmds.EncoderMap{
|
||||
|
@ -131,7 +131,7 @@ func TestLegacyDHT(t *testing.T) {
|
||||
node.WriteBytes("foo", []byte("foo"))
|
||||
res := node.RunIPFS("dht", "put", "/ipns/"+node.PeerID().String(), "foo")
|
||||
assert.Equal(t, 1, res.ExitCode())
|
||||
assert.Contains(t, res.Stderr.String(), "this action must be run in online mode")
|
||||
assert.Contains(t, res.Stderr.String(), "can't put while offline: pass `--allow-offline` to override")
|
||||
})
|
||||
})
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ func testRoutingDHT(t *testing.T, enablePubsub bool) {
|
||||
node.WriteBytes("foo", []byte("foo"))
|
||||
res := node.RunIPFS("routing", "put", "/ipns/"+node.PeerID().String(), "foo")
|
||||
assert.Equal(t, 1, res.ExitCode())
|
||||
assert.Contains(t, res.Stderr.String(), "this action must be run in online mode")
|
||||
assert.Contains(t, res.Stderr.String(), "can't put while offline: pass `--allow-offline` to override")
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user