-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gateway: clean up its surface, and remove BlockList #2874
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ import ( | |
_ "net/http/pprof" | ||
"os" | ||
"sort" | ||
"strings" | ||
"sync" | ||
|
||
"gx/ipfs/QmPpRcbNUXauP3zWZ1NJMLWpe4QnmEHrd2ba2D3yqWznw7/go-multiaddr-net" | ||
|
@@ -135,7 +134,7 @@ Headers. | |
cmds.BoolOption(writableKwd, "Enable writing objects (with POST, PUT and DELETE)").Default(false), | ||
cmds.StringOption(ipfsMountKwd, "Path to the mountpoint for IPFS (if using --mount). Defaults to config setting."), | ||
cmds.StringOption(ipnsMountKwd, "Path to the mountpoint for IPNS (if using --mount). Defaults to config setting."), | ||
cmds.BoolOption(unrestrictedApiAccessKwd, "Allow API access to unlisted hashes").Default(false), | ||
cmds.BoolOption(unrestrictedApiAccessKwd, "This option has no effect since v0.4.3").Default(false), | ||
cmds.BoolOption(unencryptTransportKwd, "Disable transport encryption (for debugging protocols)").Default(false), | ||
cmds.BoolOption(enableGCKwd, "Enable automatic periodic repo garbage collection").Default(false), | ||
cmds.BoolOption(adjustFDLimitKwd, "Check and raise file descriptor limits if needed").Default(false), | ||
|
@@ -364,33 +363,11 @@ func serveHTTPApi(req cmds.Request) (error, <-chan error) { | |
apiMaddr = apiLis.Multiaddr() | ||
fmt.Printf("API server listening on %s\n", apiMaddr) | ||
|
||
unrestricted, _, err := req.Option(unrestrictedApiAccessKwd).Bool() | ||
if err != nil { | ||
return fmt.Errorf("serveHTTPApi: Option(%s) failed: %s", unrestrictedApiAccessKwd, err), nil | ||
} | ||
|
||
apiGw := corehttp.NewGateway(corehttp.GatewayConfig{ | ||
Writable: true, | ||
BlockList: &corehttp.BlockList{ | ||
Decider: func(s string) bool { | ||
if unrestricted { | ||
return true | ||
} | ||
// for now, only allow paths in the WebUI path | ||
for _, webuipath := range corehttp.WebUIPaths { | ||
if strings.HasPrefix(s, webuipath) { | ||
return true | ||
} | ||
} | ||
return false | ||
}, | ||
}, | ||
}) | ||
var opts = []corehttp.ServeOption{ | ||
corehttp.MetricsCollectionOption("api"), | ||
corehttp.CommandsOption(*req.InvocContext()), | ||
corehttp.WebUIOption, | ||
apiGw.ServeOption(), | ||
corehttp.GatewayOption("/ipfs", "/ipns"), | ||
corehttp.VersionOption(), | ||
defaultMux("/debug/vars"), | ||
defaultMux("/debug/pprof/"), | ||
|
@@ -452,8 +429,8 @@ func serveHTTPGateway(req cmds.Request) (error, <-chan error) { | |
if err != nil { | ||
return fmt.Errorf("serveHTTPGateway: req.Option(%s) failed: %s", writableKwd, err), nil | ||
} | ||
if !writableOptionFound { | ||
writable = cfg.Gateway.Writable | ||
if writableOptionFound { | ||
cfg.Gateway.Writable = writable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As we are using defaults, the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mh okay, we shouldn't be using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So... the second return value (writableOptionFound) is separate from defaults -- it tells specifically whether the option was passed on the CLI. So this assumption is still true and everything's good as-is:
In other words, the default value for --writable is never used -- only if it has actually been passed. |
||
} | ||
|
||
gwLis, err := manet.Listen(gatewayMaddr) | ||
|
@@ -474,7 +451,7 @@ func serveHTTPGateway(req cmds.Request) (error, <-chan error) { | |
corehttp.CommandsROOption(*req.InvocContext()), | ||
corehttp.VersionOption(), | ||
corehttp.IPNSHostnameOption(), | ||
corehttp.GatewayOption(writable, cfg.Gateway.PathPrefixes), | ||
corehttp.GatewayOption("/ipfs", "/ipns"), | ||
} | ||
|
||
if len(cfg.Gateway.RootRedirect) > 0 { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,7 +104,7 @@ _ipfs_config_show() | |
_ipfs_daemon() | ||
{ | ||
_ipfs_comp "--init --routing= --mount --writable --mount-ipfs= \ | ||
--mount-ipns= --unrestricted-api --disable-transport-encryption \ | ||
--mount-ipns= --disable-transport-encryption \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this needs to come back too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ack right! thanks |
||
--help" | ||
} | ||
|
||
|
@@ -314,7 +314,7 @@ _ipfs_resolve() | |
|
||
_ipfs_stats() | ||
{ | ||
_ipfs_comp "bw --help" | ||
_ipfs_comp "bw --help" | ||
} | ||
|
||
_ipfs_stats_bw() | ||
|
@@ -401,17 +401,17 @@ _ipfs() | |
{ | ||
COMPREPLY=() | ||
local word="${COMP_WORDS[COMP_CWORD]}" | ||
|
||
case "${COMP_CWORD}" in | ||
1) | ||
1) | ||
local opts="add bitswap block bootstrap cat commands config daemon dht \ | ||
diag dns file get id init log ls mount name object pin ping \ | ||
refs repo stats swarm tour update version" | ||
COMPREPLY=( $(compgen -W "${opts}" -- ${word}) );; | ||
2) | ||
2) | ||
local command="${COMP_WORDS[1]}" | ||
eval "_ipfs_$command" 2> /dev/null ;; | ||
*) | ||
*) | ||
local command="${COMP_WORDS[1]}" | ||
local subcommand="${COMP_WORDS[2]}" | ||
eval "_ipfs_${command}_${subcommand}" 2> /dev/null && return | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this true?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The option itself is still there, but not being used anymore, lines 365 ff. were the only usage. I left the option there for now so that you don't get
Error: Unrecognized option 'unrestricted-api'
if you were really using it. The new behaviour is as if--unrestricted-api
was always true.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this has since been reverted. But this comment should've raised flags.