diff options
author | Nick Thomas <nick@gitlab.com> | 2018-08-28 10:37:07 +0200 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2018-09-28 04:24:52 +0100 |
commit | 1f8556b2f86d7954f86f4a9a58f586a838f8ae21 (patch) | |
tree | 79fd8ba537a8073b0b9b32cabc39dcd4cafe258f | |
parent | 1cc2993f357c4467e4d45c54c01d2307103efb3e (diff) | |
download | gitlab-shell-1f8556b2f86d7954f86f4a9a58f586a838f8ae21.tar.gz |
Initial feature-flagged go/ruby switch
-rw-r--r-- | .gitignore | 1 | ||||
-rwxr-xr-x | bin/gitlab-shell-ruby (renamed from bin/gitlab-shell) | 0 | ||||
-rw-r--r-- | config.yml.example | 3 | ||||
-rw-r--r-- | go/cmd/gitlab-shell/main.go | 36 | ||||
-rw-r--r-- | go/internal/config/config.go | 7 | ||||
-rw-r--r-- | go/internal/config/config_test.go | 12 |
6 files changed, 53 insertions, 6 deletions
@@ -12,6 +12,7 @@ tags custom_hooks hooks/*.d /go_build +/bin/gitlab-shell /bin/gitaly-upload-pack /bin/gitaly-receive-pack /bin/gitaly-upload-archive diff --git a/bin/gitlab-shell b/bin/gitlab-shell-ruby index 93a79f6..93a79f6 100755 --- a/bin/gitlab-shell +++ b/bin/gitlab-shell-ruby diff --git a/config.yml.example b/config.yml.example index 23743fd..49f5d78 100644 --- a/config.yml.example +++ b/config.yml.example @@ -49,3 +49,6 @@ log_level: INFO # Set to true to see real usernames in the logs instead of key ids, which is easier to follow, but # incurs an extra API call on every gitlab-shell command. audit_usernames: false + +# Feature flag: go or ruby +experimental: false diff --git a/go/cmd/gitlab-shell/main.go b/go/cmd/gitlab-shell/main.go new file mode 100644 index 0000000..53632a1 --- /dev/null +++ b/go/cmd/gitlab-shell/main.go @@ -0,0 +1,36 @@ +package main + +import ( + "fmt" + "os" + "path/filepath" + "syscall" + + "gitlab.com/gitlab-org/gitlab-shell/go/internal/config" +) + +func experiment() { + fmt.Println("Experiment! nothing works!") + os.Exit(1) +} + +func main() { + root := filepath.Dir(os.Args[0]) + ruby := filepath.Join(root, "gitlab-shell-ruby") + + config, err := config.New() + if err != nil { + fmt.Println(err) + os.Exit(1) + } + + if config.Experimental { + experiment() + } else { + execErr := syscall.Exec(ruby, os.Args, os.Environ()) + if execErr != nil { + fmt.Fprintf(os.Stderr, "Failed to exec(%q): %v\n", ruby, execErr) + os.Exit(1) + } + } +} diff --git a/go/internal/config/config.go b/go/internal/config/config.go index 7d521f5..64822c7 100644 --- a/go/internal/config/config.go +++ b/go/internal/config/config.go @@ -14,9 +14,10 @@ const ( ) type Config struct { - RootDir string - LogFile string `yaml:"log_file"` - LogFormat string `yaml:"log_format"` + RootDir string + LogFile string `yaml:"log_file"` + LogFormat string `yaml:"log_format"` + Experimental bool `yaml:"experimental"` } func New() (*Config, error) { diff --git a/go/internal/config/config_test.go b/go/internal/config/config_test.go index 0a5c842..552a600 100644 --- a/go/internal/config/config_test.go +++ b/go/internal/config/config_test.go @@ -8,14 +8,16 @@ import ( func TestConfigLogFile(t *testing.T) { testRoot := "/foo/bar" testCases := []struct { - yaml string - path string - format string + yaml string + path string + format string + experimental bool }{ {path: "/foo/bar/gitlab-shell.log", format: "text"}, {yaml: "log_file: my-log.log", path: "/foo/bar/my-log.log", format: "text"}, {yaml: "log_file: /qux/my-log.log", path: "/qux/my-log.log", format: "text"}, {yaml: "log_format: json", path: "/foo/bar/gitlab-shell.log", format: "json"}, + {yaml: "experimental: true", path: "/foo/bar/gitlab-shell.log", format: "text", experimental: true}, } for _, tc := range testCases { @@ -25,6 +27,10 @@ func TestConfigLogFile(t *testing.T) { t.Fatal(err) } + if cfg.Experimental != tc.experimental { + t.Fatalf("expected %v, got %v", tc.experimental, cfg.Experimental) + } + if cfg.LogFile != tc.path { t.Fatalf("expected %q, got %q", tc.path, cfg.LogFile) } |