summaryrefslogtreecommitdiff
path: root/pkg/api/handlers/utils
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-01-23 11:12:36 -0800
committerGitHub <noreply@github.com>2020-01-23 11:12:36 -0800
commit5bad873c4cd9fab9112e1d84ba376d47073cc8bb (patch)
treeec76af6eb70bebd52e861273228215480df0cbc2 /pkg/api/handlers/utils
parent8beeb067aac857deb29e91562cf4b6f068fe0328 (diff)
parentcf7be58b2c160e2e1df737015c913fc1aff1dbe8 (diff)
downloadpodman-5bad873c4cd9fab9112e1d84ba376d47073cc8bb.tar.gz
podman-5bad873c4cd9fab9112e1d84ba376d47073cc8bb.tar.bz2
podman-5bad873c4cd9fab9112e1d84ba376d47073cc8bb.zip
Merge pull request #4953 from baude/reviewcorrections2
Review corrections pass #2
Diffstat (limited to 'pkg/api/handlers/utils')
-rw-r--r--pkg/api/handlers/utils/containers.go21
-rw-r--r--pkg/api/handlers/utils/handler.go8
2 files changed, 28 insertions, 1 deletions
diff --git a/pkg/api/handlers/utils/containers.go b/pkg/api/handlers/utils/containers.go
index 64d3d378a..2c986db3a 100644
--- a/pkg/api/handlers/utils/containers.go
+++ b/pkg/api/handlers/utils/containers.go
@@ -6,6 +6,7 @@ import (
"syscall"
"time"
+ "github.com/containers/libpod/cmd/podman/shared"
"github.com/containers/libpod/libpod"
"github.com/containers/libpod/libpod/define"
"github.com/gorilla/mux"
@@ -83,7 +84,7 @@ func WaitContainer(w http.ResponseWriter, r *http.Request) (int32, error) {
}
if len(query.Condition) > 0 {
- return 0, errors.Errorf("the condition parameter is not supported")
+ UnSupportedParameter("condition")
}
name := mux.Vars(r)["name"]
@@ -101,3 +102,21 @@ func WaitContainer(w http.ResponseWriter, r *http.Request) (int32, error) {
}
return con.Wait()
}
+
+// GenerateFilterFuncsFromMap is used to generate un-executed functions that can be used to filter
+// containers. It is specifically designed for the RESTFUL API input.
+func GenerateFilterFuncsFromMap(r *libpod.Runtime, filters map[string][]string) ([]libpod.ContainerFilter, error) {
+ var (
+ filterFuncs []libpod.ContainerFilter
+ )
+ for k, v := range filters {
+ for _, val := range v {
+ f, err := shared.GenerateContainerFilterFuncs(k, val, r)
+ if err != nil {
+ return filterFuncs, err
+ }
+ filterFuncs = append(filterFuncs, f)
+ }
+ }
+ return filterFuncs, nil
+}
diff --git a/pkg/api/handlers/utils/handler.go b/pkg/api/handlers/utils/handler.go
index 2fd9bffba..f2ce26f1a 100644
--- a/pkg/api/handlers/utils/handler.go
+++ b/pkg/api/handlers/utils/handler.go
@@ -51,3 +51,11 @@ func WriteJSON(w http.ResponseWriter, code int, value interface{}) {
logrus.Errorf("unable to write json: %q", err)
}
}
+
+func FilterMapToString(filters map[string][]string) (string, error) {
+ f, err := json.Marshal(filters)
+ if err != nil {
+ return "", err
+ }
+ return string(f), nil
+}