From aab85f3600caf04b491d6ca4fc3f0f004d9e3fc0 Mon Sep 17 00:00:00 2001 From: Patrick Bajao Date: Mon, 29 Jul 2019 14:33:01 +0800 Subject: Support falling back to ruby version of checkers Rename the ruby scripts to have `-ruby` suffix and add a symlink for both to `./gitlab-shell`. The executable name will be used to determine how args will be parsed. For now, we only parse the arguments for gitlab-shell commands. If the executable is `gitlab-shell-authorized-keys-check` or `gitlab-shell-authorized-principals-check`, it'll always fallback to the ruby version. Ruby specs test the ruby script, the fallback from go to ruby and go implementation of both (still pending). --- go/internal/command/fallback/fallback.go | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'go/internal/command/fallback/fallback.go') diff --git a/go/internal/command/fallback/fallback.go b/go/internal/command/fallback/fallback.go index f525a57..cec94d5 100644 --- a/go/internal/command/fallback/fallback.go +++ b/go/internal/command/fallback/fallback.go @@ -1,14 +1,22 @@ package fallback import ( + "fmt" "os" "path/filepath" "syscall" + + "gitlab.com/gitlab-org/gitlab-shell/go/internal/command/commandargs" ) +type CommandArgs interface { + Executable() commandargs.Executable + Arguments() []string +} + type Command struct { RootDir string - Args []string + Args CommandArgs } var ( @@ -16,15 +24,15 @@ var ( execFunc = syscall.Exec ) -const ( - RubyProgram = "gitlab-shell-ruby" -) - func (c *Command) Execute() error { - rubyCmd := filepath.Join(c.RootDir, "bin", RubyProgram) + rubyCmd := filepath.Join(c.RootDir, "bin", c.fallbackProgram()) // Ensure rubyArgs[0] is the full path to gitlab-shell-ruby - rubyArgs := append([]string{rubyCmd}, c.Args[1:]...) + rubyArgs := append([]string{rubyCmd}, c.Args.Arguments()...) return execFunc(rubyCmd, rubyArgs, os.Environ()) } + +func (c *Command) fallbackProgram() string { + return fmt.Sprintf("%s-ruby", c.Args.Executable()) +} -- cgit v1.2.1