diff --git a/cmd/zrok/create.go b/cmd/zrok/create.go index ad382060..6e725b8d 100644 --- a/cmd/zrok/create.go +++ b/cmd/zrok/create.go @@ -50,7 +50,10 @@ func (cmd *createAccountCommand) run(_ *cobra.Command, _ []string) { panic("confirmed password mismatch") } - zrok := newZrokClient() + zrok, err := newZrokClient() + if err != nil { + panic(err) + } req := identity.NewCreateAccountParams() req.Body = &rest_model_zrok.AccountRequest{ Email: email, diff --git a/cmd/zrok/disable.go b/cmd/zrok/disable.go index d6c924e2..39439e68 100644 --- a/cmd/zrok/disable.go +++ b/cmd/zrok/disable.go @@ -33,7 +33,10 @@ func (cmd *disableCommand) run(_ *cobra.Command, args []string) { if err != nil { panic(err) } - zrok := newZrokClient() + zrok, err := newZrokClient() + if err != nil { + panic(err) + } auth := httptransport.APIKeyAuth("X-TOKEN", "header", env.ZrokToken) req := identity.NewDisableParams() req.Body = &rest_model_zrok.DisableRequest{ diff --git a/cmd/zrok/enable.go b/cmd/zrok/enable.go index a44aa243..4dee64db 100644 --- a/cmd/zrok/enable.go +++ b/cmd/zrok/enable.go @@ -55,7 +55,10 @@ func (cmd *enableCommand) run(_ *cobra.Command, args []string) { cmd.description = fmt.Sprintf("%v@%v", user.Username, hostName) } - zrok := newZrokClient() + zrok, err := newZrokClient() + if err != nil { + panic(err) + } auth := httptransport.APIKeyAuth("X-TOKEN", "header", token) req := identity.NewEnableParams() req.Body = &rest_model_zrok.EnableRequest{ diff --git a/cmd/zrok/http_backend.go b/cmd/zrok/http_backend.go index c3295fa4..949c70fb 100644 --- a/cmd/zrok/http_backend.go +++ b/cmd/zrok/http_backend.go @@ -69,7 +69,10 @@ func (self *httpBackendCommand) run(_ *cobra.Command, args []string) { EndpointAddress: args[0], } - zrok := newZrokClient() + zrok, err := newZrokClient() + if err != nil { + panic(err) + } auth := httptransport.APIKeyAuth("X-TOKEN", "header", env.ZrokToken) req := tunnel.NewTunnelParams() req.Body = &rest_model_zrok.TunnelRequest{ diff --git a/cmd/zrok/main.go b/cmd/zrok/main.go index aafddacf..ad9f5343 100644 --- a/cmd/zrok/main.go +++ b/cmd/zrok/main.go @@ -6,8 +6,10 @@ import ( "github.com/go-openapi/strfmt" "github.com/michaelquigley/pfxlog" "github.com/openziti-test-kitchen/zrok/rest_client_zrok" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/spf13/cobra" + "net/url" "os" "path/filepath" "strings" @@ -18,7 +20,7 @@ func init() { rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose logging") apiEndpointDefault := os.Getenv("ZROK_API_ENDPOINT") if apiEndpointDefault == "" { - apiEndpointDefault = "api.zrok.io" + apiEndpointDefault = "https://api.zrok.io" } rootCmd.PersistentFlags().StringVarP(&apiEndpoint, "endpoint", "e", apiEndpointDefault, "zrok API endpoint address") rootCmd.AddCommand(httpCmd) @@ -47,9 +49,13 @@ func main() { } } -func newZrokClient() *rest_client_zrok.Zrok { - transport := httptransport.New(apiEndpoint, "/api/v1", []string{"https", "http"}) +func newZrokClient() (*rest_client_zrok.Zrok, error) { + apiUrl, err := url.Parse(apiEndpoint) + if err != nil { + return nil, errors.Wrapf(err, "error parsing api endpoint '%v'", apiEndpoint) + } + transport := httptransport.New(apiUrl.Host, "/api/v1", []string{apiUrl.Scheme}) transport.Producers["application/zrok.v1+json"] = runtime.JSONProducer() transport.Consumers["application/zrok.v1+json"] = runtime.JSONConsumer() - return rest_client_zrok.New(transport, strfmt.Default) + return rest_client_zrok.New(transport, strfmt.Default), nil }