apiEndpoint validation tweaks (#260)

This commit is contained in:
Michael Quigley 2023-03-10 16:33:58 -05:00
parent 1c39fd5f3e
commit 6e17f4df3a
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
2 changed files with 6 additions and 6 deletions

2
.gitignore vendored
View File

@ -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

View File

@ -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