Skip to content

Commit eb34bc4

Browse files
committed
appease the linter
1 parent 00262eb commit eb34bc4

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

agent/agentsocket/server.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,25 @@ import (
1818
"github.com/coder/coder/v2/codersdk/drpcsdk"
1919
)
2020

21+
// Client wraps a DRPC client with connection management.
22+
// This type is defined here so it's available on all platforms.
23+
type Client struct {
24+
proto.DRPCAgentSocketClient
25+
conn net.Conn
26+
session *yamux.Session
27+
}
28+
29+
// Close closes the client connection.
30+
func (c *Client) Close() error {
31+
if c.session != nil {
32+
_ = c.session.Close()
33+
}
34+
if c.conn != nil {
35+
return c.conn.Close()
36+
}
37+
return nil
38+
}
39+
2140
// Server provides access to the DRPCAgentSocketService via a Unix domain socket.
2241
// Do not invoke Server{} directly. Use NewServer() instead.
2342
type Server struct {

agent/agentsocket/socket_unix.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,20 @@
33
package agentsocket
44

55
import (
6+
"context"
67
"crypto/rand"
78
"encoding/hex"
89
"net"
910
"os"
1011
"path/filepath"
1112
"time"
1213

14+
"github.com/hashicorp/yamux"
1315
"golang.org/x/xerrors"
16+
17+
"cdr.dev/slog"
18+
"github.com/coder/coder/v2/agent/agentsocket/proto"
19+
"github.com/coder/coder/v2/codersdk/drpcsdk"
1420
)
1521

1622
// createSocket creates a Unix domain socket listener
@@ -81,3 +87,25 @@ func isSocketAvailable(path string) bool {
8187
// Socket is in use
8288
return false
8389
}
90+
91+
// NewClient creates a DRPC client for the agent socket at the given path.
92+
func NewClient(path string, logger slog.Logger) (*Client, error) {
93+
conn, err := net.Dial("unix", path)
94+
if err != nil {
95+
return nil, xerrors.Errorf("dial unix socket: %w", err)
96+
}
97+
98+
config := yamux.DefaultConfig()
99+
config.LogOutput = nil
100+
config.Logger = slog.Stdlib(context.Background(), logger, slog.LevelInfo)
101+
session, err := yamux.Client(conn, config)
102+
if err != nil {
103+
_ = conn.Close()
104+
return nil, xerrors.Errorf("multiplex client: %w", err)
105+
}
106+
return &Client{
107+
DRPCAgentSocketClient: proto.NewDRPCAgentSocketClient(drpcsdk.MultiplexedConn(session)),
108+
conn: conn,
109+
session: session,
110+
}, nil
111+
}

cli/testdata/coder_agent_--help.golden

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ OPTIONS:
6767
--script-data-dir string, $CODER_AGENT_SCRIPT_DATA_DIR (default: /tmp)
6868
Specify the location for storing script data.
6969

70+
--socket-path string, $CODER_AGENT_SOCKET_PATH
71+
Specify the path for the agent socket.
72+
7073
--ssh-max-timeout duration, $CODER_AGENT_SSH_MAX_TIMEOUT (default: 72h)
7174
Specify the max timeout for a SSH connection, it is advisable to set
7275
it to a minimum of 60s, but no more than 72h.

0 commit comments

Comments
 (0)