podman/pkg/machine/apple/vfkit-rest.go

38 lines
1000 B
Go
Raw 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)
}
}