From 49c42d06dc79558ab9205d02f3de5e8410f70666 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Fri, 28 Mar 2025 15:01:27 +0100 Subject: [PATCH] pkg/machine/apple: simplify restNewEndpointToCmdLine() We only use the http URL endpoint so we can remove the other code. There is the question if we should not use direct unix sockets instead as this seems much safer but that seems like a larger change that might need more discussion. Signed-off-by: Paul Holzinger --- pkg/machine/apple/vfkit-rest.go | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/pkg/machine/apple/vfkit-rest.go b/pkg/machine/apple/vfkit-rest.go index 8045fd4c91..78caa3dabe 100644 --- a/pkg/machine/apple/vfkit-rest.go +++ b/pkg/machine/apple/vfkit-rest.go @@ -6,43 +6,21 @@ import ( "errors" "fmt" "net/url" - "strings" - "syscall" ) // This code is adapted from github.com/crc-org/vfkit/pkg/rest/rest.go as of vkit v0.6.0. // We don’t want to import that directly because it imports an enormous dependency tree. -// see `man unix`: -// UNIX-domain addresses are variable-length filesystem pathnames of at most 104 characters. -func maxSocketPathLen() int { - var sockaddr syscall.RawSockaddrUnix - // sockaddr.Path must end with '\0', it's not relevant for go strings - return len(sockaddr.Path) - 1 -} - -// This is intended to be equivalent to github.com/crc-org/vfkit/pkg/rest.NewEndpoint(input).ToCmdLine() +// This was taken from github.com/crc-org/vfkit/pkg/rest.NewEndpoint(input).ToCmdLine() +// and adapted with only the case we use. func restNewEndpointToCmdLine(input string) ([]string, error) { uri, err := url.ParseRequestURI(input) if err != nil { return nil, err } - switch strings.ToUpper(uri.Scheme) { - case "NONE": - return []string{}, nil - case "UNIX": - if len(uri.Path) < 1 { - return nil, errors.New("invalid unix uri: missing path") - } - if len(uri.Host) > 0 { - return nil, errors.New("invalid unix uri: host is forbidden") - } - if len(uri.Path) > maxSocketPathLen() { - return nil, fmt.Errorf("invalid unix uri: socket path length exceeds macOS limits") - } - return []string{"--restful-uri", fmt.Sprintf("unix://%s", uri.Path)}, nil - case "TCP", "HTTP": + switch uri.Scheme { + case "tcp", "http": if len(uri.Host) < 1 { return nil, errors.New("invalid TCP uri: missing host") }