summaryrefslogtreecommitdiff
path: root/go/cmd/gitlab-shell
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2018-12-21 18:05:18 +0100
committerBob Van Landuyt <bob@vanlanduyt.co>2019-01-15 11:51:38 +0100
commit7215126b6674abd4b5ff6b97d30bab6c544bf8df (patch)
tree80afaa50573476962cd8b531678ddb8b77ae8c63 /go/cmd/gitlab-shell
parent0cbbe1e3b555b3d62b2cb5a6a17c5c4992e3619d (diff)
downloadgitlab-shell-7215126b6674abd4b5ff6b97d30bab6c544bf8df.tar.gz
Allow enabling gitlab-shell "discover"-feature
This adds the possibility to enable features for GitLab shell. The first feature being recognized is "Discover": It's the command that is executed when running `ssh git@gitlab.example.com` and is called without a command. The gitlab key id or username is already parsed from the command line arguments. Currently we only support communicating with GitLab-rails using unix sockets. So features will not be enabled if the GitLab-url is using a different protocol. The url for this read from the config yaml. Pending ruby-specs have been added for the gitlab-shell command. Refactor to have separate command packages
Diffstat (limited to 'go/cmd/gitlab-shell')
-rw-r--r--go/cmd/gitlab-shell/main.go35
1 files changed, 18 insertions, 17 deletions
diff --git a/go/cmd/gitlab-shell/main.go b/go/cmd/gitlab-shell/main.go
index ae54151..9e7f2cb 100644
--- a/go/cmd/gitlab-shell/main.go
+++ b/go/cmd/gitlab-shell/main.go
@@ -4,8 +4,9 @@ import (
"fmt"
"os"
"path/filepath"
- "syscall"
+ "gitlab.com/gitlab-org/gitlab-shell/go/internal/command"
+ "gitlab.com/gitlab-org/gitlab-shell/go/internal/command/fallback"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/config"
)
@@ -19,20 +20,12 @@ func init() {
rootDir = filepath.Dir(binDir)
}
-func migrate(*config.Config) (int, bool) {
- // TODO: Dispatch appropriate requests to Go handlers and return
- // <exitstatus, true> depending on how they fare
- return 0, false
-}
-
// rubyExec will never return. It either replaces the current process with a
// Ruby interpreter, or outputs an error and kills the process.
func execRuby() {
- rubyCmd := filepath.Join(binDir, "gitlab-shell-ruby")
-
- execErr := syscall.Exec(rubyCmd, os.Args, os.Environ())
- if execErr != nil {
- fmt.Fprintf(os.Stderr, "Failed to exec(%q): %v\n", rubyCmd, execErr)
+ cmd := &fallback.Command{}
+ if err := cmd.Execute(); err != nil {
+ fmt.Fprintf(os.Stderr, "Failed to exec: %v\n", err)
os.Exit(1)
}
}
@@ -46,11 +39,19 @@ func main() {
execRuby()
}
- // Try to handle the command with the Go implementation
- if exitCode, done := migrate(config); done {
- os.Exit(exitCode)
+ cmd, err := command.New(os.Args, config)
+ if err != nil {
+ // Failed to build the command, fall back to ruby.
+ // For now this could happen if `SSH_CONNECTION` is not set on
+ // the environment
+ fmt.Fprintf(os.Stderr, "Failed to build command: %v\n", err)
+ execRuby()
}
- // Since a migration has not handled the command, fall back to Ruby to do so
- execRuby()
+ // The command will write to STDOUT on execution or replace the current
+ // process in case of the `fallback.Command`
+ if err = cmd.Execute(); err != nil {
+ fmt.Fprintf(os.Stderr, "%s\n", err)
+ os.Exit(1)
+ }
}