From ea329aed6909cac85680dbae37f6f4dcca134f8b Mon Sep 17 00:00:00 2001 From: Sascha Date: Sun, 28 Feb 2021 16:27:14 +0100 Subject: [PATCH] Add option to specify host address '--host'-cmdline-option is added to the webui command. Previously, the WebUI couldn't be hosted inside of a container. As the WebUI-server only listend per default to localhost and there was no option to change the address, the server should listend to. This means, that the WebUI was only reachable from localhost. So only from inside of the container but never from outside. The '--host'-option allows to set the IP address or a hostname which the WebUI-server should listen to. E.g. by setting 0.0.0.0 or :: as address. Update documentation for new option. Update shell completion for new option. Compilation seems to add another go-gitlab version. --- commands/webui.go | 8 ++++++-- doc/man/git-bug-webui.1 | 6 +++++- doc/md/git-bug_webui.md | 11 ++++++----- go.sum | 1 + misc/bash_completion/git-bug | 4 ++++ 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/commands/webui.go b/commands/webui.go index 7e5fc75206d060fed6c015f0987f04bce37ceb7d..d910a7034794ecf0ff5d41fa3233c2a6d9944711 100644 --- a/commands/webui.go +++ b/commands/webui.go @@ -4,9 +4,11 @@ import ( "context" "fmt" "log" + "net" "net/http" "os" "os/signal" + "strconv" "time" "github.com/99designs/gqlgen/graphql/playground" @@ -27,6 +29,7 @@ import ( const webUIOpenConfigKey = "git-bug.webui.open" type webUIOptions struct { + host string port int open bool noOpen bool @@ -54,9 +57,10 @@ Available git config: flags := cmd.Flags() flags.SortFlags = false + flags.StringVar(&options.host, "host", "127.0.0.1", "Network address or hostname to listen to (default to 127.0.0.1)") flags.BoolVar(&options.open, "open", false, "Automatically open the web UI in the default browser") flags.BoolVar(&options.noOpen, "no-open", false, "Prevent the automatic opening of the web UI in the default browser") - flags.IntVarP(&options.port, "port", "p", 0, "Port to listen to (default is random)") + flags.IntVarP(&options.port, "port", "p", 0, "Port to listen to (default to random available port)") flags.BoolVar(&options.readOnly, "read-only", false, "Whether to run the web UI in read-only mode") return cmd @@ -71,7 +75,7 @@ func runWebUI(env *Env, opts webUIOptions, args []string) error { } } - addr := fmt.Sprintf("127.0.0.1:%d", opts.port) + addr := net.JoinHostPort(opts.host, strconv.Itoa(opts.port)) webUiAddr := fmt.Sprintf("http://%s", addr) router := mux.NewRouter() diff --git a/doc/man/git-bug-webui.1 b/doc/man/git-bug-webui.1 index 954250a280bf497abbf845d94a047e8da5c080e3..6e4622be77b4cb36d29f09200798bbc3d5afd811 100644 --- a/doc/man/git-bug-webui.1 +++ b/doc/man/git-bug-webui.1 @@ -21,6 +21,10 @@ Available git config: .SH OPTIONS +.PP +\fB\-\-host\fP="127.0.0.1" + Network address or hostname to listen to (default to 127.0.0.1) + .PP \fB\-\-open\fP[=false] Automatically open the web UI in the default browser @@ -31,7 +35,7 @@ Available git config: .PP \fB\-p\fP, \fB\-\-port\fP=0 - Port to listen to (default is random) + Port to listen to (default to random available port) .PP \fB\-\-read\-only\fP[=false] diff --git a/doc/md/git-bug_webui.md b/doc/md/git-bug_webui.md index 98a61eb2b8c6fdb5d49e504b77f6704d63dee7a9..ccfaff9a6e9540f084c7ae0ac420d8a1b410442e 100644 --- a/doc/md/git-bug_webui.md +++ b/doc/md/git-bug_webui.md @@ -17,11 +17,12 @@ git-bug webui [flags] ### Options ``` - --open Automatically open the web UI in the default browser - --no-open Prevent the automatic opening of the web UI in the default browser - -p, --port int Port to listen to (default is random) - --read-only Whether to run the web UI in read-only mode - -h, --help help for webui + --host string Network address or hostname to listen to (default to 127.0.0.1) (default "127.0.0.1") + --open Automatically open the web UI in the default browser + --no-open Prevent the automatic opening of the web UI in the default browser + -p, --port int Port to listen to (default to random available port) + --read-only Whether to run the web UI in read-only mode + -h, --help help for webui ``` ### SEE ALSO diff --git a/go.sum b/go.sum index 2cfdff75edf8320a667e0b8f9a3e4c5dd590993d..b13e190e94a8fb00d370a3a91fa441e9f92567ad 100644 --- a/go.sum +++ b/go.sum @@ -476,6 +476,7 @@ github.com/willf/bitset v1.1.10 h1:NotGKqX0KwQ72NUzqrjZq5ipPNDQex9lo3WpaS8L2sc= github.com/willf/bitset v1.1.10/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4= github.com/xanzy/go-gitlab v0.40.1 h1:jHueLh5Inzv20TL5Yki+CaLmyvtw3Yq7blbWx7GmglQ= github.com/xanzy/go-gitlab v0.40.1/go.mod h1:sPLojNBn68fMUWSxIJtdVVIP8uSBYqesTfDUseX11Ug= +github.com/xanzy/go-gitlab v0.44.0 h1:cEiGhqu7EpFGuei2a2etAwB+x6403E5CvpLn35y+GPs= github.com/xanzy/go-gitlab v0.44.0/go.mod h1:sPLojNBn68fMUWSxIJtdVVIP8uSBYqesTfDUseX11Ug= github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4= github.com/xanzy/ssh-agent v0.3.0 h1:wUMzuKtKilRgBAD1sUb8gOwwRr2FGoBVumcjoOACClI= diff --git a/misc/bash_completion/git-bug b/misc/bash_completion/git-bug index 3cedd86a118dbcf036e13a01e4f936a2fdf1d8e9..8f2a0f8f3e7e1c2bba629787b5f5ea790c82906c 100644 --- a/misc/bash_completion/git-bug +++ b/misc/bash_completion/git-bug @@ -1331,6 +1331,10 @@ _git-bug_webui() flags_with_completion=() flags_completion=() + flags+=("--host=") + two_word_flags+=("--host") + local_nonpersistent_flags+=("--host") + local_nonpersistent_flags+=("--host=") flags+=("--open") local_nonpersistent_flags+=("--open") flags+=("--no-open")