You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virt/agent/hypervisor/network_selector.go

20 lines
736 B
Go

package hypervisor
import (
"regexp"
"strings"
)
var networkSourceNamePattern = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9_.-]{0,63}$`)
// ParseNetworkSelector accepts the explicit network source in a signed panel
// request. Existing VM metadata and journal records may contain older aliases.
func ParseNetworkSelector(selector string) (LocalNetworkSource, error) {
kind, name, found := strings.Cut(selector, ":")
if !found || !networkSourceNamePattern.MatchString(name) ||
(kind != "bridge" && kind != "network") || (kind == "bridge" && len(name) > 15) {
return LocalNetworkSource{}, NewError(ErrInvalid, "invalid_network", "network selector is invalid", nil)
}
return LocalNetworkSource{Type: kind, Source: name}, nil
}