mirror of
https://github.com/psviderski/uncloud.git
synced 2026-10-08 22:24:54 +00:00
fix filter unmarshalling for list containers
This commit is contained in:
1 parent
00dbbec62b
commit
c0dff56378
2 files changed
+19
No files matched your search
@@ -126,6 +126,10 @@ func (c *Client) ListContainers(ctx context.Context, opts container.ListOptions)
|
|||||||
machineContainers := make([]MachineContainers, len(resp.Messages))
|
machineContainers := make([]MachineContainers, len(resp.Messages))
|
||||||
for i, msg := range resp.Messages {
|
for i, msg := range resp.Messages {
|
||||||
machineContainers[i].Metadata = msg.Metadata
|
machineContainers[i].Metadata = msg.Metadata
|
||||||
|
if msg.Metadata != nil && msg.Metadata.Error != "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if err = json.Unmarshal(msg.Containers, &machineContainers[i].Containers); err != nil {
|
if err = json.Unmarshal(msg.Containers, &machineContainers[i].Containers); err != nil {
|
||||||
return nil, fmt.Errorf("unmarshal containers: %w", err)
|
return nil, fmt.Errorf("unmarshal containers: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
|
"github.com/docker/docker/api/types/filters"
|
||||||
"github.com/docker/docker/api/types/image"
|
"github.com/docker/docker/api/types/image"
|
||||||
"github.com/docker/docker/api/types/network"
|
"github.com/docker/docker/api/types/network"
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
@@ -87,6 +88,20 @@ func (s *Server) ListContainers(ctx context.Context, req *pb.ListContainersReque
|
|||||||
if err := json.Unmarshal(req.Options, &opts); err != nil {
|
if err := json.Unmarshal(req.Options, &opts); err != nil {
|
||||||
return nil, status.Errorf(codes.InvalidArgument, "unmarshal options: %v", err)
|
return nil, status.Errorf(codes.InvalidArgument, "unmarshal options: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle filters separately because they implement custom JSON unmarshalling.
|
||||||
|
var raw map[string]json.RawMessage
|
||||||
|
if err := json.Unmarshal(req.Options, &raw); err != nil {
|
||||||
|
return nil, status.Errorf(codes.InvalidArgument, "unmarshal options to raw map: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if filtersBytes, ok := raw["Filters"]; ok {
|
||||||
|
args, err := filters.FromJSON(string(filtersBytes))
|
||||||
|
if err != nil {
|
||||||
|
return nil, status.Errorf(codes.InvalidArgument, "unmarshal filters: %v", err)
|
||||||
|
}
|
||||||
|
opts.Filters = args
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
containers, err := s.client.ContainerList(ctx, opts)
|
containers, err := s.client.ContainerList(ctx, opts)
|
||||||
|
|||||||
Reference in new issue
Block a user