validation

package
v0.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 23, 2026 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package validation provides validation functions for Megaport resources and configurations. It contains utilities to validate inputs for Megaport API calls, ensuring that input parameters meet required criteria before they are submitted to the API.

Index

Constants

View Source
const (
	// MaxPortNameLength defines the maximum length of a port name in characters.
	MaxPortNameLength = 64
	// MaxAWSConnectionNameLength is the maximum allowed length of an AWS connection name.
	MaxAWSConnectionNameLength = 255
	// MaxMVENameLength defines the maximum length of an MVE name in characters.
	MaxMVENameLength = 64
	// AutoAssignVLAN indicates the VLAN should be automatically assigned by the system.
	AutoAssignVLAN = 0
	// UntaggedVLAN indicates packets should be untagged (no VLAN tag).
	UntaggedVLAN = -1
	// MinAssignableVLAN is the lowest VLAN ID that can be assigned to traffic.
	MinAssignableVLAN = 2
	// MaxAssignableVLAN is the highest VLAN ID that can typically be assigned by users.
	MaxAssignableVLAN = 4093
	// MaxVLAN is the maximum possible VLAN ID according to IEEE 802.1Q.
	MaxVLAN = 4094
	// ReservedVLAN identifies a VLAN ID that is reserved and cannot be used.
	ReservedVLAN = 1
	// MinASN is the minimum valid Autonomous System Number.
	MinASN int64 = 1
	// MaxASN is the maximum valid 32-bit Autonomous System Number.
	MaxASN int64 = 4294967295
)
View Source
const (
	// MinASPathPrependCount is the minimum allowed AS path prepend count in BGP configurations.
	MinASPathPrependCount = 0
	// MaxASPathPrependCount is the maximum allowed AS path prepend count in BGP configurations.
	MaxASPathPrependCount = 10
	// MinBFDInterval is the minimum Bidirectional Forwarding Detection interval in milliseconds.
	MinBFDInterval = 300
	// MaxBFDInterval is the maximum Bidirectional Forwarding Detection interval in milliseconds.
	MaxBFDInterval = 30000
	// MinBFDMultiplier is the minimum Bidirectional Forwarding Detection multiplier value.
	MinBFDMultiplier = 3
	// MaxBFDMultiplier is the maximum Bidirectional Forwarding Detection multiplier value.
	MaxBFDMultiplier = 20
	// MinMED is the minimum Multi-Exit Discriminator value for BGP routing.
	MinMED = 0
	// MaxMED is the maximum Multi-Exit Discriminator value for BGP routing.
	// Using int64 to avoid overflow on 32-bit platforms.
	MaxMED int64 = 4294967295
	// BGPPeerNonCloud identifies a non-cloud BGP peer type.
	BGPPeerNonCloud = "NON_CLOUD"
	// BGPPeerPrivCloud identifies a private cloud BGP peer type.
	BGPPeerPrivCloud = "PRIV_CLOUD"
	// BGPPeerPubCloud identifies a public cloud BGP peer type.
	BGPPeerPubCloud = "PUB_CLOUD"
	// BGPExportPolicyPermit defines the permit policy for BGP route exports.
	BGPExportPolicyPermit = "permit"
	// BGPExportPolicyDeny defines the deny policy for BGP route exports.
	BGPExportPolicyDeny = "deny"
	// MaxIBMNameLength is the maximum allowed length of an IBM connection name.
	MaxIBMNameLength = 100
	// IBMAccountIDLength is the required length of an IBM account ID.
	IBMAccountIDLength = 32
	// AWSConnectTypeAWS denotes a standard AWS connection type.
	AWSConnectTypeAWS = "AWS"
	// AWSConnectTypeAWSHC denotes a high-capacity AWS connection type.
	AWSConnectTypeAWSHC = "AWSHC"
	// AWSConnectTypeTransit denotes a transit AWS connection type.
	AWSConnectTypeTransit = "transit"
	// AWSConnectTypePrivate denotes a private AWS connection type.
	AWSConnectTypePrivate = "private"
	// AWSConnectTypePublic denotes a public AWS connection type.
	AWSConnectTypePublic = "public"
)

Variables

View Source
var (
	// ValidContractTerms lists the allowed contract term durations in months.
	ValidContractTerms = []int{1, 12, 24, 36}
	// ValidMCRPortSpeeds lists the supported MCR port speeds in Mbps.
	ValidMCRPortSpeeds = []int{1000, 2500, 5000, 10000, 25000, 50000, 100000}
	// ValidPortSpeeds lists the supported port speeds in Mbps.
	ValidPortSpeeds = []int{1000, 10000, 100000}
	// ValidMVEProductSizes lists the supported MVE product sizes.
	ValidMVEProductSizes = []string{"SMALL", "MEDIUM", "LARGE", "X_LARGE_12"}
)
View Source
var (
	ValidLAGPortSpeeds = []int{10000, 100000}
	MinLAGCount        = 1
	MaxLAGCount        = 8
)

Define constants for LAG validation

View Source
var MVELabelToProductSize = map[string]string{
	"MVE 2/8":   "SMALL",
	"MVE 4/16":  "MEDIUM",
	"MVE 8/32":  "LARGE",
	"MVE 12/48": "X_LARGE_12",
}

MVELabelToProductSize maps human-readable MVE size labels (as returned by the images API in the availableSizes field) to their canonical programmatic names.

View Source
var (
	ValidMVEVendors = []string{
		"6wind",
		"aruba",
		"aviatrix",
		"cisco",
		"fortinet",
		"palo_alto",
		"prisma",
		"versa",
		"vmware",
		"meraki",
	}
)

Functions

func ExtractFieldsWithTypes

func ExtractFieldsWithTypes(config map[string]interface{}, fields map[string]string) map[string]interface{}

ExtractFieldsWithTypes extracts fields from a configuration map according to their expected types. This helper function is used to convert untyped map data (typically from JSON deserialization) to correctly typed fields for further processing or validation. It handles type conversion intelligently based on the specified expected types.

Parameters:

  • config: A map containing mixed type values, typically from JSON deserialization
  • fields: A map where key is the field name and value is the expected type name

Supported type names in the fields map:

  • "string": Extracts the value as a string
  • "int": Extracts the value as an integer
  • "bool": Extracts the value as a boolean
  • "string_slice": Extracts the value as a slice of strings/interfaces
  • "map_slice": Extracts the value as a slice of map[string]interface{}

The function calls the appropriate type conversion helper function for each field based on the specified expected type.

Returns:

  • A new map with the extracted values, correctly typed according to the fields map

Example:

config := map[string]interface{}{
    "name": "test",
    "port": 8080,
    "enabled": true,
    "tags": []interface{}{"tag1", "tag2"},
}
fields := map[string]string{
    "name": "string",
    "port": "int",
    "enabled": "bool",
    "tags": "string_slice",
}
result := ExtractFieldsWithTypes(config, fields)
// result will contain the extracted values with proper types

func FormatIntSlice added in v0.7.0

func FormatIntSlice(vals []int) string

FormatIntSlice formats a slice of ints as a human-readable string. Example: []int{1, 12, 24, 36} → "1, 12, 24, or 36"

func GetBoolFromInterface

func GetBoolFromInterface(value interface{}) (bool, bool)

GetBoolFromInterface attempts to convert an interface{} value to a bool. Returns the converted bool value and a boolean indicating success.

func GetFloatFromInterface

func GetFloatFromInterface(value interface{}) (float64, bool)

GetFloatFromInterface attempts to convert an interface{} value to a float64. Returns the converted float64 value and a boolean indicating success.

func GetIntFromInterface

func GetIntFromInterface(value interface{}) (int, bool)

GetIntFromInterface attempts to convert an interface{} value to an int. Returns the converted int value and a boolean indicating success.

func GetMapStringInterfaceFromInterface

func GetMapStringInterfaceFromInterface(value interface{}) (map[string]interface{}, bool)

GetMapStringInterfaceFromInterface attempts to convert an interface{} value to a map[string]interface{}. Returns the converted map and a boolean indicating success.

func GetSliceInterfaceFromInterface

func GetSliceInterfaceFromInterface(value interface{}) ([]interface{}, bool)

GetSliceInterfaceFromInterface attempts to convert an interface{} value to a []interface{}. Returns the converted slice and a boolean indicating success.

func GetSliceMapStringInterfaceFromInterface

func GetSliceMapStringInterfaceFromInterface(value interface{}) ([]map[string]interface{}, bool)

GetSliceMapStringInterfaceFromInterface attempts to convert an interface{} value to a []map[string]interface{}. Handles both direct slice conversions and conversion of []interface{} where each element is a map. Returns the converted slice of maps and a boolean indicating success.

func GetStringFromInterface

func GetStringFromInterface(value interface{}) (string, bool)

GetStringFromInterface attempts to convert an interface{} value to a string. Returns the converted string value and a boolean indicating success.

func InnerVLANHelpText added in v0.9.0

func InnerVLANHelpText() string

InnerVLANHelpText returns a canonical human-readable description of valid inner VLAN (Q-in-Q) values. Inner VLANs use 0 to mean "no inner VLAN" rather than "auto-assign".

func IsValidationError

func IsValidationError(err error) bool

IsValidationError checks if an error is an instance of ValidationError. Returns true if the error is a ValidationError, false otherwise.

func NormalizeMVEProductSize added in v0.11.0

func NormalizeMVEProductSize(size string) string

NormalizeMVEProductSize converts an MVE product size to its canonical form. It accepts both programmatic names ("SMALL") and human-readable labels ("MVE 2/8") as returned by the list-images API.

func ParseInt added in v0.13.0

func ParseInt(field, value string) (int, error)

ParseInt converts a user-supplied string into an int. On failure it returns a friendly error naming the field and the offending value, instead of leaking strconv internals like `strconv.Atoi: parsing "x": invalid syntax`.

The message keeps the lowercase "invalid <field>" prefix so exit-code classification still tags it as a usage error. For ID arguments the field should contain "ID" (e.g. "location ID") so that classification holds.

func VLANHelpText added in v0.9.0

func VLANHelpText() string

VLANHelpText returns a canonical human-readable description of valid VLAN values, derived from the VLAN constants defined in this package.

func ValidateASN added in v0.13.0

func ValidateASN(asn int) error

ValidateASN validates if an ASN (Autonomous System Number) is within the supported range for the current build target.

Parameters:

  • asn: The ASN to validate

Validation checks:

  • ASN must be between MinASN (1) and the lesser of MaxASN (4294967295) and the current target's maximum int value, inclusive.

Returns:

  • A ValidationError if the ASN is not valid
  • nil if the validation passes

func ValidateAWSPartnerConfig

func ValidateAWSPartnerConfig(config *megaport.VXCPartnerConfigAWS) error

ValidateAWSPartnerConfig validates an AWS partner configuration for a VXC connection. This function ensures the AWS-specific connection parameters meet all requirements.

Parameters:

  • config: The AWS partner configuration to validate

Validation checks include:

  • Connect type must be provided and be one of the valid types ('AWS', 'AWSHC', 'private', 'public')
  • Owner account must be provided (AWS account ID)
  • ASN must be provided and within the valid range (1-4294967295)
  • If customer IP address is provided, it must be in valid IPv4 CIDR notation
  • If Amazon IP address is provided, it must be in valid IPv4 CIDR notation
  • If connection name is provided, it must not exceed 255 characters
  • For 'AWS' connect type with a specified connection type, it must be 'private' or 'public'

Returns:

  • A ValidationError if any validation check fails
  • nil if all validation checks pass

func ValidateArubaConfig

func ValidateArubaConfig(config *megaport.ArubaConfig) error

ValidateArubaConfig validates an Aruba configuration for an MVE deployment. This function ensures all required parameters for an Aruba virtual appliance are provided.

Parameters:

  • config: The Aruba configuration to validate

Validation checks:

  • Image ID must be a positive integer
  • Product size must be valid (calls ValidateMVEProductSize)
  • Account name must be provided
  • Account key must be provided
  • System tag must be provided

Returns:

  • A ValidationError if any validation check fails
  • nil if all validation checks pass

func ValidateAviatrixConfig

func ValidateAviatrixConfig(config *megaport.AviatrixConfig) error

ValidateAviatrixConfig validates an Aviatrix configuration for an MVE deployment. This function ensures all required parameters for an Aviatrix virtual appliance are provided.

Parameters:

  • config: The Aviatrix configuration to validate

Validation checks:

  • Image ID must be a positive integer
  • Product size must be valid (calls ValidateMVEProductSize)
  • Cloud init data must be provided (for initial configuration)

Returns:

  • A ValidationError if any validation check fails
  • nil if all validation checks pass

func ValidateAzurePartnerConfig

func ValidateAzurePartnerConfig(config *megaport.VXCPartnerConfigAzure) error

ValidateAzurePartnerConfig validates an Azure partner configuration for a VXC connection. This function ensures the Azure-specific connection parameters meet all requirements.

Parameters:

  • config: The Azure partner configuration to validate

Validation checks include:

  • Configuration cannot be nil
  • Service key must be provided (required for Azure connections)
  • For each peer, at least one of primary_subnet or secondary_subnet must be provided
  • For each peer, VLAN must be provided and valid

Returns:

  • A ValidationError if any validation check fails
  • nil if all validation checks pass

func ValidateBFDConfig

func ValidateBFDConfig(bfd megaport.BfdConfig, ifaceIndex int) error

ValidateBFDConfig validates a Bidirectional Forwarding Detection (BFD) configuration. BFD is a network protocol used to detect link failures between adjacent forwarding engines. This function ensures that BFD parameters are within acceptable ranges for stable operation.

Parameters:

  • bfd: The BFD configuration to validate, containing interval and multiplier settings
  • ifaceIndex: The index of the interface this BFD configuration belongs to (used for error messages)

Validation checks include:

  • TX interval (transmission interval) must be within allowed range (300-30000 milliseconds)
  • RX interval (receive interval) must be within allowed range (300-30000 milliseconds)
  • Multiplier must be within allowed range (3-20)
  • Zero values are allowed and considered as "not specified"

Returns:

  • A ValidationError if any validation check fails
  • nil if all validation checks pass

func ValidateBGPConnectionConfig

func ValidateBGPConnectionConfig(conn megaport.BgpConnectionConfig, ifaceIndex, connIndex int) error

ValidateBGPConnectionConfig validates the configuration for a BGP (Border Gateway Protocol) connection. This function performs comprehensive validation of all BGP connection parameters to ensure they meet the requirements for establishing BGP peering sessions in a vRouter interface.

Parameters:

  • conn: The BGP connection configuration to validate
  • ifaceIndex: The index of the interface this BGP connection belongs to (used for error messages)
  • connIndex: The index of this BGP connection within the interface (used for error messages)

Validation checks include:

  • Peer ASN must be provided and within the valid range (1-4294967295)
  • Local IP address must be provided and be a valid IPv4 address or IPv4 CIDR
  • Peer IP address must be provided and be a valid IPv4 address or IPv4 CIDR
  • If Peer Type is provided, it must be one of the predefined values (NON_CLOUD, PRIV_CLOUD, PUB_CLOUD)
  • If MED values (Multi-Exit Discriminator) are provided, they must be within allowed range (0-4294967295)
  • If AS path prepend count is provided, it must be within allowed range (0-10)
  • If Export Policy is provided, it must be either "permit" or "deny"

Returns:

  • A ValidationError if any validation check fails
  • nil if all validation checks pass

func ValidateBuyMVERequest

func ValidateBuyMVERequest(req *megaport.BuyMVERequest) error

ValidateBuyMVERequest validates a request to buy/provision a new MVE (Megaport Virtual Edge) instance. This function ensures all required parameters are present and valid for creating a new MVE.

Parameters:

  • req: The BuyMVERequest object containing all MVE provisioning parameters

Validation checks:

  • Name must be provided and cannot exceed the maximum length (MaxMVENameLength)
  • Contract term must be valid (typically 1, 12, 24, or 36 months)
  • Location ID must be a positive integer
  • Vendor configuration must be provided and valid

Returns:

  • A ValidationError if any validation check fails
  • nil if all validation checks pass

func ValidateCIDR

func ValidateCIDR(cidr string, fieldName string) error

ValidateCIDR validates that a string is in valid IPv4 CIDR notation. Returns a ValidationError if the string is empty or not a valid IPv4 CIDR.

func ValidateCiscoConfig

func ValidateCiscoConfig(config *megaport.CiscoConfig) error

ValidateCiscoConfig validates a Cisco configuration for an MVE deployment. This function ensures all required parameters for a Cisco virtual appliance are provided.

Parameters:

  • config: The Cisco configuration to validate

Validation checks:

  • Image ID must be a positive integer
  • Product size must be valid (calls ValidateMVEProductSize)
  • Admin SSH public key must be provided
  • SSH public key must be provided
  • If not managing locally (FMC management):
  • FMC IP address must be provided
  • FMC registration key must be provided
  • FMC NAT ID must be provided

Returns:

  • A ValidationError if any validation check fails
  • nil if all validation checks pass

func ValidateContractTerm

func ValidateContractTerm(term int) error

ValidateContractTerm validates if a contract term is one of the allowed values. Contract terms define the duration of the service commitment in months.

Parameters:

  • term: The contract term in months to validate

Validation checks:

  • Term must be one of the predefined valid values (ValidContractTerms)
  • Typically valid values are 1, 12, 24, or 36 months

Returns:

  • A ValidationError if the term is not valid
  • nil if the validation passes

func ValidateCreateNATGatewayRequest added in v0.8.0

func ValidateCreateNATGatewayRequest(req *megaport.CreateNATGatewayRequest) error

ValidateCreateNATGatewayRequest validates a request to create a NAT Gateway.

func ValidateDateRange added in v0.5.2

func ValidateDateRange(startDate, endDate string) error

ValidateDateRange validates that a start and end date pair is complete, well-formed, and ordered. Both dates must be provided together in YYYY-MM-DD format, and the end date must be after the start date.

func ValidateFortinetConfig

func ValidateFortinetConfig(config *megaport.FortinetConfig) error

ValidateFortinetConfig validates a Fortinet configuration for an MVE deployment. This function ensures all required parameters for a Fortinet virtual appliance are provided.

Parameters:

  • config: The Fortinet configuration to validate

Validation checks:

  • Image ID must be a positive integer
  • Product size must be valid (calls ValidateMVEProductSize)
  • Admin SSH public key must be provided (for administrator access)
  • SSH public key must be provided (for regular user access)
  • License data must be provided (for Fortinet licensing)

Returns:

  • A ValidationError if any validation check fails
  • nil if all validation checks pass

func ValidateGooglePartnerConfig

func ValidateGooglePartnerConfig(config *megaport.VXCPartnerConfigGoogle) error

ValidateGooglePartnerConfig validates a Google Cloud partner configuration for a VXC connection. This function ensures the Google-specific connection parameters meet all requirements.

Parameters:

  • config: The Google partner configuration to validate

Validation checks include:

  • Pairing key must be provided (required for Google Cloud connections)

Returns:

  • A ValidationError if any validation check fails
  • nil if all validation checks pass

func ValidateIBMPartnerConfig

func ValidateIBMPartnerConfig(config *megaport.VXCPartnerConfigIBM) error

ValidateIBMPartnerConfig validates an IBM Cloud partner configuration for a VXC connection. This function ensures the IBM-specific connection parameters meet all requirements.

Parameters:

  • config: The IBM partner configuration to validate

Validation checks include:

  • Account ID must be provided
  • Account ID must be exactly 32 characters (IBMAccountIDLength)
  • Account ID must contain only hexadecimal characters (0-9, a-f, A-F)
  • If connection name is provided, it must not exceed the maximum length (MaxIBMNameLength)
  • If connection name is provided, it must contain only allowed characters (0-9, a-z, A-Z, /, -, _, ,)
  • If customer IP address is provided, it must be in valid IPv4 CIDR notation
  • If provider IP address is provided, it must be in valid IPv4 CIDR notation

Returns:

  • A ValidationError if any validation check fails
  • nil if all validation checks pass

func ValidateIPRouteConfig

func ValidateIPRouteConfig(route megaport.IpRoute, ifaceIndex, routeIndex int) error

ValidateIPRouteConfig validates an IP route configuration for a vRouter interface. This function ensures that IP routes are correctly formatted according to networking requirements.

Parameters:

  • route: The IP route configuration to validate (contains prefix and next hop)
  • ifaceIndex: The index of the interface this route belongs to (used for error messages)
  • routeIndex: The index of this route within the interface (used for error messages)

Validation checks include:

  • Prefix must be provided and be a valid IPv4 CIDR notation (e.g., "10.0.0.0/24")
  • Next hop must be provided and be a valid IPv4 address (not a CIDR)
  • Next hop must be in the standard IPv4 format (e.g., "192.168.1.1")

Returns:

  • A ValidationError if any validation check fails
  • nil if all validation checks pass

func ValidateIPSecTunnelCount added in v0.7.1

func ValidateIPSecTunnelCount(count int, allowZeroDisable bool) error

ValidateIPSecTunnelCount validates a tunnel count for an IPSec add-on. Valid non-zero values are always 10, 20, or 30. When allowZeroDisable is true (update mode), 0 is also accepted to disable IPSec. When allowZeroDisable is false (add mode), 0 is rejected; callers that wish to use the API default should skip calling this function when count is 0.

func ValidateIPv4

func ValidateIPv4(ip string, fieldName string) error

ValidateIPv4 validates that a string is a valid IPv4 address. Returns a ValidationError if the string is empty or not a valid IPv4 address.

func ValidateIntRange

func ValidateIntRange(value int, minValue int, maxValue int, fieldName string) error

ValidateIntRange validates that an integer value falls within the specified range. Returns a ValidationError if the value is outside the range, nil otherwise.

func ValidateLAGPortRequest

func ValidateLAGPortRequest(req *megaport.BuyPortRequest) error

ValidateLAGPortRequest validates a LAG (Link Aggregation Group) port buy request. This function ensures all parameters meet Megaport's requirements for provisioning a new LAG port.

Parameters:

  • req: The BuyPortRequest object containing LAG port provisioning parameters

Validation checks:

  • Port name cannot be empty
  • Port name cannot exceed the maximum length (MaxPortNameLength)
  • Location ID must be a positive integer
  • Port speed must be one of the valid LAG port speeds (typically 10000 or 100000 Mbps)
  • LAG count must be between the minimum and maximum allowed values (typically 1-8)
  • Contract term must be valid (typically 1, 12, 24, or 36 months)

Returns:

  • A ValidationError if any validation check fails
  • nil if all validation checks pass

func ValidateMACAddress added in v0.13.0

func ValidateMACAddress(mac string) error

ValidateMACAddress validates if a string is a valid EUI-48 MAC address.

Parameters:

  • mac: The MAC address string to validate

Validation checks:

  • MAC address must not be empty
  • Must be parseable as a hardware address by net.ParseMAC (colon-separated, hyphen-separated, or dot-separated formats)
  • Must be exactly 6 bytes (EUI-48)

Returns:

  • A ValidationError if the MAC address is not valid
  • nil if the validation passes

func ValidateMCRASN added in v0.13.0

func ValidateMCRASN(asn int64) error

ValidateMCRASN validates an explicit BGP ASN for an MCR. The argument is taken as int64 so a full 32-bit ASN is compared safely regardless of platform int width. MinASN/MaxASN (shared in common.go) bound it to the valid 32-bit range; the check only rejects out-of-range values, leaving assignment policy to the API.

func ValidateMCRPortSpeed

func ValidateMCRPortSpeed(speed int) error

ValidateMCRPortSpeed validates if a port speed is one of the allowed values for MCR. This function ensures that the specified port speed is supported for Megaport Cloud Routers.

Parameters:

  • speed: The port speed in Mbps to validate

Validation checks:

  • Speed must be one of the predefined valid values (ValidMCRPortSpeeds)
  • Typically valid values are 1000, 2500, 5000, 10000, 25000, 50000, or 100000 Mbps

Returns:

  • A ValidationError if the speed is not valid
  • nil if the validation passes

func ValidateMCRRequest

func ValidateMCRRequest(req *megaport.BuyMCRRequest) error

ValidateMCRRequest validates a request to buy/provision a new MCR (Megaport Cloud Router). This function ensures all parameters meet the requirements for creating a new MCR.

Parameters:

  • req: The BuyMCRRequest object containing all MCR provisioning parameters

Validation checks:

  • Name cannot be empty
  • Contract term must be valid (typically 1, 12, 24, or 36 months)
  • Port speed must be one of the valid MCR port speeds
  • Location ID must be a positive integer

Returns:

  • A ValidationError if any validation check fails
  • nil if all validation checks pass

func ValidateMVENetworkInterfaces

func ValidateMVENetworkInterfaces(vnics []megaport.MVENetworkInterface) error

ValidateMVENetworkInterfaces validates the network interfaces for an MVE instance. This function ensures the virtual network interfaces meet Megaport's requirements.

Parameters:

  • vnics: A slice of MVENetworkInterface objects representing the virtual NICs to configure

Validation checks:

  • Cannot have more than 5 vNICs per MVE instance
  • Each vNIC must have a non-empty description

Returns:

  • A ValidationError if any validation check fails
  • nil if all validation checks pass

func ValidateMVEProductSize

func ValidateMVEProductSize(size string) error

ValidateMVEProductSize validates the product size for an MVE (Megaport Virtual Edge) instance. This function ensures the specified size is among the allowed values for MVE deployments.

Parameters:

  • size: The MVE product size to validate (e.g., "SMALL", "MEDIUM", "LARGE", "X_LARGE_12")

Validation checks:

  • Size must be one of the predefined valid values (ValidMVEProductSizes)
  • Size cannot be empty

Returns:

  • A ValidationError if the size is not valid
  • nil if the validation passes

func ValidateMVERequest

func ValidateMVERequest(name string, term int, locationID int) error

ValidateMVERequest validates the core parameters for creating an MVE (Megaport Virtual Edge). This function is used by other validators to validate common MVE parameters.

Parameters:

  • name: The name to give the MVE instance
  • term: The contract term in months
  • locationID: The ID of the Megaport location where the MVE will be deployed

Validation checks:

  • Name cannot be empty
  • Name cannot exceed the maximum length (MaxMVENameLength)
  • Contract term must be valid (typically 1, 12, 24, or 36 months)
  • Location ID must be a positive integer

Returns:

  • A ValidationError if any validation check fails
  • nil if all validation checks pass

func ValidateMVEVendor

func ValidateMVEVendor(vendor string) error

ValidateMVEVendor validates that a vendor name is one of the supported MVE vendors. This ensures that only supported network virtualization platforms can be deployed.

Parameters:

  • vendor: The name of the vendor/platform (e.g., "cisco", "palo_alto", "vmware")

Validation checks:

  • Vendor name must be one of the predefined values in ValidMVEVendors
  • Vendor name is case-insensitive (normalized to lowercase for comparison)

Returns:

  • A ValidationError if the vendor is not supported
  • nil if the validation passes

func ValidateMVEVendorConfig

func ValidateMVEVendorConfig(config megaport.VendorConfig) error

ValidateMVEVendorConfig validates vendor-specific configurations for an MVE deployment. This function acts as a dispatcher that routes validation to the appropriate vendor-specific validation function based on the concrete type of the configuration.

Parameters:

  • config: The vendor configuration to validate (an interface that can be any vendor-specific type)

Validation checks:

  • Configuration cannot be nil
  • The concrete type must be one of the supported vendor configuration types
  • Delegates to vendor-specific validation functions:
  • ValidateSixwindVSRConfig
  • ValidateArubaConfig
  • ValidateAviatrixConfig
  • ValidateCiscoConfig
  • ValidateFortinetConfig
  • ValidatePaloAltoConfig
  • ValidatePrismaConfig
  • ValidateVersaConfig
  • ValidateVmwareConfig
  • ValidateMerakiConfig

Returns:

  • A ValidationError if the configuration type is not supported or vendor-specific validation fails
  • nil if all validation checks pass

func ValidateMerakiConfig

func ValidateMerakiConfig(config *megaport.MerakiConfig) error

ValidateMerakiConfig validates a Cisco Meraki configuration for an MVE deployment. This function ensures all required parameters for a Meraki virtual appliance are provided.

Parameters:

  • config: The Meraki configuration to validate

Validation checks:

  • Image ID must be a positive integer
  • Product size must be valid (calls ValidateMVEProductSize)
  • Authentication token must be provided

Returns:

  • A ValidationError if any validation check fails
  • nil if all validation checks pass

func ValidateOraclePartnerConfig

func ValidateOraclePartnerConfig(config *megaport.VXCPartnerConfigOracle) error

ValidateOraclePartnerConfig validates an Oracle Cloud partner configuration for a VXC connection. This function ensures the Oracle-specific connection parameters meet all requirements.

Parameters:

  • config: The Oracle partner configuration to validate

Validation checks include:

  • Virtual Circuit ID must be provided (required for Oracle Cloud connections)

Returns:

  • A ValidationError if any validation check fails
  • nil if all validation checks pass

func ValidatePaloAltoConfig

func ValidatePaloAltoConfig(config *megaport.PaloAltoConfig) error

ValidatePaloAltoConfig validates a Palo Alto Networks configuration for an MVE deployment. This function ensures all required parameters for a Palo Alto Networks virtual appliance are provided.

Parameters:

  • config: The Palo Alto Networks configuration to validate

Validation checks:

  • Image ID must be a positive integer
  • Product size must be valid (calls ValidateMVEProductSize)
  • SSH public key must be provided (for user access)
  • Exactly one of admin password or admin password hash must be provided (for secure administrator authentication)
  • License data must be provided (for Palo Alto Networks licensing)

Returns:

  • A ValidationError if any validation check fails
  • nil if all validation checks pass

func ValidatePortName

func ValidatePortName(name string) error

ValidatePortName validates a port name for a Megaport port. This function ensures the port name meets Megaport's requirements.

Parameters:

  • name: The port name to validate

Validation checks:

  • Name cannot be empty
  • Name cannot exceed the maximum length (MaxPortNameLength)

Returns:

  • A ValidationError if the port name is not valid
  • nil if the validation passes

func ValidatePortRequest

func ValidatePortRequest(req *megaport.BuyPortRequest) error

ValidatePortRequest validates a standard port buy request. This function ensures all parameters meet Megaport's requirements for provisioning a new port.

Parameters:

  • req: The BuyPortRequest object containing all port provisioning parameters

Validation checks:

  • Port name cannot be empty
  • Port name cannot exceed the maximum length (MaxPortNameLength)
  • Location ID must be a positive integer
  • Port speed must be one of the valid port speeds (typically 1000, 10000, or 100000 Mbps)
  • Contract term must be valid (typically 1, 12, 24, or 36 months)

Returns:

  • A ValidationError if any validation check fails
  • nil if all validation checks pass

func ValidatePortSpeed

func ValidatePortSpeed(speed int) error

ValidatePortSpeed validates if a port speed is one of the allowed values for ports. This function ensures that the specified port speed is supported for Megaport physical ports.

Parameters:

  • speed: The port speed in Mbps to validate

Validation checks:

  • Speed must be one of the predefined valid values (ValidPortSpeeds)
  • Typically valid values are 1000, 10000, or 100000 Mbps

Returns:

  • A ValidationError if the speed is not valid
  • nil if the validation passes

func ValidatePortVLANAvailability

func ValidatePortVLANAvailability(vlan int) error

ValidatePortVLANAvailability validates if a VLAN ID is within the range typically available for user assignment on a Port (excluding special/reserved values).

Parameters:

  • vlan: The VLAN ID to validate (typically 2-4093 for user-assignable VLANs)

Validation checks:

  • VLAN must be within the assignable range (MinAssignableVLAN to MaxAssignableVLAN)
  • Special values like AutoAssignVLAN, UntaggedVLAN, and ReservedVLAN are not valid for availability checks

Returns:

  • A ValidationError if the VLAN ID is not within the assignable range
  • nil if the validation passes

func ValidatePrefixFilterListRequest

func ValidatePrefixFilterListRequest(req *megaport.CreateMCRPrefixFilterListRequest) error

ValidatePrefixFilterListRequest validates a request to create a new prefix filter list for an MCR. Prefix filter lists are used to control route advertisements in BGP sessions on MCRs.

Parameters:

  • req: The CreateMCRPrefixFilterListRequest object containing the prefix filter list definition

Validation checks:

  • Description cannot be empty
  • Address family must be provided ("IPv4" or "IPv6")
  • Address family must be a valid value ("IPv4" or "IPv6")
  • At least one entry must be provided in the prefix filter list
  • For each entry:
  • Prefix cannot be empty
  • Action must be "permit" or "deny"

Returns:

  • A ValidationError if any validation check fails
  • nil if all validation checks pass

func ValidatePrismaConfig

func ValidatePrismaConfig(config *megaport.PrismaConfig) error

ValidatePrismaConfig validates a Prisma SD-WAN configuration for an MVE deployment. This function ensures all required parameters for a Prisma SD-WAN virtual appliance are provided.

Parameters:

  • config: The Prisma configuration to validate

Validation checks:

  • Image ID must be a positive integer
  • Product size must be valid (calls ValidateMVEProductSize)
  • ION key must be provided (required for Prisma SD-WAN activation)
  • Secret key must be provided (required for Prisma SD-WAN authentication)

Returns:

  • A ValidationError if any validation check fails
  • nil if all validation checks pass

func ValidateRateLimit

func ValidateRateLimit(rateLimit int) error

ValidateRateLimit validates if a rate limit is a positive integer. This function ensures the rate limit value is valid for bandwidth constraints.

Parameters:

  • rateLimit: The rate limit in Mbps to validate

Validation checks:

  • Rate limit must be a positive integer (greater than zero)
  • Rate limit represents bandwidth in Mbps

Returns:

  • A ValidationError if the rate limit is not valid
  • nil if the validation passes

func ValidateSixwindVSRConfig

func ValidateSixwindVSRConfig(config *megaport.SixwindVSRConfig) error

ValidateSixwindVSRConfig validates a 6WIND VSR configuration for an MVE deployment. This function ensures all required parameters for a 6WIND virtual router are provided.

Parameters:

  • config: The 6WIND VSR configuration to validate

Validation checks:

  • Image ID must be a positive integer
  • Product size must be valid (calls ValidateMVEProductSize)
  • SSH public key must be provided (for authentication)

Returns:

  • A ValidationError if any validation check fails
  • nil if all validation checks pass

func ValidateStringOneOf

func ValidateStringOneOf(value string, validValues []string, fieldName string) error

ValidateStringOneOf validates that a string value is one of the allowed values. Returns a ValidationError if the string is empty or not in the list of valid values.

func ValidateUpdateMVERequest

func ValidateUpdateMVERequest(req *megaport.ModifyMVERequest) error

ValidateUpdateMVERequest validates a request to update an existing MVE (Megaport Virtual Edge) instance. This function ensures that necessary fields are provided to modify an MVE.

Parameters:

  • req: The ModifyMVERequest object containing the fields to update

Validation checks:

  • At least one updateable field must be provided (name, cost center, contract term, or vNICs)
  • If contract term is provided, it must be valid (typically 1, 12, 24, or 36 months)

Returns:

  • A ValidationError if any validation check fails
  • nil if all validation checks pass

func ValidateUpdateNATGatewayRequest added in v0.8.0

func ValidateUpdateNATGatewayRequest(req *megaport.UpdateNATGatewayRequest) error

ValidateUpdateNATGatewayRequest validates a request to update a NAT Gateway. Only the product UID is strictly required; other fields should be pre-filled from the original resource before calling this function.

func ValidateUpdatePrefixFilterList

func ValidateUpdatePrefixFilterList(prefixFilterList *megaport.MCRPrefixFilterList) error

ValidateUpdatePrefixFilterList validates a request to update an existing prefix filter list for an MCR. This function ensures that the updated prefix filter list entries meet the requirements.

Parameters:

  • prefixFilterList: The MCRPrefixFilterList object containing the updated prefix filter list

Validation checks:

  • If entries are provided:
  • For each entry:
  • Prefix cannot be empty
  • Action must be "permit" or "deny"

Returns:

  • A ValidationError if any validation check fails
  • nil if all validation checks pass

func ValidateVLAN

func ValidateVLAN(vlan int) error

ValidateVLAN validates if a VLAN ID is valid for use in Megaport configurations. This function ensures the VLAN ID meets the requirements of IEEE 802.1Q standards and Megaport-specific constraints.

Parameters:

  • vlan: The VLAN ID to validate

Validation checks:

  • VLAN must be one of the following:
  • AutoAssignVLAN (0): System will auto-assign a VLAN
  • UntaggedVLAN (-1): Packet will be untagged
  • A value between MinAssignableVLAN (2) and MaxVLAN (4094) inclusive

Returns:

  • A ValidationError if the VLAN ID is not valid
  • nil if the validation passes

func ValidateVNICIndex added in v0.5.1

func ValidateVNICIndex(index int) error

ValidateVNICIndex validates a vNIC index for a VXC endpoint. The index must be non-negative.

func ValidateVXCEndInnerVLAN

func ValidateVXCEndInnerVLAN(vlan int) error

ValidateVXCEndInnerVLAN validates the inner VLAN ID (Q-in-Q) for a VXC endpoint. This function ensures the inner VLAN ID meets the requirements for QinQ configurations.

Parameters:

  • vlan: The inner VLAN ID to validate (typically 0-4094)

Validation checks:

  • Inner VLAN follows the same validation rules as outer VLANs
  • Must be a valid VLAN ID (0, -1, or 2-4094)

Returns:

  • A ValidationError if the inner VLAN ID is not valid
  • nil if the validation passes

func ValidateVXCEndVLAN

func ValidateVXCEndVLAN(vlan int) error

ValidateVXCEndVLAN validates the VLAN ID for a VXC (Virtual Cross Connect) endpoint. This ensures the VLAN ID meets the Megaport requirements for VXC configurations.

Parameters:

  • vlan: The VLAN ID to validate (typically 0-4094)

Validation checks:

  • The VLAN must be one of the following:
  • AutoAssignVLAN (0): System will auto-assign a VLAN
  • UntaggedVLAN (-1): Packet will be untagged
  • A value between MinAssignableVLAN (2) and MaxVLAN (4094) inclusive

Returns:

  • A ValidationError if the VLAN ID is not valid
  • nil if the validation passes

func ValidateVXCPartnerConfig

func ValidateVXCPartnerConfig(config megaport.VXCPartnerConfiguration) error

ValidateVXCPartnerConfig validates a partner configuration for a VXC connection. This function uses type switching to determine the specific type of partner configuration and delegates to the appropriate type-specific validation function.

Parameters:

  • config: The partner configuration to validate (can be any of the supported partner types)

Validation checks include:

  • Type-specific validations delegated to:
  • ValidateAWSPartnerConfig
  • ValidateAzurePartnerConfig
  • ValidateGooglePartnerConfig
  • ValidateOraclePartnerConfig
  • ValidateIBMPartnerConfig
  • ValidateVrouterPartnerConfig
  • Configuration type must be one of the supported types

Returns:

  • A ValidationError if the type is not supported or if type-specific validation fails
  • nil if all validation checks pass

func ValidateVXCRequest

func ValidateVXCRequest(req *megaport.BuyVXCRequest) error

ValidateVXCRequest validates a VXC (Virtual Cross Connect) request. This function ensures all required parameters for creating a VXC are present and valid.

Parameters:

  • req: The BuyVXCRequest containing all VXC configuration parameters

Validation checks include:

  • VXC name cannot be empty
  • Contract term must be valid (1, 12, 24, or 36 months)
  • Rate limit must be a positive value
  • Port UID (A-End) cannot be empty
  • B-End UID cannot be empty when no partner configuration is provided
  • Partner configurations (if present) must be valid for their respective types

Returns:

  • A ValidationError if any validation check fails
  • nil if all validation checks pass

func ValidateVersaConfig

func ValidateVersaConfig(config *megaport.VersaConfig) error

ValidateVersaConfig validates a Versa Networks configuration for an MVE deployment. This function ensures all required parameters for a Versa Networks virtual appliance are provided.

Parameters:

  • config: The Versa Networks configuration to validate

Validation checks:

  • Image ID must be a positive integer
  • Product size must be valid (calls ValidateMVEProductSize)
  • Director address must be provided (Versa Director management plane)
  • Controller address must be provided (Versa Controller address)
  • Local auth credential must be provided
  • Remote auth credential must be provided
  • Serial number must be provided (for device registration)

Returns:

  • A ValidationError if any validation check fails
  • nil if all validation checks pass

func ValidateVmwareConfig

func ValidateVmwareConfig(config *megaport.VmwareConfig) error

ValidateVmwareConfig validates a VMware SD-WAN configuration for an MVE deployment. This function ensures all required parameters for a VMware SD-WAN virtual appliance are provided.

Parameters:

  • config: The VMware configuration to validate

Validation checks:

  • Image ID must be a positive integer
  • Product size must be valid (calls ValidateMVEProductSize)
  • Admin SSH public key must be provided
  • SSH public key must be provided
  • VCO address must be provided (VMware SD-WAN orchestrator address)
  • VCO activation code must be provided

Returns:

  • A ValidationError if any validation check fails
  • nil if all validation checks pass

func ValidateVrouterPartnerConfig

func ValidateVrouterPartnerConfig(config *megaport.VXCOrderVrouterPartnerConfig) error

ValidateVrouterPartnerConfig validates a vRouter partner configuration for a VXC connection. This function ensures all aspects of a connection to a Megaport virtual router are properly configured.

Parameters:

  • config: The vRouter partner configuration to validate

Validation checks include:

  • Configuration cannot be nil
  • At least one interface must be provided
  • For each interface:
  • If VLAN is specified, it must be within allowed range
  • All IP addresses must be in valid IPv4 CIDR notation
  • All NAT IP addresses must be in valid IPv4 CIDR notation
  • All IP routes must be valid (calls ValidateIPRouteConfig)
  • BFD configuration must be valid (calls ValidateBFDConfig)
  • All BGP connections must be valid (calls ValidateBGPConnectionConfig)

Returns:

  • A ValidationError if any validation check fails
  • nil if all validation checks pass

Types

type ValidationError

type ValidationError struct {
	Field  string
	Value  any
	Reason string
}

ValidationError represents an error that occurs during validation of user input. It contains information about the field being validated, its value, and the reason for validation failure.

func NewValidationError

func NewValidationError(field string, value interface{}, reason string) *ValidationError

NewValidationError creates a new ValidationError with the specified field name, value, and reason.

func (*ValidationError) Error

func (e *ValidationError) Error() string

Error implements the error interface for ValidationError. Returns a formatted string with field name, value, and reason for the validation error.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL