Skip to content
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: fix --writable flag :| #3206

Merged
merged 1 commit into from
Sep 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions cmd/ipfs/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,9 @@ func serveHTTPApi(req cmds.Request) (error, <-chan error) {
if err != nil {
return fmt.Errorf("serveHTTPApi: Option(%s) failed: %s", unrestrictedApiAccessKwd, err), nil
}
gatewayOpt := corehttp.GatewayOption(corehttp.WebUIPaths...)
gatewayOpt := corehttp.GatewayOption(false, corehttp.WebUIPaths...)
if unrestricted {
gatewayOpt = corehttp.GatewayOption("/ipfs", "/ipns")
gatewayOpt = corehttp.GatewayOption(true, "/ipfs", "/ipns")
}

var opts = []corehttp.ServeOption{
Expand Down Expand Up @@ -480,8 +480,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 {
cfg.Gateway.Writable = writable
if !writableOptionFound {
writable = cfg.Gateway.Writable
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 4 lines are the essence of the bug.

}

gwLis, err := manet.Listen(gatewayMaddr)
Expand All @@ -502,7 +502,7 @@ func serveHTTPGateway(req cmds.Request) (error, <-chan error) {
corehttp.CommandsROOption(*req.InvocContext()),
corehttp.VersionOption(),
corehttp.IPNSHostnameOption(),
corehttp.GatewayOption("/ipfs", "/ipns"),
corehttp.GatewayOption(writable, "/ipfs", "/ipns"),
}

if len(cfg.Gateway.RootRedirect) > 0 {
Expand Down
8 changes: 1 addition & 7 deletions cmd/ipfswatch/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,10 @@ func run(ipfsPath, watchPath string) error {
}
defer node.Close()

cfg, err := node.Repo.Config()
if err != nil {
return err
}
cfg.Gateway.Writable = true

if *http {
addr := "/ip4/127.0.0.1/tcp/5001"
var opts = []corehttp.ServeOption{
corehttp.GatewayOption("/ipfs", "/ipns"),
corehttp.GatewayOption(true, "/ipfs", "/ipns"),
corehttp.WebUIOption,
corehttp.CommandsOption(cmdCtx(node, ipfsPath)),
}
Expand Down
4 changes: 2 additions & 2 deletions core/corehttp/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type GatewayConfig struct {
PathPrefixes []string
}

func GatewayOption(paths ...string) ServeOption {
func GatewayOption(writable bool, paths ...string) ServeOption {
return func(n *core.IpfsNode, _ net.Listener, mux *http.ServeMux) (*http.ServeMux, error) {
cfg, err := n.Repo.Config()
if err != nil {
Expand All @@ -25,7 +25,7 @@ func GatewayOption(paths ...string) ServeOption {

gateway := newGatewayHandler(n, GatewayConfig{
Headers: cfg.Gateway.HTTPHeaders,
Writable: cfg.Gateway.Writable,
Writable: writable,
PathPrefixes: cfg.Gateway.PathPrefixes,
})

Expand Down
2 changes: 1 addition & 1 deletion core/corehttp/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func newTestServerAndNode(t *testing.T, ns mockNamesys) (*httptest.Server, *core
ts.Listener,
VersionOption(),
IPNSHostnameOption(),
GatewayOption("/ipfs", "/ipns"),
GatewayOption(false, "/ipfs", "/ipns"),
)
if err != nil {
t.Fatal(err)
Expand Down
15 changes: 15 additions & 0 deletions test/sharness/t0111-gateway-writeable.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,22 @@ test_description="Test HTTP Gateway (Writable)"
. lib/test-lib.sh

test_init_ipfs

test_launch_ipfs_daemon --writable
test_expect_success "ipfs daemon --writable overrides config" '
curl -v -X POST http://$GWAY_ADDR/ipfs/ 2> outfile &&
grep "HTTP/1.1 201 Created" outfile &&
grep "Location: /ipfs/QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH" outfile
'
test_kill_ipfs_daemon

test_config_ipfs_gateway_writable
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it happens right here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oooooh, i see. thanks!

test_launch_ipfs_daemon --writable=false
test_expect_success "ipfs daemon --writable=false overrides Writable=true config" '
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do we set the config value to true?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks! Moved the call to test_config_ipfs_gateway_writable up a bit

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still not seeing it... Does it happen in one of the test libs?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey I think you might have been viewing the outdated diff -- it happens right there: https://github.com/ipfs/go-ipfs/pull/3206/files#r78514885

(and I filed #3208 for the unrelated test failure)

curl -v -X POST http://$GWAY_ADDR/ipfs/ 2> outfile &&
grep "HTTP/1.1 405 Method Not Allowed" outfile
'
test_kill_ipfs_daemon
test_launch_ipfs_daemon

port=$GWAY_PORT
Expand Down
2 changes: 1 addition & 1 deletion test/supernode_client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func run() error {

opts := []corehttp.ServeOption{
corehttp.CommandsOption(cmdCtx(node, repoPath)),
corehttp.GatewayOption(),
corehttp.GatewayOption(false),
}

if *cat {
Expand Down