diff options
author | Patrick Bajao <ebajao@gitlab.com> | 2019-08-02 16:10:17 +0800 |
---|---|---|
committer | Patrick Bajao <ebajao@gitlab.com> | 2019-08-02 16:10:17 +0800 |
commit | 3b6f9f7583755e041e76142d7caf7716937907fa (patch) | |
tree | ed7f7281633d97933e4465a2ac0f86d62c9a216e /go/internal/command/commandargs/shell.go | |
parent | 592823d5e25006331b361b36cc61df7802fc1938 (diff) | |
download | gitlab-shell-3b6f9f7583755e041e76142d7caf7716937907fa.tar.gz |
Add Executable struct181-migrate-gitlab-shell-checks-fallback
This struct is responsible for determining the name and
root dir of the executable.
The `RootDir` property will be used to find the config.
The `Name` property will be used to determine what `Command`
and `CommandArgs` to be built.
Diffstat (limited to 'go/internal/command/commandargs/shell.go')
-rw-r--r-- | go/internal/command/commandargs/shell.go | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/go/internal/command/commandargs/shell.go b/go/internal/command/commandargs/shell.go index 04b1040..7e2b72e 100644 --- a/go/internal/command/commandargs/shell.go +++ b/go/internal/command/commandargs/shell.go @@ -23,7 +23,7 @@ var ( ) type Shell struct { - *BaseArgs + Arguments []string GitlabUsername string GitlabKeyId string SshArgs []string @@ -31,23 +31,44 @@ type Shell struct { } func (s *Shell) Parse() error { - if sshConnection := os.Getenv("SSH_CONNECTION"); sshConnection == "" { - return errors.New("Only ssh allowed") + if err := s.validate(); err != nil { + return err } s.parseWho() + s.defineCommandType() + + return nil +} + +func (s *Shell) GetArguments() []string { + return s.Arguments +} - if err := s.parseCommand(os.Getenv("SSH_ORIGINAL_COMMAND")); err != nil { - return errors.New("Invalid ssh command") +func (s *Shell) validate() error { + if !s.isSshConnection() { + return errors.New("Only SSH allowed") } - s.defineCommandType() + if !s.isValidSshCommand() { + return errors.New("Invalid SSH command") + } return nil } +func (s *Shell) isSshConnection() bool { + ok := os.Getenv("SSH_CONNECTION") + return ok != "" +} + +func (s *Shell) isValidSshCommand() bool { + err := s.parseCommand(os.Getenv("SSH_ORIGINAL_COMMAND")) + return err == nil +} + func (s *Shell) parseWho() { - for _, argument := range s.arguments { + for _, argument := range s.Arguments { if keyId := tryParseKeyId(argument); keyId != "" { s.GitlabKeyId = keyId break |