Skip to content

Commit

Permalink
refactor: use Status: cmds.Removed
Browse files Browse the repository at this point in the history
This allows us to return meaningful error to end users who were not
aware of deprecation, and also produce useful removal notice at
https://docs.ipfs.tech/reference/kubo/rpc/ for people who
try to execute commands or RPC from old tutorials.
  • Loading branch information
lidel committed Mar 21, 2024
1 parent 7daa23c commit 850ec3c
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
13 changes: 13 additions & 0 deletions core/commands/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ func TestCommands(t *testing.T) {
"/dag/stat",
"/dht",
"/dht/query",
"/dht/findprovs",
"/dht/findpeer",
"/dht/get",
"/dht/provide",
"/dht/put",
"/routing",
"/routing/put",
"/routing/get",
Expand Down Expand Up @@ -120,10 +125,18 @@ func TestCommands(t *testing.T) {
"/name/pubsub/subs",
"/name/resolve",
"/object",
"/object/data",
"/object/diff",
"/object/get",
"/object/links",
"/object/new",
"/object/patch",
"/object/patch/add-link",
"/object/patch/append-data",
"/object/patch/rm-link",
"/object/patch/set-data",
"/object/put",
"/object/stat",
"/p2p",
"/p2p/close",
"/p2p/forward",
Expand Down
18 changes: 17 additions & 1 deletion core/commands/dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@ import (
var ErrNotDHT = errors.New("routing service is not a DHT")

var DhtCmd = &cmds.Command{
Status: cmds.Deprecated,
Helptext: cmds.HelpText{
Tagline: "Issue commands directly through the DHT.",
ShortDescription: ``,
},

Subcommands: map[string]*cmds.Command{
"query": queryDhtCmd,
"query": queryDhtCmd,
"findprovs": RemovedDHTCmd,
"findpeer": RemovedDHTCmd,
"get": RemovedDHTCmd,
"put": RemovedDHTCmd,
"provide": RemovedDHTCmd,
},
}

Expand All @@ -32,6 +38,7 @@ type kademlia interface {
}

var queryDhtCmd = &cmds.Command{
Status: cmds.Deprecated,
Helptext: cmds.HelpText{
Tagline: "Find the closest Peer IDs to a given Peer ID by querying the DHT.",
ShortDescription: "Outputs a list of newline-delimited Peer IDs.",
Expand Down Expand Up @@ -114,3 +121,12 @@ var queryDhtCmd = &cmds.Command{
},
Type: routing.QueryEvent{},
}
var RemovedDHTCmd = &cmds.Command{
Status: cmds.Removed,
Helptext: cmds.HelpText{
Tagline: "Removed, use 'ipfs routing' instead.",
},
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
return errors.New("removed, use 'ipfs routing' instead")
},
}
16 changes: 16 additions & 0 deletions core/commands/object/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,23 @@ directly. Deprecated, use more modern 'ipfs dag' and 'ipfs files' instead.`,
},

Subcommands: map[string]*cmds.Command{
"data": RemovedObjectCmd,
"diff": ObjectDiffCmd,
"get": RemovedObjectCmd,
"links": RemovedObjectCmd,
"new": RemovedObjectCmd,
"patch": ObjectPatchCmd,
"put": RemovedObjectCmd,
"stat": RemovedObjectCmd,
},
}

var RemovedObjectCmd = &cmds.Command{
Status: cmds.Removed,
Helptext: cmds.HelpText{
Tagline: "Removed, use 'ipfs dag' or 'ipfs files' instead.",
},
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
return errors.New("removed, use 'ipfs dag' or 'ipfs files' instead")
},
}
6 changes: 4 additions & 2 deletions core/commands/object/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ For modern use cases, use MFS with 'files' commands: 'ipfs files --help'.
},
Arguments: []cmds.Argument{},
Subcommands: map[string]*cmds.Command{
"add-link": patchAddLinkCmd,
"rm-link": patchRmLinkCmd,
"append-data": RemovedObjectCmd,
"add-link": patchAddLinkCmd,
"rm-link": patchRmLinkCmd,
"set-data": RemovedObjectCmd,
},
Options: []cmds.Option{
cmdutils.AllowBigBlockOption,
Expand Down

0 comments on commit 850ec3c

Please sign in to comment.