mirror of
https://github.com/openziti/zrok.git
synced 2025-06-21 10:17:51 +02:00
Added validation on setting apiEndpoint.
Requires scheme and host to be present.
This commit is contained in:
parent
5a2340e121
commit
2871d9bdd8
@ -2,10 +2,12 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/openziti/zrok/tui"
|
"github.com/openziti/zrok/tui"
|
||||||
"github.com/openziti/zrok/zrokdir"
|
"github.com/openziti/zrok/zrokdir"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -42,6 +44,15 @@ func (cmd *configSetCommand) run(_ *cobra.Command, args []string) {
|
|||||||
if zrd.Cfg == nil {
|
if zrd.Cfg == nil {
|
||||||
zrd.Cfg = &zrokdir.Config{}
|
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
|
zrd.Cfg.ApiEndpoint = value
|
||||||
modified = true
|
modified = true
|
||||||
|
|
||||||
@ -62,3 +73,14 @@ func (cmd *configSetCommand) run(_ *cobra.Command, args []string) {
|
|||||||
fmt.Println("zrok configuration not changed")
|
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
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user