mirror of
https://github.com/containers/podman.git
synced 2025-10-15 02:06:42 +08:00
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 <pholzing@redhat.com>
This commit is contained in:
@ -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")
|
||||
}
|
||||
|
Reference in New Issue
Block a user