blob: a01b8b2e4b4cdc0019193358c61dd5f6484c4334 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
package commandargs
import (
"errors"
"fmt"
"gitlab.com/gitlab-org/gitlab-shell/internal/executable"
"gitlab.com/gitlab-org/gitlab-shell/internal/sshenv"
)
type CommandType string
type CommandArgs interface {
Parse() error
GetArguments() []string
}
func Parse(e *executable.Executable, arguments []string, env sshenv.Env) (CommandArgs, error) {
var args CommandArgs
switch e.Name {
case executable.GitlabShell:
args = &Shell{Arguments: arguments, Env: env}
case executable.AuthorizedKeysCheck:
args = &AuthorizedKeys{Arguments: arguments}
case executable.AuthorizedPrincipalsCheck:
args = &AuthorizedPrincipals{Arguments: arguments}
default:
return nil, errors.New(fmt.Sprintf("unknown executable: %s", e.Name))
}
if err := args.Parse(); err != nil {
return nil, err
}
return args, nil
}
|