validate machine info before returning in ListMachine

This commit is contained in:
Pavel Sviderski
2024-11-10 19:38:55 +10:00
parent 5c74b09f45
commit c70c8a6ec1
+5
View File
@@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"google.golang.org/protobuf/encoding/protojson"
"log/slog"
"uncloud/internal/corrosion"
"uncloud/internal/machine/api/pb"
)
@@ -77,6 +78,10 @@ func (s *Store) ListMachines(ctx context.Context) ([]*pb.MachineInfo, error) {
if err = protojson.Unmarshal([]byte(mJSON), &m); err != nil {
return nil, fmt.Errorf("unmarshal machine info: %w", err)
}
if err = m.Network.Validate(); err != nil {
slog.Error("Invalid network configuration for machine in store", "id", m.Id, "error", err)
continue
}
machines = append(machines, &m)
}
return machines, nil