Skip to content

Commit 49c42d0

Browse files
committed
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 <[email protected]>
1 parent 5ad70c9 commit 49c42d0

File tree

1 file changed

+4
-26
lines changed

1 file changed

+4
-26
lines changed

pkg/machine/apple/vfkit-rest.go

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,21 @@ import (
66
"errors"
77
"fmt"
88
"net/url"
9-
"strings"
10-
"syscall"
119
)
1210

1311
// This code is adapted from github.com/crc-org/vfkit/pkg/rest/rest.go as of vkit v0.6.0.
1412
// We don’t want to import that directly because it imports an enormous dependency tree.
1513

16-
// see `man unix`:
17-
// UNIX-domain addresses are variable-length filesystem pathnames of at most 104 characters.
18-
func maxSocketPathLen() int {
19-
var sockaddr syscall.RawSockaddrUnix
20-
// sockaddr.Path must end with '\0', it's not relevant for go strings
21-
return len(sockaddr.Path) - 1
22-
}
23-
24-
// This is intended to be equivalent to github.com/crc-org/vfkit/pkg/rest.NewEndpoint(input).ToCmdLine()
14+
// This was taken from github.com/crc-org/vfkit/pkg/rest.NewEndpoint(input).ToCmdLine()
15+
// and adapted with only the case we use.
2516
func restNewEndpointToCmdLine(input string) ([]string, error) {
2617
uri, err := url.ParseRequestURI(input)
2718
if err != nil {
2819
return nil, err
2920
}
3021

31-
switch strings.ToUpper(uri.Scheme) {
32-
case "NONE":
33-
return []string{}, nil
34-
case "UNIX":
35-
if len(uri.Path) < 1 {
36-
return nil, errors.New("invalid unix uri: missing path")
37-
}
38-
if len(uri.Host) > 0 {
39-
return nil, errors.New("invalid unix uri: host is forbidden")
40-
}
41-
if len(uri.Path) > maxSocketPathLen() {
42-
return nil, fmt.Errorf("invalid unix uri: socket path length exceeds macOS limits")
43-
}
44-
return []string{"--restful-uri", fmt.Sprintf("unix://%s", uri.Path)}, nil
45-
case "TCP", "HTTP":
22+
switch uri.Scheme {
23+
case "tcp", "http":
4624
if len(uri.Host) < 1 {
4725
return nil, errors.New("invalid TCP uri: missing host")
4826
}

0 commit comments

Comments
 (0)