mirror of
https://github.com/token2/snapd.git
synced 2026-03-13 11:15:47 -07:00
* store: Return categories in find results This allows clients to show the categories as snapcraft.io does. Fixes https://bugs.launchpad.net/snapd/+bug/1838786 * Remove unnecessary CategoryInfos type * Only show categories when using --verbose * Add tests for snap info printing categories * Update cmd/snap/cmd_info.go Co-authored-by: Miguel Pires <miguelpires94@gmail.com> * Update cmd/snap/cmd_info.go Co-authored-by: Miguel Pires <miguelpires94@gmail.com> * v1 store API doesn't return categories * Drop category information from snap info Other snap commands don't support categories yet, this change should be part of that. * Add /v2/categories and support /v2/find?category=foo * Add note that section is deprecated * Update client/packages.go Co-authored-by: Miguel Pires <miguelpires94@gmail.com> * Update daemon/api_categories.go Co-authored-by: Miguel Pires <miguelpires94@gmail.com> * Update daemon/api_categories.go Co-authored-by: Miguel Pires <miguelpires94@gmail.com> * Update daemon/api_categories.go Co-authored-by: Miguel Pires <miguelpires94@gmail.com> * Update store/store.go Co-authored-by: Miguel Pires <miguelpires94@gmail.com> * Update store/details_v2.go Co-authored-by: Miguel Pires <miguelpires94@gmail.com> * Update client/packages.go Co-authored-by: Miguel Pires <miguelpires94@gmail.com> * Improve test error message * Drop copy/pasted comments that doesn't seem relevant * Remove unused import * Reorder CategoryInfo struct * Fix accepted content type for store v2/snaps/categories request * Set APILevel for v2/snaps/categories request * Update accept string used to get data for store test * Make /v2/categories return objects not just strings --------- Co-authored-by: Miguel Pires <miguelpires94@gmail.com>
59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
// -*- Mode: Go; indent-tabs-mode: t -*-
|
|
|
|
/*
|
|
* Copyright (C) 2023 Canonical Ltd
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 3 as
|
|
* published by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*
|
|
*/
|
|
|
|
package daemon
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/snapcore/snapd/overlord/auth"
|
|
"github.com/snapcore/snapd/store"
|
|
)
|
|
|
|
var (
|
|
categoriesCmd = &Command{
|
|
Path: "/v2/categories",
|
|
GET: getCategories,
|
|
ReadAccess: openAccess{},
|
|
}
|
|
)
|
|
|
|
func getCategories(c *Command, r *http.Request, user *auth.UserState) Response {
|
|
route := c.d.router.Get(snapCmd.Path)
|
|
if route == nil {
|
|
return InternalError("cannot find route for categories")
|
|
}
|
|
|
|
theStore := storeFrom(c.d)
|
|
|
|
categories, err := theStore.Categories(r.Context(), user)
|
|
switch err {
|
|
case nil:
|
|
// pass
|
|
case store.ErrBadQuery:
|
|
return BadQuery()
|
|
case store.ErrUnauthenticated, store.ErrInvalidCredentials:
|
|
return Unauthorized("%v", err)
|
|
default:
|
|
return InternalError("%v", err)
|
|
}
|
|
|
|
return SyncResponse(categories)
|
|
}
|