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 }