mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 11:03:34 +00:00
fix filter unmarshalling for list containers
This commit is contained in:
@@ -126,6 +126,10 @@ func (c *Client) ListContainers(ctx context.Context, opts container.ListOptions)
|
||||
machineContainers := make([]MachineContainers, len(resp.Messages))
|
||||
for i, msg := range resp.Messages {
|
||||
machineContainers[i].Metadata = msg.Metadata
|
||||
if msg.Metadata != nil && msg.Metadata.Error != "" {
|
||||
continue
|
||||
}
|
||||
|
||||
if err = json.Unmarshal(msg.Containers, &machineContainers[i].Containers); err != nil {
|
||||
return nil, fmt.Errorf("unmarshal containers: %w", err)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"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/network"
|
||||
"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 {
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user