提交 fbac8204 作者: Juan Benet

Merge pull request #1581 from rht/feat/read-only-api-gateway

Add readonly api to gateway
......@@ -401,6 +401,7 @@ func serveHTTPGateway(req cmds.Request) (error, <-chan error) {
}
var opts = []corehttp.ServeOption{
corehttp.CommandsROOption(*req.InvocContext()),
corehttp.VersionOption(),
corehttp.IPNSHostnameOption(),
corehttp.GatewayOption(writable),
......
......@@ -109,9 +109,39 @@ var rootSubcommands = map[string]*cmds.Command{
"version": VersionCmd,
"bitswap": BitswapCmd,
}
var rootROSubcommands = map[string]*cmds.Command{
"block": &cmds.Command{
Subcommands: map[string]*cmds.Command{
"stat": blockStatCmd,
"get": blockGetCmd,
},
},
"cat": CatCmd,
"commands": CommandsDaemonCmd,
"ls": LsCmd,
"name": &cmds.Command{
Subcommands: map[string]*cmds.Command{
"resolve": IpnsCmd,
},
},
"object": &cmds.Command{
Subcommands: map[string]*cmds.Command{
"data": objectDataCmd,
"links": objectLinksCmd,
"get": objectGetCmd,
"stat": objectStatCmd,
},
},
"refs": RefsCmd,
//"resolve": ResolveCmd,
}
var RootRO = &cmds.Command{}
func init() {
*RootRO = *Root
Root.Subcommands = rootSubcommands
RootRO.Subcommands = rootROSubcommands
}
type MessageOutput struct {
......
......@@ -99,7 +99,7 @@ func patchCORSVars(c *cmdsHttp.ServerConfig, addr net.Addr) {
}
}
func CommandsOption(cctx commands.Context) ServeOption {
func commandsOption(cctx commands.Context, command *commands.Command) ServeOption {
return func(n *core.IpfsNode, l net.Listener, mux *http.ServeMux) (*http.ServeMux, error) {
cfg := &cmdsHttp.ServerConfig{
......@@ -113,8 +113,16 @@ func CommandsOption(cctx commands.Context) ServeOption {
addCORSDefaults(cfg)
patchCORSVars(cfg, l.Addr())
cmdHandler := cmdsHttp.NewHandler(cctx, corecommands.Root, cfg)
cmdHandler := cmdsHttp.NewHandler(cctx, command, cfg)
mux.Handle(cmdsHttp.ApiPath+"/", cmdHandler)
return mux, nil
}
}
func CommandsOption(cctx commands.Context) ServeOption {
return commandsOption(cctx, corecommands.Root)
}
func CommandsROOption(cctx commands.Context) ServeOption {
return commandsOption(cctx, corecommands.RootRO)
}
......@@ -91,6 +91,19 @@ test_expect_success "log output looks good" '
grep "log API client connected" log_out
'
# test ipfs readonly api
test_expect_success "get IPFS directory file through readonly API succeeds" '
curl -sfo actual "http://127.0.0.1:$port/api/v0/cat?arg=$HASH2/test"
'
test_expect_success "get IPFS directory file through readonly API output looks good" '
test_cmp dir/test actual
'
test_expect_success "refs IPFS directory file through readonly API succeeds" '
curl -sfo actual "http://127.0.0.1:$port/api/v0/refs?arg=$HASH2/test"
'
test_kill_ipfs_daemon
test_done
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论