Comment 2 for bug 1659153

Revision history for this message
Robert Ancell (robert-ancell) wrote :

The relevant part of the code is (daemon/api.go):

        query := r.URL.Query()
        q := query.Get("q")
        section := query.Get("section")
        name := query.Get("name")
        private := false
        prefix := false

        if name != "" {
                if q != "" {
                        return BadRequest("cannot use 'q' and 'name' together")
                }

                if name[len(name)-1] != '*' {
                        return findOne(c, r, user, name)
                }

                prefix = true
                q = name[:len(name)-1]
        }

        if sel := query.Get("select"); sel != "" {
                switch sel {
                case "refresh":
                        if prefix {
                                return BadRequest("cannot use 'name' with 'select=refresh'")
                        }
                        if q != "" {
                                return BadRequest("cannot use 'q' with 'select=refresh'")
                        }
                        return storeUpdates(c, r, user)
                case "private":
                        private = true
                }
        }

        theStore := getStore(c)
        found, err := theStore.Find(&store.Search{
                Query: q,
                Section: section,
                Private: private,
                Prefix: prefix,
        }, user)

The main issue seems to be if you pass ?name=&select= no BadRequest is generated because the function returns after findOne().

Also note the 'section' parameter is not documented in https://github.com/snapcore/snapd/wiki/REST-API