(s ssh.Session)
| 184 | } |
| 185 | |
| 186 | func (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 | } |
nothing calls this directly
no test coverage detected