Panic-ing when trying to access a view

I created the view via this method. The view works perfectly… on the admin port. I switch to port 4984, include a SyncGatewaySession cookie… and then all I get is 403 forbidden. (It’s “unauthorized” when the cookie is missing or invalid.)

Last time we discussed that 403 means it’s not in the user’s channel, so I tried adding a channel to the view, but could not do it. All of the documents emitted by the view ARE in the user’s channel but the resulting JSON doesn’t have a channels property. Here is the result of the view from the admin port. The channel I want the view to be in is “new-quote”.

{
  "total_rows": 3,
  "rows": [
    {
      "id": "quote1",
      "key": "quote1",
      "value": "new-quote"
    },
    {
      "id": "quote1042",
      "key": "quote1042",
      "value": "new-quote"
    },
    {
      "id": "quote3001",
      "key": "quote3001",
      "value": "new-quote"
    }
  ]
}

Here it is from the public port (with a valid SyncGatewaySession cookie)

{
  "error": "Forbidden",
  "reason": "forbidden"
}

Here is the view itself:

{
    "views":{
        "new_quote":{
            "map":"function (doc, meta) { if (doc.channels == 'new-quote') emit(meta.id, doc.channels); }"
        }
    }
}

And here is the curl used to install the view:

curl -vX PUT http://sync.gateway.ip.address:4985/{dbname}/_design/new_quote -H "Content-Type: application/json" -d @view.json
  1. How do I get access to this view on the public port?
  2. How do I restrict access to only users of the “new-quote” channel? (Or does a view automatically only emit documents that are in the users’ channels?)

Have a great weekend.

Kind regards,
David

Which Sync Gateway build are you running?

Version 1.1.0 community for ubuntu

http://www.couchbase.com/dl/releases/couchbase-sync-gateway/1.1.0/couchbase-sync-gateway-community_1.1.0-28_x86_64.deb

View access via the public port is currently only available on the Sync Gateway master branch - it wasn’t included in 1.1.0 due to some potential issue with view filtering when using map/reduce views.

There are some additional details here:

Good to know. I will build from github.

So am I correct in my reading that the view will only emit references that the user has in his channels?

Thanks for the quick reply!

Kind regards,
David

installed from github, now my gateway is panic-ing…

(same view as above, accessed from public port with a valid SyncGatewaySession Cookie header)

2015-07-25T02:12:08.857Z HTTP:  #001: GET /{dbname}/_design/new_quote/_view/new_quote  (as myusername)
2015-07-25T02:12:08.857Z HTTP: JSON view "new_quote"/"new_quote" - opts map[]
2015/07/25 02:12:08 http: panic serving 208.107.235.44:49603: interface conversion: interface is string, not []interface {}
goroutine 44 [running]:
net/http.func·011()
        /usr/lib/go/src/pkg/net/http/server.go:1100 +0xb7
runtime.panic(0xa0f900, 0xc208225580)
        /usr/lib/go/src/pkg/runtime/panic.c:248 +0x18d
github.com/couchbase/sync_gateway/db.filterViewResult(0x3, 0xc2081e4c00, 0x3, 0x4, 0x0, 0x0, 0x0, 0x0, 0x7f7fb3f51fe8, 0xc208034e70, ...)
        /home/dbergan/sync_gateway/src/github.com/couchbase/sync_gateway/db/design_doc.go:140 +0x373
github.com/couchbase/sync_gateway/db.(*Database).QueryDesignDoc(0xc2081e4360, 0xc208224cdb, 0x9, 0xc208224ceb, 0x9, 0xc20819a6f0, 0x3, 0x0,
 0x0)
        /home/dbergan/sync_gateway/src/github.com/couchbase/sync_gateway/db/design_doc.go:113 +0x569
github.com/couchbase/sync_gateway/rest.(*handler).handleView(0xc20826ef30, 0x0, 0x0)
        /home/dbergan/sync_gateway/src/github.com/couchbase/sync_gateway/rest/view_api.go:104 +0x9ae
github.com/couchbase/sync_gateway/rest.(*handler).invoke(0xc20826ef30, 0xd3e5f0, 0x0, 0x0)
        /home/dbergan/sync_gateway/src/github.com/couchbase/sync_gateway/rest/handler.go:159 +0x430
github.com/couchbase/sync_gateway/rest.func·015(0x7f7fb3f56600, 0xc208199ae0, 0xc20802a9c0)
        /home/dbergan/sync_gateway/src/github.com/couchbase/sync_gateway/rest/handler.go:86 +0x7c
net/http.HandlerFunc.ServeHTTP(0xc2081d96a0, 0x7f7fb3f56600, 0xc208199ae0, 0xc20802a9c0)
        /usr/lib/go/src/pkg/net/http/server.go:1235 +0x40
github.com/gorilla/mux.(*Router).ServeHTTP(0xc20825e690, 0x7f7fb3f56600, 0xc208199ae0, 0xc20802a9c0)
        /home/dbergan/sync_gateway/src/github.com/gorilla/mux/mux.go:86 +0x288
github.com/couchbase/sync_gateway/rest.func·017(0x7f7fb3f56600, 0xc208199ae0, 0xc20802a9c0)
        /home/dbergan/sync_gateway/src/github.com/couchbase/sync_gateway/rest/routing.go:236 +0x33f
net/http.HandlerFunc.ServeHTTP(0xc2081f5a20, 0x7f7fb3f56600, 0xc208199ae0, 0xc20802a9c0)
        /usr/lib/go/src/pkg/net/http/server.go:1235 +0x40
net/http.serverHandler.ServeHTTP(0xc20821d920, 0x7f7fb3f56600, 0xc208199ae0, 0xc20802a9c0)
        /usr/lib/go/src/pkg/net/http/server.go:1673 +0x19f
net/http.(*conn).serve(0xc208097800)
        /usr/lib/go/src/pkg/net/http/server.go:1174 +0xa7e
created by net/http.(*Server).Serve
        /usr/lib/go/src/pkg/net/http/server.go:1721 +0x313

Also panics when I try to access the view from the admin port.

2015-07-25T02:24:29.009Z HTTP:  #005: GET /quote-unquote/_design/new_quote/_view/new_quote  (ADMIN)
2015-07-25T02:24:29.009Z HTTP: JSON view "new_quote"/"new_quote" - opts map[]
2015/07/25 02:24:29 http: panic serving 208.107.235.44:49736: interface conversion: interface is string, not []interface {}
goroutine 57 [running]:
net/http.func·011()
        /usr/lib/go/src/pkg/net/http/server.go:1100 +0xb7
runtime.panic(0xa0f900, 0xc20826af40)
        /usr/lib/go/src/pkg/runtime/panic.c:248 +0x18d
github.com/couchbase/sync_gateway/db.filterViewResult(0x3, 0xc2081ffdc0, 0x3, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        /home/dbergan/sync_gateway/src/github.com/couchbase/sync_gateway/db/design_doc.go:140 +0x373
github.com/couchbase/sync_gateway/db.(*Database).QueryDesignDoc(0xc2081ff540, 0xc20826ab9b, 0x9, 0xc20826abab, 0x9, 0xc208156ab0, 0x3, 0x0,
 0x0)
        /home/dbergan/sync_gateway/src/github.com/couchbase/sync_gateway/db/design_doc.go:113 +0x569
github.com/couchbase/sync_gateway/rest.(*handler).handleView(0xc20826e6c0, 0x0, 0x0)
        /home/dbergan/sync_gateway/src/github.com/couchbase/sync_gateway/rest/view_api.go:104 +0x9ae
github.com/couchbase/sync_gateway/rest.(*handler).invoke(0xc20826e6c0, 0xd3e5f0, 0x0, 0x0)
        /home/dbergan/sync_gateway/src/github.com/couchbase/sync_gateway/rest/handler.go:159 +0x430
github.com/couchbase/sync_gateway/rest.func·015(0x7f7fb3f56600, 0xc208279220, 0xc2081dc340)
        /home/dbergan/sync_gateway/src/github.com/couchbase/sync_gateway/rest/handler.go:86 +0x7c
net/http.HandlerFunc.ServeHTTP(0xc2081fcba0, 0x7f7fb3f56600, 0xc208279220, 0xc2081dc340)
        /usr/lib/go/src/pkg/net/http/server.go:1235 +0x40
github.com/gorilla/mux.(*Router).ServeHTTP(0xc2080ae730, 0x7f7fb3f56600, 0xc208279220, 0xc2081dc340)
        /home/dbergan/sync_gateway/src/github.com/gorilla/mux/mux.go:86 +0x288
github.com/couchbase/sync_gateway/rest.func·017(0x7f7fb3f56600, 0xc208279220, 0xc2081dc340)
        /home/dbergan/sync_gateway/src/github.com/couchbase/sync_gateway/rest/routing.go:236 +0x33f
net/http.HandlerFunc.ServeHTTP(0xc2081baf60, 0x7f7fb3f56600, 0xc208279220, 0xc2081dc340)
        /usr/lib/go/src/pkg/net/http/server.go:1235 +0x40
net/http.serverHandler.ServeHTTP(0xc20821dbc0, 0x7f7fb3f56600, 0xc208279220, 0xc2081dc340)
        /usr/lib/go/src/pkg/net/http/server.go:1673 +0x19f
net/http.(*conn).serve(0xc20806e600)
        /usr/lib/go/src/pkg/net/http/server.go:1174 +0xa7e
created by net/http.(*Server).Serve
        /usr/lib/go/src/pkg/net/http/server.go:1721 +0x313

However, the view still works from the couchbase server administration interface.

Kind regards,
David

Nevermind. Works fine now.

It panic-ed because I was using the view PUT-ed from the 1.1.0 gateway. I ran

curl -vX PUT http://sync.gateway.ip.address:4985/{dbname}/_design/new_quote -H "Content-Type: application/json" -d @view.json

again on the github gateway, and now the view is working fine on both ports.

Carry on…

Kind regards,
David