Files
podman/pkg/machine/apple/vfkit-rest.go
Paul Holzinger 49c42d06dc 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>
2025-03-31 14:39:51 +02:00

38 lines
1000 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//go:build darwin
package apple
import (
"errors"
"fmt"
"net/url"
)
// This code is adapted from github.com/crc-org/vfkit/pkg/rest/rest.go as of vkit v0.6.0.
// We dont want to import that directly because it imports an enormous dependency tree.
// 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 uri.Scheme {
case "tcp", "http":
if len(uri.Host) < 1 {
return nil, errors.New("invalid TCP uri: missing host")
}
if len(uri.Path) > 0 {
return nil, errors.New("invalid TCP uri: path is forbidden")
}
if uri.Port() == "" {
return nil, errors.New("invalid TCP uri: missing port")
}
return []string{"--restful-uri", fmt.Sprintf("tcp://%s%s", uri.Host, uri.Path)}, nil
default:
return nil, fmt.Errorf("invalid scheme %s", uri.Scheme)
}
}