-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Don't depend on github.com/crc-org/vfkit/pkg/rest #25712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| //go:build darwin | ||
|
|
||
| package apple | ||
|
|
||
| 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() | ||
| 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": | ||
| 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) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK podman always seem to use an http API socket so this could be simplified even further.
(I might need to check why we use a tcp socket at all, unix seems much better suited for local IPC)
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I see things like
mc.AppleHypervisor.Vfkit.Endpoint = localhostURI + ":" + strconv.Itoa(randPort), but that’s a few layers away from the call site.I’m all in favor of simplifying further, but I’ll leave that to Podman experts.