diff options
author | Eric Multanen <eric.w.multanen@intel.com> | 2020-04-08 12:01:24 -0700 |
---|---|---|
committer | Eric Multanen <eric.w.multanen@intel.com> | 2020-04-08 12:01:24 -0700 |
commit | eafe59ee894f6bb42d090a2aad42323e67243b4f (patch) | |
tree | 4cf2c8d1ecb7e0b06c6f5949d3b8b9ae86a857ca /src/orchestrator/pkg/infra/validation/validation.go | |
parent | ee5748eca6350222051125b5e2313f78da00efbe (diff) |
Add validation routines
Splitting out new orchestration validation routines
from other patch for ncm which uses them - so these
changes can go in first. Should fix build issues.
Issue-ID: MULTICLOUD-1029
Signed-off-by: Eric Multanen <eric.w.multanen@intel.com>
Change-Id: I89c4163e1204d444e48a4786acececa20fce1844
Diffstat (limited to 'src/orchestrator/pkg/infra/validation/validation.go')
-rw-r--r-- | src/orchestrator/pkg/infra/validation/validation.go | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/orchestrator/pkg/infra/validation/validation.go b/src/orchestrator/pkg/infra/validation/validation.go index d744dc3d..03b37fa1 100644 --- a/src/orchestrator/pkg/infra/validation/validation.go +++ b/src/orchestrator/pkg/infra/validation/validation.go @@ -70,21 +70,37 @@ func IsTarGz(r io.Reader) error { } func IsIpv4Cidr(cidr string) error { - _, _, err := net.ParseCIDR(cidr) - if err != nil { - return pkgerrors.Wrapf(err, "could not parse subnet %v", cidr) + ip, _, err := net.ParseCIDR(cidr) + if err != nil || ip.To4() == nil { + return pkgerrors.Wrapf(err, "could not parse ipv4 cidr %v", cidr) } return nil } -func IsIpv4(ip string) error { +func IsIp(ip string) error { addr := net.ParseIP(ip) if addr == nil { + return pkgerrors.Errorf("invalid ip address %v", ip) + } + return nil +} + +func IsIpv4(ip string) error { + addr := net.ParseIP(ip) + if addr == nil || addr.To4() == nil { return pkgerrors.Errorf("invalid ipv4 address %v", ip) } return nil } +func IsMac(mac string) error { + _, err := net.ParseMAC(mac) + if err != nil { + return pkgerrors.Errorf("invalid MAC address %v", mac) + } + return nil +} + // default name check - matches valid label value with addtion that length > 0 func IsValidName(name string) []string { var errs []string |