diff options
author | feistel <6742251-feistel@users.noreply.gitlab.com> | 2021-09-08 15:04:21 +0000 |
---|---|---|
committer | feistel <6742251-feistel@users.noreply.gitlab.com> | 2021-09-08 15:04:21 +0000 |
commit | d0e09b414a9b069ec7bcbed2880b93c27cf3727c (patch) | |
tree | 16ab2acb6bcaeb1cc88acf01f1f7f4eb9dc1ca76 | |
parent | 67415dc4f6f293460517d4281b5e4e80e66ffb91 (diff) | |
download | gitlab-shell-d0e09b414a9b069ec7bcbed2880b93c27cf3727c.tar.gz |
refactor: cleanup func signature and remove unused args
9 files changed, 22 insertions, 29 deletions
diff --git a/cmd/gitlab-shell-authorized-keys-check/command/command.go b/cmd/gitlab-shell-authorized-keys-check/command/command.go index 3db8605..8cf309b 100644 --- a/cmd/gitlab-shell-authorized-keys-check/command/command.go +++ b/cmd/gitlab-shell-authorized-keys-check/command/command.go @@ -7,12 +7,10 @@ import ( "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/executable" - "gitlab.com/gitlab-org/gitlab-shell/internal/sshenv" ) -func New(e *executable.Executable, arguments []string, env sshenv.Env, config *config.Config, readWriter *readwriter.ReadWriter) (command.Command, error) { - args, err := Parse(e, arguments, env) +func New(arguments []string, config *config.Config, readWriter *readwriter.ReadWriter) (command.Command, error) { + args, err := Parse(arguments) if err != nil { return nil, err } @@ -24,7 +22,7 @@ func New(e *executable.Executable, arguments []string, env sshenv.Env, config *c return nil, disallowedcommand.Error } -func Parse(e *executable.Executable, arguments []string, env sshenv.Env) (*commandargs.AuthorizedKeys, error) { +func Parse(arguments []string) (*commandargs.AuthorizedKeys, error) { args := &commandargs.AuthorizedKeys{Arguments: arguments} if err := args.Parse(); err != nil { diff --git a/cmd/gitlab-shell-authorized-keys-check/command/command_test.go b/cmd/gitlab-shell-authorized-keys-check/command/command_test.go index 5c5419e..3343e1c 100644 --- a/cmd/gitlab-shell-authorized-keys-check/command/command_test.go +++ b/cmd/gitlab-shell-authorized-keys-check/command/command_test.go @@ -37,7 +37,7 @@ func TestNew(t *testing.T) { for _, tc := range testCases { t.Run(tc.desc, func(t *testing.T) { - command, err := command.New(tc.executable, tc.arguments, tc.env, tc.config, nil) + command, err := command.New(tc.arguments, tc.config, nil) require.NoError(t, err) require.IsType(t, tc.expectedType, command) @@ -64,7 +64,7 @@ func TestParseSuccess(t *testing.T) { for _, tc := range testCases { t.Run(tc.desc, func(t *testing.T) { - result, err := command.Parse(tc.executable, tc.arguments, tc.env) + result, err := command.Parse(tc.arguments) if !tc.expectError { require.NoError(t, err) @@ -112,7 +112,7 @@ func TestParseFailure(t *testing.T) { for _, tc := range testCases { t.Run(tc.desc, func(t *testing.T) { - _, err := command.Parse(tc.executable, tc.arguments, tc.env) + _, err := command.Parse(tc.arguments) require.EqualError(t, err, tc.expectedError) }) diff --git a/cmd/gitlab-shell-authorized-keys-check/main.go b/cmd/gitlab-shell-authorized-keys-check/main.go index bfaeca7..ebe6da9 100644 --- a/cmd/gitlab-shell-authorized-keys-check/main.go +++ b/cmd/gitlab-shell-authorized-keys-check/main.go @@ -11,7 +11,6 @@ import ( "gitlab.com/gitlab-org/gitlab-shell/internal/console" "gitlab.com/gitlab-org/gitlab-shell/internal/executable" "gitlab.com/gitlab-org/gitlab-shell/internal/logger" - "gitlab.com/gitlab-org/gitlab-shell/internal/sshenv" ) func main() { @@ -36,7 +35,7 @@ func main() { logCloser := logger.Configure(config) defer logCloser.Close() - cmd, err := cmd.New(executable, os.Args[1:], sshenv.Env{}, config, readWriter) + cmd, err := cmd.New(os.Args[1:], config, readWriter) if err != nil { // For now this could happen if `SSH_CONNECTION` is not set on // the environment diff --git a/cmd/gitlab-shell-authorized-principals-check/command/command.go b/cmd/gitlab-shell-authorized-principals-check/command/command.go index b5ded54..9418dad 100644 --- a/cmd/gitlab-shell-authorized-principals-check/command/command.go +++ b/cmd/gitlab-shell-authorized-principals-check/command/command.go @@ -7,12 +7,10 @@ import ( "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/executable" - "gitlab.com/gitlab-org/gitlab-shell/internal/sshenv" ) -func New(e *executable.Executable, arguments []string, env sshenv.Env, config *config.Config, readWriter *readwriter.ReadWriter) (command.Command, error) { - args, err := Parse(e, arguments, env) +func New(arguments []string, config *config.Config, readWriter *readwriter.ReadWriter) (command.Command, error) { + args, err := Parse(arguments) if err != nil { return nil, err } @@ -24,7 +22,7 @@ func New(e *executable.Executable, arguments []string, env sshenv.Env, config *c return nil, disallowedcommand.Error } -func Parse(e *executable.Executable, arguments []string, env sshenv.Env) (*commandargs.AuthorizedPrincipals, error) { +func Parse(arguments []string) (*commandargs.AuthorizedPrincipals, error) { args := &commandargs.AuthorizedPrincipals{Arguments: arguments} if err := args.Parse(); err != nil { diff --git a/cmd/gitlab-shell-authorized-principals-check/command/command_test.go b/cmd/gitlab-shell-authorized-principals-check/command/command_test.go index b6a89f5..2ca2125 100644 --- a/cmd/gitlab-shell-authorized-principals-check/command/command_test.go +++ b/cmd/gitlab-shell-authorized-principals-check/command/command_test.go @@ -37,7 +37,7 @@ func TestNew(t *testing.T) { for _, tc := range testCases { t.Run(tc.desc, func(t *testing.T) { - command, err := cmd.New(tc.executable, tc.arguments, tc.env, tc.config, nil) + command, err := cmd.New(tc.arguments, tc.config, nil) require.NoError(t, err) require.IsType(t, tc.expectedType, command) @@ -64,7 +64,7 @@ func TestParseSuccess(t *testing.T) { for _, tc := range testCases { t.Run(tc.desc, func(t *testing.T) { - result, err := cmd.Parse(tc.executable, tc.arguments, tc.env) + result, err := cmd.Parse(tc.arguments) if !tc.expectError { require.NoError(t, err) @@ -106,7 +106,7 @@ func TestParseFailure(t *testing.T) { for _, tc := range testCases { t.Run(tc.desc, func(t *testing.T) { - _, err := cmd.Parse(tc.executable, tc.arguments, tc.env) + _, err := cmd.Parse(tc.arguments) require.EqualError(t, err, tc.expectedError) }) diff --git a/cmd/gitlab-shell-authorized-principals-check/main.go b/cmd/gitlab-shell-authorized-principals-check/main.go index d0e709c..3e18b9d 100644 --- a/cmd/gitlab-shell-authorized-principals-check/main.go +++ b/cmd/gitlab-shell-authorized-principals-check/main.go @@ -11,7 +11,6 @@ import ( "gitlab.com/gitlab-org/gitlab-shell/internal/console" "gitlab.com/gitlab-org/gitlab-shell/internal/executable" "gitlab.com/gitlab-org/gitlab-shell/internal/logger" - "gitlab.com/gitlab-org/gitlab-shell/internal/sshenv" ) func main() { @@ -36,7 +35,7 @@ func main() { logCloser := logger.Configure(config) defer logCloser.Close() - cmd, err := cmd.New(executable, os.Args[1:], sshenv.Env{}, config, readWriter) + cmd, err := cmd.New(os.Args[1:], config, readWriter) if err != nil { // For now this could happen if `SSH_CONNECTION` is not set on // the environment diff --git a/cmd/gitlab-shell/command/command.go b/cmd/gitlab-shell/command/command.go index 98bfdff..be54ac6 100644 --- a/cmd/gitlab-shell/command/command.go +++ b/cmd/gitlab-shell/command/command.go @@ -14,12 +14,11 @@ import ( "gitlab.com/gitlab-org/gitlab-shell/internal/command/uploadarchive" "gitlab.com/gitlab-org/gitlab-shell/internal/command/uploadpack" "gitlab.com/gitlab-org/gitlab-shell/internal/config" - "gitlab.com/gitlab-org/gitlab-shell/internal/executable" "gitlab.com/gitlab-org/gitlab-shell/internal/sshenv" ) -func New(e *executable.Executable, arguments []string, env sshenv.Env, config *config.Config, readWriter *readwriter.ReadWriter) (command.Command, error) { - args, err := Parse(e, arguments, env) +func New(arguments []string, env sshenv.Env, config *config.Config, readWriter *readwriter.ReadWriter) (command.Command, error) { + args, err := Parse(arguments, env) if err != nil { return nil, err } @@ -31,7 +30,7 @@ func New(e *executable.Executable, arguments []string, env sshenv.Env, config *c return nil, disallowedcommand.Error } -func Parse(e *executable.Executable, arguments []string, env sshenv.Env) (*commandargs.Shell, error) { +func Parse(arguments []string, env sshenv.Env) (*commandargs.Shell, error) { args := &commandargs.Shell{Arguments: arguments, Env: env} if err := args.Parse(); err != nil { diff --git a/cmd/gitlab-shell/command/command_test.go b/cmd/gitlab-shell/command/command_test.go index 5dacb67..2db644b 100644 --- a/cmd/gitlab-shell/command/command_test.go +++ b/cmd/gitlab-shell/command/command_test.go @@ -95,7 +95,7 @@ func TestNew(t *testing.T) { for _, tc := range testCases { t.Run(tc.desc, func(t *testing.T) { - command, err := cmd.New(tc.executable, tc.arguments, tc.env, tc.config, nil) + command, err := cmd.New(tc.arguments, tc.env, tc.config, nil) require.NoError(t, err) require.IsType(t, tc.expectedType, command) @@ -125,7 +125,7 @@ func TestFailingNew(t *testing.T) { for _, tc := range testCases { t.Run(tc.desc, func(t *testing.T) { - command, err := cmd.New(tc.executable, []string{}, tc.env, basicConfig, nil) + command, err := cmd.New([]string{}, tc.env, basicConfig, nil) require.Nil(t, command) require.Equal(t, tc.expectedError, err) }) @@ -236,7 +236,7 @@ func TestParseSuccess(t *testing.T) { for _, tc := range testCases { t.Run(tc.desc, func(t *testing.T) { - result, err := cmd.Parse(tc.executable, tc.arguments, tc.env) + result, err := cmd.Parse(tc.arguments, tc.env) if !tc.expectError { require.NoError(t, err) @@ -273,7 +273,7 @@ func TestParseFailure(t *testing.T) { for _, tc := range testCases { t.Run(tc.desc, func(t *testing.T) { - _, err := cmd.Parse(tc.executable, tc.arguments, tc.env) + _, err := cmd.Parse(tc.arguments, tc.env) require.EqualError(t, err, tc.expectedError) }) diff --git a/cmd/gitlab-shell/main.go b/cmd/gitlab-shell/main.go index 14bd457..2576e8b 100644 --- a/cmd/gitlab-shell/main.go +++ b/cmd/gitlab-shell/main.go @@ -51,7 +51,7 @@ func main() { defer logCloser.Close() env := sshenv.NewFromEnv() - cmd, err := shellCmd.New(executable, os.Args[1:], env, config, readWriter) + cmd, err := shellCmd.New(os.Args[1:], env, config, readWriter) if err != nil { // For now this could happen if `SSH_CONNECTION` is not set on // the environment |