Skip to content

Commit d5f7a4e

Browse files
committed
Rename receivers
1 parent 37adb62 commit d5f7a4e

File tree

1 file changed

+42
-42
lines changed

1 file changed

+42
-42
lines changed

agent/agentssh/agentssh.go

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ func NewServer(ctx context.Context, logger slog.Logger, maxTimeout time.Duration
136136
}
137137

138138
// SetManifest sets the manifest used for starting commands.
139-
func (a *Server) SetManifest(m *agentsdk.Manifest) {
140-
a.manifest.Store(m)
139+
func (s *Server) SetManifest(m *agentsdk.Manifest) {
140+
s.manifest.Store(m)
141141
}
142142

143143
type ConnStats struct {
@@ -146,25 +146,25 @@ type ConnStats struct {
146146
JetBrains int64
147147
}
148148

149-
func (a *Server) ConnStats() ConnStats {
149+
func (s *Server) ConnStats() ConnStats {
150150
return ConnStats{
151-
Sessions: a.connCountSSHSession.Load(),
152-
VSCode: a.connCountVSCode.Load(),
153-
JetBrains: a.connCountJetBrains.Load(),
151+
Sessions: s.connCountSSHSession.Load(),
152+
VSCode: s.connCountVSCode.Load(),
153+
JetBrains: s.connCountJetBrains.Load(),
154154
}
155155
}
156156

157-
func (a *Server) sessionHandler(session ssh.Session) {
157+
func (s *Server) sessionHandler(session ssh.Session) {
158158
ctx := session.Context()
159-
err := a.sessionStart(session)
159+
err := s.sessionStart(session)
160160
var exitError *exec.ExitError
161161
if xerrors.As(err, &exitError) {
162-
a.logger.Debug(ctx, "ssh session returned", slog.Error(exitError))
162+
s.logger.Debug(ctx, "ssh session returned", slog.Error(exitError))
163163
_ = session.Exit(exitError.ExitCode())
164164
return
165165
}
166166
if err != nil {
167-
a.logger.Warn(ctx, "ssh session failed", slog.Error(err))
167+
s.logger.Warn(ctx, "ssh session failed", slog.Error(err))
168168
// This exit code is designed to be unlikely to be confused for a legit exit code
169169
// from the process.
170170
_ = session.Exit(MagicSessionErrorCode)
@@ -173,7 +173,7 @@ func (a *Server) sessionHandler(session ssh.Session) {
173173
_ = session.Exit(0)
174174
}
175175

176-
func (a *Server) sessionStart(session ssh.Session) (retErr error) {
176+
func (s *Server) sessionStart(session ssh.Session) (retErr error) {
177177
ctx := session.Context()
178178
env := session.Environ()
179179
var magicType string
@@ -186,19 +186,19 @@ func (a *Server) sessionStart(session ssh.Session) (retErr error) {
186186
}
187187
switch magicType {
188188
case MagicSessionTypeVSCode:
189-
a.connCountVSCode.Add(1)
190-
defer a.connCountVSCode.Add(-1)
189+
s.connCountVSCode.Add(1)
190+
defer s.connCountVSCode.Add(-1)
191191
case MagicSessionTypeJetBrains:
192-
a.connCountJetBrains.Add(1)
193-
defer a.connCountJetBrains.Add(-1)
192+
s.connCountJetBrains.Add(1)
193+
defer s.connCountJetBrains.Add(-1)
194194
case "":
195-
a.connCountSSHSession.Add(1)
196-
defer a.connCountSSHSession.Add(-1)
195+
s.connCountSSHSession.Add(1)
196+
defer s.connCountSSHSession.Add(-1)
197197
default:
198-
a.logger.Warn(ctx, "invalid magic ssh session type specified", slog.F("type", magicType))
198+
s.logger.Warn(ctx, "invalid magic ssh session type specified", slog.F("type", magicType))
199199
}
200200

201-
cmd, err := a.CreateCommand(ctx, session.RawCommand(), env)
201+
cmd, err := s.CreateCommand(ctx, session.RawCommand(), env)
202202
if err != nil {
203203
return err
204204
}
@@ -220,14 +220,14 @@ func (a *Server) sessionStart(session ssh.Session) (retErr error) {
220220
session.DisablePTYEmulation()
221221

222222
if !isQuietLogin(session.RawCommand()) {
223-
manifest := a.manifest.Load()
223+
manifest := s.manifest.Load()
224224
if manifest != nil {
225225
err = showMOTD(session, manifest.MOTDFile)
226226
if err != nil {
227-
a.logger.Error(ctx, "show MOTD", slog.Error(err))
227+
s.logger.Error(ctx, "show MOTD", slog.Error(err))
228228
}
229229
} else {
230-
a.logger.Warn(ctx, "metadata lookup failed, unable to show MOTD")
230+
s.logger.Warn(ctx, "metadata lookup failed, unable to show MOTD")
231231
}
232232
}
233233

@@ -236,7 +236,7 @@ func (a *Server) sessionStart(session ssh.Session) (retErr error) {
236236
// The pty package sets `SSH_TTY` on supported platforms.
237237
ptty, process, err := pty.Start(cmd, pty.WithPTYOption(
238238
pty.WithSSHRequest(sshPty),
239-
pty.WithLogger(slog.Stdlib(ctx, a.logger, slog.LevelInfo)),
239+
pty.WithLogger(slog.Stdlib(ctx, s.logger, slog.LevelInfo)),
240240
))
241241
if err != nil {
242242
return xerrors.Errorf("start command: %w", err)
@@ -246,7 +246,7 @@ func (a *Server) sessionStart(session ssh.Session) (retErr error) {
246246
defer wg.Wait()
247247
closeErr := ptty.Close()
248248
if closeErr != nil {
249-
a.logger.Warn(ctx, "failed to close tty", slog.Error(closeErr))
249+
s.logger.Warn(ctx, "failed to close tty", slog.Error(closeErr))
250250
if retErr == nil {
251251
retErr = closeErr
252252
}
@@ -257,7 +257,7 @@ func (a *Server) sessionStart(session ssh.Session) (retErr error) {
257257
resizeErr := ptty.Resize(uint16(win.Height), uint16(win.Width))
258258
// If the pty is closed, then command has exited, no need to log.
259259
if resizeErr != nil && !errors.Is(resizeErr, pty.ErrClosed) {
260-
a.logger.Warn(ctx, "failed to resize tty", slog.Error(resizeErr))
260+
s.logger.Warn(ctx, "failed to resize tty", slog.Error(resizeErr))
261261
}
262262
}
263263
}()
@@ -306,7 +306,7 @@ func (a *Server) sessionStart(session ssh.Session) (retErr error) {
306306
// ExitErrors just mean the command we run returned a non-zero exit code, which is normal
307307
// and not something to be concerned about. But, if it's something else, we should log it.
308308
if err != nil && !xerrors.As(err, &exitErr) {
309-
a.logger.Warn(ctx, "wait error", slog.Error(err))
309+
s.logger.Warn(ctx, "wait error", slog.Error(err))
310310
}
311311
return err
312312
}
@@ -335,7 +335,7 @@ type readNopCloser struct{ io.Reader }
335335
// Close implements io.Closer.
336336
func (readNopCloser) Close() error { return nil }
337337

338-
func (a *Server) sftpHandler(session ssh.Session) {
338+
func (s *Server) sftpHandler(session ssh.Session) {
339339
ctx := session.Context()
340340

341341
// Typically sftp sessions don't request a TTY, but if they do,
@@ -349,14 +349,14 @@ func (a *Server) sftpHandler(session ssh.Session) {
349349
// directory so that SFTP connections land there.
350350
homedir, err := userHomeDir()
351351
if err != nil {
352-
a.logger.Warn(ctx, "get sftp working directory failed, unable to get home dir", slog.Error(err))
352+
s.logger.Warn(ctx, "get sftp working directory failed, unable to get home dir", slog.Error(err))
353353
} else {
354354
opts = append(opts, sftp.WithServerWorkingDirectory(homedir))
355355
}
356356

357357
server, err := sftp.NewServer(session, opts...)
358358
if err != nil {
359-
a.logger.Debug(ctx, "initialize sftp server", slog.Error(err))
359+
s.logger.Debug(ctx, "initialize sftp server", slog.Error(err))
360360
return
361361
}
362362
defer server.Close()
@@ -374,14 +374,14 @@ func (a *Server) sftpHandler(session ssh.Session) {
374374
_ = session.Exit(0)
375375
return
376376
}
377-
a.logger.Warn(ctx, "sftp server closed with error", slog.Error(err))
377+
s.logger.Warn(ctx, "sftp server closed with error", slog.Error(err))
378378
_ = session.Exit(1)
379379
}
380380

381381
// CreateCommand processes raw command input with OpenSSH-like behavior.
382382
// If the script provided is empty, it will default to the users shell.
383383
// This injects environment variables specified by the user at launch too.
384-
func (a *Server) CreateCommand(ctx context.Context, script string, env []string) (*exec.Cmd, error) {
384+
func (s *Server) CreateCommand(ctx context.Context, script string, env []string) (*exec.Cmd, error) {
385385
currentUser, err := user.Current()
386386
if err != nil {
387387
return nil, xerrors.Errorf("get current user: %w", err)
@@ -393,7 +393,7 @@ func (a *Server) CreateCommand(ctx context.Context, script string, env []string)
393393
return nil, xerrors.Errorf("get user shell: %w", err)
394394
}
395395

396-
manifest := a.manifest.Load()
396+
manifest := s.manifest.Load()
397397
if manifest == nil {
398398
return nil, xerrors.Errorf("no metadata was provided")
399399
}
@@ -446,7 +446,7 @@ func (a *Server) CreateCommand(ctx context.Context, script string, env []string)
446446
cmd.Env = append(cmd.Env, fmt.Sprintf(`GIT_SSH_COMMAND=%s gitssh --`, unixExecutablePath))
447447

448448
// Specific Coder subcommands require the agent token exposed!
449-
cmd.Env = append(cmd.Env, fmt.Sprintf("CODER_AGENT_TOKEN=%s", a.AgentToken()))
449+
cmd.Env = append(cmd.Env, fmt.Sprintf("CODER_AGENT_TOKEN=%s", s.AgentToken()))
450450

451451
// Set SSH connection environment variables (these are also set by OpenSSH
452452
// and thus expected to be present by SSH clients). Since the agent does
@@ -475,30 +475,30 @@ func (a *Server) CreateCommand(ctx context.Context, script string, env []string)
475475

476476
// Agent-level environment variables should take over all!
477477
// This is used for setting agent-specific variables like "CODER_AGENT_TOKEN".
478-
for envKey, value := range a.Env {
478+
for envKey, value := range s.Env {
479479
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", envKey, value))
480480
}
481481

482482
return cmd, nil
483483
}
484484

485-
func (a *Server) Serve(l net.Listener) error {
486-
a.serveWg.Add(1)
487-
defer a.serveWg.Done()
488-
return a.srv.Serve(l)
485+
func (s *Server) Serve(l net.Listener) error {
486+
s.serveWg.Add(1)
487+
defer s.serveWg.Done()
488+
return s.srv.Serve(l)
489489
}
490490

491-
func (a *Server) Close() error {
492-
err := a.srv.Close()
493-
a.serveWg.Wait()
491+
func (s *Server) Close() error {
492+
err := s.srv.Close()
493+
s.serveWg.Wait()
494494
return err
495495
}
496496

497497
// Shutdown gracefully closes all active SSH connections and stops
498498
// accepting new connections.
499499
//
500500
// Shutdown is not implemented.
501-
func (a *Server) Shutdown(ctx context.Context) error {
501+
func (*Server) Shutdown(ctx context.Context) error {
502502
// TODO(mafredri): Implement shutdown, SIGHUP running commands, etc.
503503
return nil
504504
}

0 commit comments

Comments
 (0)