From 2871d9bdd8a9ba6aa3a7e9a1645374906a0232e1 Mon Sep 17 00:00:00 2001 From: Cam Otts Date: Mon, 6 Mar 2023 13:36:03 -0600 Subject: [PATCH 1/3] Added validation on setting apiEndpoint. Requires scheme and host to be present. --- cmd/zrok/configSet.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/cmd/zrok/configSet.go b/cmd/zrok/configSet.go index 8b9837e9..0244683a 100644 --- a/cmd/zrok/configSet.go +++ b/cmd/zrok/configSet.go @@ -2,10 +2,12 @@ package main import ( "fmt" + "net/url" + "os" + "github.com/openziti/zrok/tui" "github.com/openziti/zrok/zrokdir" "github.com/spf13/cobra" - "os" ) func init() { @@ -42,6 +44,15 @@ func (cmd *configSetCommand) run(_ *cobra.Command, args []string) { if zrd.Cfg == nil { zrd.Cfg = &zrokdir.Config{} } + ok, err := isValidUrl(value) + if err != nil { + fmt.Println("unable to validate api endpoint") + os.Exit(1) + } + if !ok { + fmt.Println("invalid apiEndpoint, please make sure scheme and host is provided") + os.Exit(1) + } zrd.Cfg.ApiEndpoint = value modified = true @@ -62,3 +73,14 @@ func (cmd *configSetCommand) run(_ *cobra.Command, args []string) { fmt.Println("zrok configuration not changed") } } + +func isValidUrl(rawUrl string) (bool, error) { + u, err := url.Parse(rawUrl) + if err != nil { + return false, err + } + if u.Scheme == "" || u.Host == "" { + return false, nil + } + return true, nil +} From 6e17f4df3ac7236955d8339cfa054c107baef7c2 Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Fri, 10 Mar 2023 16:33:58 -0500 Subject: [PATCH 2/3] apiEndpoint validation tweaks (#260) --- .gitignore | 2 ++ cmd/zrok/configSet.go | 10 ++++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 337fee57..12c12704 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ *.db automated-release-build etc/dev.yml +etc/dev-metrics.yml # Dependencies /node_modules/ @@ -28,3 +29,4 @@ npm-debug.log* yarn-debug.log* yarn-error.log* +.obsidian diff --git a/cmd/zrok/configSet.go b/cmd/zrok/configSet.go index 0244683a..a72d29f4 100644 --- a/cmd/zrok/configSet.go +++ b/cmd/zrok/configSet.go @@ -44,14 +44,12 @@ func (cmd *configSetCommand) run(_ *cobra.Command, args []string) { if zrd.Cfg == nil { zrd.Cfg = &zrokdir.Config{} } - ok, err := isValidUrl(value) + ok, err := isFullyValidUrl(value) if err != nil { - fmt.Println("unable to validate api endpoint") - os.Exit(1) + tui.Error("unable to validate api endpoint", err) } if !ok { - fmt.Println("invalid apiEndpoint, please make sure scheme and host is provided") - os.Exit(1) + tui.Error("invalid apiEndpoint; please make sure URL starts with http:// or https://", nil) } zrd.Cfg.ApiEndpoint = value modified = true @@ -74,7 +72,7 @@ func (cmd *configSetCommand) run(_ *cobra.Command, args []string) { } } -func isValidUrl(rawUrl string) (bool, error) { +func isFullyValidUrl(rawUrl string) (bool, error) { u, err := url.Parse(rawUrl) if err != nil { return false, err From 7d1b6192f17deb3f910b8876a2457966c3c8db0e Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Fri, 10 Mar 2023 16:35:12 -0500 Subject: [PATCH 3/3] changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 882ce4a5..a22c3ee8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# v0.3.5 + +CHANGE: `zrok config set apiEndpoint` now validates that the new API endpoint correctly starts with `http://` or `https://` (https://github.com/openziti/zrok/issues/258) + # v0.3.4 CHANGE: `zrok test endpoint` incorporates `--ziti` mode (and related flags) to allow direct endpoint listening on a Ziti service