vv9k / podman-api-rs

Rust interface to Podman (libpod).
MIT License
84 stars 12 forks source link

Regression in constructing JSON filters #131

Closed marhkb closed 2 years ago

marhkb commented 2 years ago

For example, a deserialized container filter now looks like

{"id":["id=0c24b5b39bab46f79c7b763a21f4562692400af0963e4e82d2f4d58c4e1aaffa"]}

But it should look like

{"id":["i0c24b5b39bab46f79c7b763a21f4562692400af0963e4e82d2f4d58c4e1aaffa"]}

So, if we URL encode the first JSON, we don't retrieve any containers

$ curl --unix-socket /run/user/1000/podman/podman.sock http://d/v3.0.0/libpod/containers/json\?all\=true\&filters=%7B%22id%22%3A%5B%22id%3Da9ee744d373ad80a280f66cb3fdcd443b9320482ce1d32c9999c3ae1806116d5%22%5D%7D
[]

If we remove the id= part, we retrieve the correct result.

$ curl --unix-socket /run/user/1000/podman/podman.sock http://d/v3.0.0/libpod/containers/json\?all\=true\&filters=%7B%22id%22%3A%5B%220c24b5b39bab46f79c7b763a21f4562692400af0963e4e82d2f4d58c4e1aaffa%22%5D%7D
[{"AutoRemove":false,"Command":["mongod"],"Created":"2022-08-27T21:10:48.274351047+02:00","CreatedAt":"","Exited":false,"ExitedAt":-62135596800,"ExitCode":0,"Id":"0c24b5b39bab46f79c7b763a21f4562692400af0963e4e82d2f4d58c4e1aaffa","Image":"docker.io/library/mongo:latest","ImageID":"a3c1334134aafd75500fbfe5cddbc0bde4d628725cb074bf988edbbad2cf0acc","IsInfra":false,"Labels":null,"Mounts":["/data/configdb","/data/db"],"Names":["TEST_PODMAN_API_RS"],"Namespaces":{},"Networks":[],"Pid":709080,"Pod":"","PodName":"","Ports":[{"host_ip":"","container_port":27017,"host_port":27017,"range":1,"protocol":"tcp"}],"Size":null,"StartedAt":1661627448,"State":"running","Status":"healthy"}]
vv9k commented 2 years ago

Fixed this in https://github.com/vv9k/containers-api/commit/e407b14c671253eb53a49c2370a685d0c1df6a94 and e1c937675a9eb5f88131b9bce89899e6ccff1628 . Also added tests to prevent future regressions https://github.com/vv9k/containers-api/commit/ca80b56aa8de7a9066e97d718bb90ec5433db733 .

I was wondering how to handle the label!=key=value filters and it turns out the key in the map has to be label! for this to work, so my concept made no sense. More info about this filters here: https://github.com/containers/podman/issues/13270

marhkb commented 2 years ago

Thanks. This fixes it for me.