-
Notifications
You must be signed in to change notification settings - Fork 624
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #285 from AkihiroSuda/auto-assign-ssh-localport
Assign `ssh.localPort` automatically to an available port
- Loading branch information
Showing
31 changed files
with
352 additions
and
104 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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,5 @@ | ||
package api | ||
|
||
type Info struct { | ||
SSHLocalPort int `json:"sshLocalPort,omitempty"` | ||
} |
This file contains 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,64 @@ | ||
package client | ||
|
||
// Forked from https://github.com/rootless-containers/rootlesskit/blob/v0.14.2/pkg/api/client/client.go | ||
// Apache License 2.0 | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/lima-vm/lima/pkg/hostagent/api" | ||
"github.com/lima-vm/lima/pkg/httpclientutil" | ||
) | ||
|
||
type HostAgentClient interface { | ||
HTTPClient() *http.Client | ||
Info(context.Context) (*api.Info, error) | ||
} | ||
|
||
// NewHostAgentClient creates a client. | ||
// socketPath is a path to the UNIX socket, without unix:// prefix. | ||
func NewHostAgentClient(socketPath string) (HostAgentClient, error) { | ||
hc, err := httpclientutil.NewHTTPClientWithSocketPath(socketPath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return NewHostAgentClientWithHTTPClient(hc), nil | ||
} | ||
|
||
func NewHostAgentClientWithHTTPClient(hc *http.Client) HostAgentClient { | ||
return &client{ | ||
Client: hc, | ||
version: "v1", | ||
dummyHost: "lima-hostagent", | ||
} | ||
} | ||
|
||
type client struct { | ||
*http.Client | ||
// version is always "v1" | ||
// TODO(AkihiroSuda): negotiate the version | ||
version string | ||
dummyHost string | ||
} | ||
|
||
func (c *client) HTTPClient() *http.Client { | ||
return c.Client | ||
} | ||
|
||
func (c *client) Info(ctx context.Context) (*api.Info, error) { | ||
u := fmt.Sprintf("http://%s/%s/info", c.dummyHost, c.version) | ||
resp, err := httpclientutil.Get(ctx, c.HTTPClient(), u) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer resp.Body.Close() | ||
var info api.Info | ||
dec := json.NewDecoder(resp.Body) | ||
if err := dec.Decode(&info); err != nil { | ||
return nil, err | ||
} | ||
return &info, nil | ||
} |
Oops, something went wrong.