Skip to content

Commit 5823cde

Browse files
committed
Add readonly api to gateway
Based on ipfs#1389 License: MIT Signed-off-by: rht <[email protected]>
1 parent da75e92 commit 5823cde

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

cmd/ipfs/daemon.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ func serveHTTPGateway(req cmds.Request) (error, <-chan error) {
401401
}
402402

403403
var opts = []corehttp.ServeOption{
404+
corehttp.CommandsROOption(*req.InvocContext()),
404405
corehttp.VersionOption(),
405406
corehttp.IPNSHostnameOption(),
406407
corehttp.GatewayOption(writable),

core/commands/root.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,39 @@ var rootSubcommands = map[string]*cmds.Command{
109109
"version": VersionCmd,
110110
"bitswap": BitswapCmd,
111111
}
112+
var rootROSubcommands = map[string]*cmds.Command{
113+
"block": &cmds.Command{
114+
Subcommands: map[string]*cmds.Command{
115+
"stat": blockStatCmd,
116+
"get": blockGetCmd,
117+
},
118+
},
119+
"cat": CatCmd,
120+
"commands": CommandsDaemonCmd,
121+
"ls": LsCmd,
122+
"name": &cmds.Command{
123+
Subcommands: map[string]*cmds.Command{
124+
"resolve": IpnsCmd,
125+
},
126+
},
127+
"object": &cmds.Command{
128+
Subcommands: map[string]*cmds.Command{
129+
"data": objectDataCmd,
130+
"links": objectLinksCmd,
131+
"get": objectGetCmd,
132+
"stat": objectStatCmd,
133+
},
134+
},
135+
"refs": RefsCmd,
136+
//"resolve": ResolveCmd,
137+
}
138+
139+
var RootRO = &cmds.Command{}
112140

113141
func init() {
142+
*RootRO = *Root
114143
Root.Subcommands = rootSubcommands
144+
RootRO.Subcommands = rootROSubcommands
115145
}
116146

117147
type MessageOutput struct {

core/corehttp/commands.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func patchCORSVars(c *cmdsHttp.ServerConfig, addr net.Addr) {
9999
}
100100
}
101101

102-
func CommandsOption(cctx commands.Context) ServeOption {
102+
func commandsOption(cctx commands.Context, commands *commands.Command) ServeOption {
103103
return func(n *core.IpfsNode, l net.Listener, mux *http.ServeMux) (*http.ServeMux, error) {
104104

105105
cfg := &cmdsHttp.ServerConfig{
@@ -113,8 +113,16 @@ func CommandsOption(cctx commands.Context) ServeOption {
113113
addCORSDefaults(cfg)
114114
patchCORSVars(cfg, l.Addr())
115115

116-
cmdHandler := cmdsHttp.NewHandler(cctx, corecommands.Root, cfg)
116+
cmdHandler := cmdsHttp.NewHandler(cctx, commands, cfg)
117117
mux.Handle(cmdsHttp.ApiPath+"/", cmdHandler)
118118
return mux, nil
119119
}
120120
}
121+
122+
func CommandsOption(cctx commands.Context) ServeOption {
123+
return commandsOption(cctx, corecommands.Root)
124+
}
125+
126+
func CommandsROOption(cctx commands.Context) ServeOption {
127+
return commandsOption(cctx, corecommands.RootRO)
128+
}

0 commit comments

Comments
 (0)