summaryrefslogtreecommitdiff
path: root/internal/sshd/session.go
diff options
context:
space:
mode:
authorfeistel <6742251-feistel@users.noreply.gitlab.com>2021-09-20 08:19:41 +0000
committerIgor Drozdov <idrozdov@gitlab.com>2021-09-20 08:19:41 +0000
commit65dadb7e51e206b6411a4518f8a26471d586bc6f (patch)
tree3d02900c42b5c4483403c73a98fdb7ced3ba3d1a /internal/sshd/session.go
parent37025e61e570e748613d9a5a57a7ae5de1b45af5 (diff)
downloadgitlab-shell-65dadb7e51e206b6411a4518f8a26471d586bc6f.tar.gz
refactor: unify instantiation of command.Shell
Diffstat (limited to 'internal/sshd/session.go')
-rw-r--r--internal/sshd/session.go31
1 files changed, 14 insertions, 17 deletions
diff --git a/internal/sshd/session.go b/internal/sshd/session.go
index b58598e..d5a0174 100644
--- a/internal/sshd/session.go
+++ b/internal/sshd/session.go
@@ -2,13 +2,14 @@ package sshd
import (
"context"
+ "errors"
"fmt"
"golang.org/x/crypto/ssh"
shellCmd "gitlab.com/gitlab-org/gitlab-shell/cmd/gitlab-shell/command"
- "gitlab.com/gitlab-org/gitlab-shell/internal/command/commandargs"
"gitlab.com/gitlab-org/gitlab-shell/internal/command/readwriter"
+ "gitlab.com/gitlab-org/gitlab-shell/internal/command/shared/disallowedcommand"
"gitlab.com/gitlab-org/gitlab-shell/internal/config"
"gitlab.com/gitlab-org/gitlab-shell/internal/sshenv"
)
@@ -104,19 +105,11 @@ func (s *session) handleShell(ctx context.Context, req *ssh.Request) uint32 {
req.Reply(true, []byte{})
}
- args := &commandargs.Shell{
- GitlabKeyId: s.gitlabKeyId,
- Env: sshenv.Env{
- IsSSHConnection: true,
- OriginalCommand: s.execCmd,
- GitProtocolVersion: s.gitProtocolVersion,
- RemoteAddr: s.remoteAddr,
- },
- }
-
- if err := args.ParseCommand(s.execCmd); err != nil {
- s.toStderr("Failed to parse command: %v\n", err.Error())
- return 128
+ env := sshenv.Env{
+ IsSSHConnection: true,
+ OriginalCommand: s.execCmd,
+ GitProtocolVersion: s.gitProtocolVersion,
+ RemoteAddr: s.remoteAddr,
}
rw := &readwriter.ReadWriter{
@@ -125,9 +118,13 @@ func (s *session) handleShell(ctx context.Context, req *ssh.Request) uint32 {
ErrOut: s.channel.Stderr(),
}
- cmd := shellCmd.Build(args, s.cfg, rw)
- if cmd == nil {
- s.toStderr("Unknown command: %v\n", args.CommandType)
+ cmd, err := shellCmd.NewWithKey(s.gitlabKeyId, env, s.cfg, rw)
+
+ if err != nil {
+ if !errors.Is(err, disallowedcommand.Error) {
+ s.toStderr("Failed to parse command: %v\n", err.Error())
+ }
+ s.toStderr("Unknown command: %v\n", s.execCmd)
return 128
}