mirror of
https://github.com/containers/podman.git
synced 2025-06-25 03:52:15 +08:00
Fix container filters
container filters were being double encoded (maybe triple) which resulted in the wrong encoding representation of filters being sent by the go-bindings. Also, on the server side, Filter needed to be changed to Filter to decode properly. Finally, due to the changed return type of List Containers, the go bindings return values needed to be changed. Signed-off-by: Brent Baude <bbaude@redhat.com>
This commit is contained in:
@ -56,7 +56,7 @@ func ListContainers(w http.ResponseWriter, r *http.Request) {
|
|||||||
decoder := r.Context().Value("decoder").(*schema.Decoder)
|
decoder := r.Context().Value("decoder").(*schema.Decoder)
|
||||||
query := struct {
|
query := struct {
|
||||||
All bool `schema:"all"`
|
All bool `schema:"all"`
|
||||||
Filter map[string][]string `schema:"filter"`
|
Filters map[string][]string `schema:"filters"`
|
||||||
Last int `schema:"last"`
|
Last int `schema:"last"`
|
||||||
Namespace bool `schema:"namespace"`
|
Namespace bool `schema:"namespace"`
|
||||||
Pod bool `schema:"pod"`
|
Pod bool `schema:"pod"`
|
||||||
@ -71,6 +71,7 @@ func ListContainers(w http.ResponseWriter, r *http.Request) {
|
|||||||
errors.Wrapf(err, "Failed to parse parameters for %s", r.URL.String()))
|
errors.Wrapf(err, "Failed to parse parameters for %s", r.URL.String()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
runtime := r.Context().Value("runtime").(*libpod.Runtime)
|
runtime := r.Context().Value("runtime").(*libpod.Runtime)
|
||||||
opts := shared.PsOptions{
|
opts := shared.PsOptions{
|
||||||
All: query.All,
|
All: query.All,
|
||||||
@ -82,8 +83,8 @@ func ListContainers(w http.ResponseWriter, r *http.Request) {
|
|||||||
Pod: query.Pod,
|
Pod: query.Pod,
|
||||||
Sync: query.Sync,
|
Sync: query.Sync,
|
||||||
}
|
}
|
||||||
if len(query.Filter) > 0 {
|
if len(query.Filters) > 0 {
|
||||||
for k, v := range query.Filter {
|
for k, v := range query.Filters {
|
||||||
for _, val := range v {
|
for _, val := range v {
|
||||||
generatedFunc, err := shared.GenerateContainerFilterFuncs(k, val, runtime)
|
generatedFunc, err := shared.GenerateContainerFilterFuncs(k, val, runtime)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -130,7 +130,7 @@ func (c *Connection) DoRequest(httpBody io.Reader, httpMethod, endpoint string,
|
|||||||
// if more desirable we could use url to form the encoded endpoint with params
|
// if more desirable we could use url to form the encoded endpoint with params
|
||||||
r := req.URL.Query()
|
r := req.URL.Query()
|
||||||
for k, v := range queryParams {
|
for k, v := range queryParams {
|
||||||
r.Add(k, url.QueryEscape(v))
|
r.Add(k, v)
|
||||||
}
|
}
|
||||||
req.URL.RawQuery = r.Encode()
|
req.URL.RawQuery = r.Encode()
|
||||||
}
|
}
|
||||||
@ -155,18 +155,14 @@ func GetConnectionFromContext(ctx context.Context) (*Connection, error) {
|
|||||||
return conn, nil
|
return conn, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// FiltersToHTML converts our typical filter format of a
|
// FiltersToString converts our typical filter format of a
|
||||||
// map[string][]string to a query/html safe string.
|
// map[string][]string to a query/html safe string.
|
||||||
func FiltersToHTML(filters map[string][]string) (string, error) {
|
func FiltersToString(filters map[string][]string) (string, error) {
|
||||||
lowerCaseKeys := make(map[string][]string)
|
lowerCaseKeys := make(map[string][]string)
|
||||||
for k, v := range filters {
|
for k, v := range filters {
|
||||||
lowerCaseKeys[strings.ToLower(k)] = v
|
lowerCaseKeys[strings.ToLower(k)] = v
|
||||||
}
|
}
|
||||||
unsafeString, err := jsoniter.MarshalToString(lowerCaseKeys)
|
return jsoniter.MarshalToString(lowerCaseKeys)
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return url.QueryEscape(unsafeString), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsInformation returns true if the response code is 1xx
|
// IsInformation returns true if the response code is 1xx
|
||||||
|
@ -5,8 +5,8 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/containers/libpod/cmd/podman/shared"
|
|
||||||
"github.com/containers/libpod/libpod"
|
"github.com/containers/libpod/libpod"
|
||||||
|
lpapiv2 "github.com/containers/libpod/pkg/api/handlers/libpod"
|
||||||
"github.com/containers/libpod/pkg/bindings"
|
"github.com/containers/libpod/pkg/bindings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -15,13 +15,16 @@ import (
|
|||||||
// the most recent number of containers. The pod and size booleans indicate that pod information and rootfs
|
// the most recent number of containers. The pod and size booleans indicate that pod information and rootfs
|
||||||
// size information should also be included. Finally, the sync bool synchronizes the OCI runtime and
|
// size information should also be included. Finally, the sync bool synchronizes the OCI runtime and
|
||||||
// container state.
|
// container state.
|
||||||
func List(ctx context.Context, filters map[string][]string, last *int, pod, size, sync *bool) ([]*shared.PsContainerOutput, error) { // nolint:typecheck
|
func List(ctx context.Context, filters map[string][]string, all *bool, last *int, pod, size, sync *bool) ([]lpapiv2.ListContainer, error) { // nolint:typecheck
|
||||||
conn, err := bindings.GetConnectionFromContext(ctx)
|
conn, err := bindings.GetConnectionFromContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var images []*shared.PsContainerOutput
|
var containers []lpapiv2.ListContainer
|
||||||
params := make(map[string]string)
|
params := make(map[string]string)
|
||||||
|
if all != nil {
|
||||||
|
params["all"] = strconv.FormatBool(*all)
|
||||||
|
}
|
||||||
if last != nil {
|
if last != nil {
|
||||||
params["last"] = strconv.Itoa(*last)
|
params["last"] = strconv.Itoa(*last)
|
||||||
}
|
}
|
||||||
@ -35,7 +38,7 @@ func List(ctx context.Context, filters map[string][]string, last *int, pod, size
|
|||||||
params["sync"] = strconv.FormatBool(*sync)
|
params["sync"] = strconv.FormatBool(*sync)
|
||||||
}
|
}
|
||||||
if filters != nil {
|
if filters != nil {
|
||||||
filterString, err := bindings.FiltersToHTML(filters)
|
filterString, err := bindings.FiltersToString(filters)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -43,9 +46,9 @@ func List(ctx context.Context, filters map[string][]string, last *int, pod, size
|
|||||||
}
|
}
|
||||||
response, err := conn.DoRequest(nil, http.MethodGet, "/containers/json", params)
|
response, err := conn.DoRequest(nil, http.MethodGet, "/containers/json", params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return images, err
|
return containers, err
|
||||||
}
|
}
|
||||||
return images, response.Process(nil)
|
return containers, response.Process(&containers)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prune removes stopped and exited containers from local storage. The optional filters can be
|
// Prune removes stopped and exited containers from local storage. The optional filters can be
|
||||||
@ -62,7 +65,7 @@ func Prune(ctx context.Context, filters map[string][]string) ([]string, error) {
|
|||||||
}
|
}
|
||||||
params := make(map[string]string)
|
params := make(map[string]string)
|
||||||
if filters != nil {
|
if filters != nil {
|
||||||
filterString, err := bindings.FiltersToHTML(filters)
|
filterString, err := bindings.FiltersToString(filters)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ func List(ctx context.Context, all *bool, filters map[string][]string) ([]*handl
|
|||||||
params["all"] = strconv.FormatBool(*all)
|
params["all"] = strconv.FormatBool(*all)
|
||||||
}
|
}
|
||||||
if filters != nil {
|
if filters != nil {
|
||||||
strFilters, err := bindings.FiltersToHTML(filters)
|
strFilters, err := bindings.FiltersToString(filters)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -155,7 +155,7 @@ func Prune(ctx context.Context, filters map[string][]string) ([]string, error) {
|
|||||||
}
|
}
|
||||||
params := make(map[string]string)
|
params := make(map[string]string)
|
||||||
if filters != nil {
|
if filters != nil {
|
||||||
stringFilter, err := bindings.FiltersToHTML(filters)
|
stringFilter, err := bindings.FiltersToString(filters)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ func Search(ctx context.Context, term string, limit *int, filters map[string][]s
|
|||||||
params["limit"] = strconv.Itoa(*limit)
|
params["limit"] = strconv.Itoa(*limit)
|
||||||
}
|
}
|
||||||
if filters != nil {
|
if filters != nil {
|
||||||
stringFilter, err := bindings.FiltersToHTML(filters)
|
stringFilter, err := bindings.FiltersToString(filters)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ func List(ctx context.Context, filters map[string][]string) (*[]libpod.PodInspec
|
|||||||
}
|
}
|
||||||
params := make(map[string]string)
|
params := make(map[string]string)
|
||||||
if filters != nil {
|
if filters != nil {
|
||||||
stringFilter, err := bindings.FiltersToHTML(filters)
|
stringFilter, err := bindings.FiltersToString(filters)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user