Skip to content

Commit 94d7593

Browse files
committed
Address PR feedback
1 parent 667d038 commit 94d7593

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

agent/agent.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ func (a *agent) init(ctx context.Context) {
167167
}
168168
sshSrv.Env = a.envVars
169169
sshSrv.AgentToken = func() string { return *a.sessionToken.Load() }
170+
sshSrv.Manifest = &a.manifest
170171
a.sshServer = sshSrv
171172

172173
go a.runLoop(ctx)
@@ -478,7 +479,6 @@ func (a *agent) run(ctx context.Context) error {
478479
}
479480

480481
oldManifest := a.manifest.Swap(&manifest)
481-
a.sshServer.SetManifest(&manifest)
482482

483483
// The startup script should only execute on the first run!
484484
if oldManifest == nil {

agent/agentssh/agentssh.go

+4-10
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ import (
1616
"runtime"
1717
"strings"
1818
"sync"
19-
"sync/atomic"
2019
"time"
2120

2221
"github.com/gliderlabs/ssh"
2322
"github.com/pkg/sftp"
23+
"go.uber.org/atomic"
2424
gossh "golang.org/x/crypto/ssh"
2525
"golang.org/x/xerrors"
2626

@@ -54,8 +54,7 @@ type Server struct {
5454

5555
Env map[string]string
5656
AgentToken func() string
57-
58-
manifest atomic.Pointer[agentsdk.Manifest]
57+
Manifest *atomic.Pointer[agentsdk.Manifest]
5958

6059
connCountVSCode atomic.Int64
6160
connCountJetBrains atomic.Int64
@@ -130,11 +129,6 @@ func NewServer(ctx context.Context, logger slog.Logger, maxTimeout time.Duration
130129
return s, nil
131130
}
132131

133-
// SetManifest sets the manifest used for starting commands.
134-
func (s *Server) SetManifest(m *agentsdk.Manifest) {
135-
s.manifest.Store(m)
136-
}
137-
138132
type ConnStats struct {
139133
Sessions int64
140134
VSCode int64
@@ -215,7 +209,7 @@ func (s *Server) sessionStart(session ssh.Session) (retErr error) {
215209
session.DisablePTYEmulation()
216210

217211
if !isQuietLogin(session.RawCommand()) {
218-
manifest := s.manifest.Load()
212+
manifest := s.Manifest.Load()
219213
if manifest != nil {
220214
err = showMOTD(session, manifest.MOTDFile)
221215
if err != nil {
@@ -388,7 +382,7 @@ func (s *Server) CreateCommand(ctx context.Context, script string, env []string)
388382
return nil, xerrors.Errorf("get user shell: %w", err)
389383
}
390384

391-
manifest := s.manifest.Load()
385+
manifest := s.Manifest.Load()
392386
if manifest == nil {
393387
return nil, xerrors.Errorf("no metadata was provided")
394388
}

agent/agentssh/agentssh_test.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Package agentssh_test provides tests for basic functinoality of the agentssh
2+
// package, more test coverage can be found in the `agent` and `cli` package(s).
13
package agentssh_test
24

35
import (
@@ -10,6 +12,7 @@ import (
1012

1113
"github.com/stretchr/testify/assert"
1214
"github.com/stretchr/testify/require"
15+
"go.uber.org/atomic"
1316
"go.uber.org/goleak"
1417
"golang.org/x/crypto/ssh"
1518

@@ -34,7 +37,7 @@ func TestNewServer_ServeClient(t *testing.T) {
3437

3538
// The assumption is that these are set before serving SSH connections.
3639
s.AgentToken = func() string { return "" }
37-
s.SetManifest(&agentsdk.Manifest{})
40+
s.Manifest = atomic.NewPointer(&agentsdk.Manifest{})
3841

3942
ln, err := net.Listen("tcp", "127.0.0.1:0")
4043
require.NoError(t, err)
@@ -74,7 +77,7 @@ func TestNewServer_CloseActiveConnections(t *testing.T) {
7477

7578
// The assumption is that these are set before serving SSH connections.
7679
s.AgentToken = func() string { return "" }
77-
s.SetManifest(&agentsdk.Manifest{})
80+
s.Manifest = atomic.NewPointer(&agentsdk.Manifest{})
7881

7982
ln, err := net.Listen("tcp", "127.0.0.1:0")
8083
require.NoError(t, err)

0 commit comments

Comments
 (0)