diff --git a/grpc-server/hardware.go b/grpc-server/hardware.go index 884c5b9a0..dffd492b7 100644 --- a/grpc-server/hardware.go +++ b/grpc-server/hardware.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "strings" "time" "github.com/pkg/errors" @@ -38,6 +39,9 @@ func (s *server) Push(ctx context.Context, in *hardware.PushRequest) (*hardware. return &hardware.Empty{}, err } + // normalize data prior to storing in the database + s.normalizeHardwareData(hw) + // validate the hardware data to avoid duplicate mac address err := s.validateHardwareData(ctx, hw) if err != nil { @@ -316,3 +320,14 @@ func (s *server) validateHardwareData(ctx context.Context, hw *hardware.Hardware } return nil } + +func (s *server) normalizeHardwareData(hw *hardware.Hardware) { + // Ensure MAC is stored as lowercase + if hw != nil && hw.Network != nil { + for i := range hw.Network.Interfaces { + if hw.Network.Interfaces[i].Dhcp != nil { + hw.Network.Interfaces[i].Dhcp.Mac = strings.ToLower(hw.Network.Interfaces[i].Dhcp.Mac) + } + } + } +}