Skip to content

Commit

Permalink
Store MAC as lowercase
Browse files Browse the repository at this point in the history
Signed-off-by: Jason DeTiberus <[email protected]>
  • Loading branch information
detiber committed Sep 4, 2020
1 parent c57d19b commit e124b4b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions grpc-server/hardware.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"strings"
"time"

"github.com/pkg/errors"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}
}
}

0 comments on commit e124b4b

Please sign in to comment.