Skip to content

Commit 36d9523

Browse files
committed
opts: deprecate ValidateMACAddress
It was a wrapper around net.ParseMAC from stdlib, so users should use that directly. Signed-off-by: Sebastiaan van Stijn <[email protected]> (cherry picked from commit 17d6a92) Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 7063a0e commit 36d9523

File tree

3 files changed

+5
-16
lines changed

3 files changed

+5
-16
lines changed

cli/command/container/opts.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"encoding/json"
66
"fmt"
7+
"net"
78
"os"
89
"path"
910
"path/filepath"
@@ -350,7 +351,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
350351

351352
// Validate the input mac address
352353
if copts.macAddress != "" {
353-
if _, err := opts.ValidateMACAddress(copts.macAddress); err != nil {
354+
if _, err := net.ParseMAC(strings.TrimSpace(copts.macAddress)); err != nil {
354355
return nil, errors.Errorf("%s is not a valid mac address", copts.macAddress)
355356
}
356357
}
@@ -883,7 +884,7 @@ func parseNetworkAttachmentOpt(ep opts.NetworkAttachmentOpts) (*networktypes.End
883884
}
884885
}
885886
if ep.MacAddress != "" {
886-
if _, err := opts.ValidateMACAddress(ep.MacAddress); err != nil {
887+
if _, err := net.ParseMAC(strings.TrimSpace(ep.MacAddress)); err != nil {
887888
return nil, errors.Errorf("%s is not a valid mac address", ep.MacAddress)
888889
}
889890
epConfig.MacAddress = ep.MacAddress

opts/opts.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ func ValidateIPAddress(val string) (string, error) {
264264
}
265265

266266
// ValidateMACAddress validates a MAC address.
267+
//
268+
// Deprecated: use [net.ParseMAC]. This function will be removed in the next release.
267269
func ValidateMACAddress(val string) (string, error) {
268270
_, err := net.ParseMAC(strings.TrimSpace(val))
269271
if err != nil {

opts/opts_test.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -396,20 +396,6 @@ func TestNamedMapOpts(t *testing.T) {
396396
}
397397
}
398398

399-
func TestValidateMACAddress(t *testing.T) {
400-
if _, err := ValidateMACAddress(`92:d0:c6:0a:29:33`); err != nil {
401-
t.Fatalf("ValidateMACAddress(`92:d0:c6:0a:29:33`) got %s", err)
402-
}
403-
404-
if _, err := ValidateMACAddress(`92:d0:c6:0a:33`); err == nil {
405-
t.Fatalf("ValidateMACAddress(`92:d0:c6:0a:33`) succeeded; expected failure on invalid MAC")
406-
}
407-
408-
if _, err := ValidateMACAddress(`random invalid string`); err == nil {
409-
t.Fatalf("ValidateMACAddress(`random invalid string`) succeeded; expected failure on invalid MAC")
410-
}
411-
}
412-
413399
func TestValidateLink(t *testing.T) {
414400
valid := []string{
415401
"name",

0 commit comments

Comments
 (0)