Skip to content

Commit 71af9d5

Browse files
committed
refactor(ipc): add ssh info to restful /info api
Signed-off-by: Kevin Cui <[email protected]>
1 parent 48763cb commit 71af9d5

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

pkg/cli/setup.go

+16
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type Context struct {
3636
SSHKeyPath string
3737
SSHPrivateKeyPath string
3838
SSHPublicKeyPath string
39+
SSHPrivateKey string
3940
SSHPublicKey string
4041

4142
ForwardSocketPath string
@@ -210,6 +211,21 @@ func (c *Context) ssh() error {
210211
c.SSHPublicKey = strings.TrimSpace(string(b))
211212
}
212213

214+
{
215+
f, err := os.Open(c.SSHPrivateKeyPath)
216+
if err != nil {
217+
return err
218+
}
219+
defer f.Close()
220+
221+
b, err := io.ReadAll(f)
222+
if err != nil {
223+
return err
224+
}
225+
226+
c.SSHPrivateKey = strings.TrimSpace(string(b))
227+
}
228+
213229
return nil
214230
}
215231

pkg/ipc/restful/restful.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@ type stateResponse struct {
2727
}
2828

2929
type infoResponse struct {
30-
PodmanSocketPath string `json:"podmanSocketPath"`
30+
PodmanSocketPath string `json:"podmanSocketPath"`
31+
SSHPort int `json:"sshPort"`
32+
SSHUser string `json:"sshUser"`
33+
SSHPublicKeyPath string `json:"sshPublicKeyPath"`
34+
SSHPrivateKeyPath string `json:"sshPrivateKeyPath"`
35+
SSHPublicKey string `json:"sshPublicKey"`
36+
SSHPrivateKey string `json:"sshPrivateKey"`
3137
}
3238

3339
type Restful struct {
@@ -144,7 +150,13 @@ func (s *Restful) Start(ctx context.Context, g *errgroup.Group, nl net.Listener)
144150
func (s *Restful) info() *infoResponse {
145151
s.log.Info("request /info")
146152
return &infoResponse{
147-
PodmanSocketPath: s.opt.ForwardSocketPath,
153+
PodmanSocketPath: s.opt.ForwardSocketPath,
154+
SSHPort: s.opt.SSHPort,
155+
SSHUser: "root",
156+
SSHPublicKeyPath: s.opt.SSHPublicKeyPath,
157+
SSHPrivateKeyPath: s.opt.SSHPrivateKeyPath,
158+
SSHPublicKey: s.opt.SSHPublicKey,
159+
SSHPrivateKey: s.opt.SSHPrivateKey,
148160
}
149161
}
150162

0 commit comments

Comments
 (0)