MCPcopy Index your code
hub / github.com/belak/gitdir / handleSession

Method handleSession

ssh_server.go:186–230  ·  view source on GitHub ↗
(s ssh.Session)

Source from the content-addressed store, hash-verified

184}
185
186func (serv *Server) handleSession(s ssh.Session) {
187 var ctx context.Context = s.Context()
188
189 // Pull a logger for the session
190 slog := CtxLogger(ctx)
191
192 defer func() {
193 // Note that we can't pass in slog as an argument because that would
194 // result in the value getting captured and we want to be able to
195 // annotate this with new values.
196 handlePanic(slog)
197 }()
198
199 slog.Info().Msg("Starting session")
200 defer slog.Info().Msg("Session closed")
201
202 cmd := s.Command()
203
204 // If the user doesn't provide any arguments, we want to run the internal
205 // whoami command.
206 if len(cmd) == 0 {
207 cmd = []string{"whoami"}
208 }
209
210 // Add the command to the logger
211 tmpLog := slog.With().Str("cmd", cmd[0]).Logger()
212 slog = &tmpLog
213 ctx = WithLogger(ctx, slog)
214
215 var exit int
216
217 switch cmd[0] {
218 case "whoami":
219 exit = cmdWhoami(ctx, s, cmd)
220 case "git-receive-pack":
221 exit = serv.cmdGitReceivePack(ctx, s, cmd)
222 case "git-upload-pack":
223 exit = serv.cmdGitUploadPack(ctx, s, cmd)
224 default:
225 exit = cmdNotFound(ctx, s, cmd)
226 }
227
228 slog.Info().Int("return_code", exit).Msg("Return code")
229 _ = s.Exit(exit)
230}

Callers

nothing calls this directly

Calls 7

cmdGitReceivePackMethod · 0.95
cmdGitUploadPackMethod · 0.95
CtxLoggerFunction · 0.85
handlePanicFunction · 0.85
WithLoggerFunction · 0.85
cmdWhoamiFunction · 0.85
cmdNotFoundFunction · 0.85

Tested by

no test coverage detected