better support for http or https zrok api endpoint urls

This commit is contained in:
Michael Quigley 2022-09-09 16:19:50 -04:00
parent 47010fe483
commit 66509ca212
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
5 changed files with 26 additions and 8 deletions

View File

@ -50,7 +50,10 @@ func (cmd *createAccountCommand) run(_ *cobra.Command, _ []string) {
panic("confirmed password mismatch") panic("confirmed password mismatch")
} }
zrok := newZrokClient() zrok, err := newZrokClient()
if err != nil {
panic(err)
}
req := identity.NewCreateAccountParams() req := identity.NewCreateAccountParams()
req.Body = &rest_model_zrok.AccountRequest{ req.Body = &rest_model_zrok.AccountRequest{
Email: email, Email: email,

View File

@ -33,7 +33,10 @@ func (cmd *disableCommand) run(_ *cobra.Command, args []string) {
if err != nil { if err != nil {
panic(err) panic(err)
} }
zrok := newZrokClient() zrok, err := newZrokClient()
if err != nil {
panic(err)
}
auth := httptransport.APIKeyAuth("X-TOKEN", "header", env.ZrokToken) auth := httptransport.APIKeyAuth("X-TOKEN", "header", env.ZrokToken)
req := identity.NewDisableParams() req := identity.NewDisableParams()
req.Body = &rest_model_zrok.DisableRequest{ req.Body = &rest_model_zrok.DisableRequest{

View File

@ -55,7 +55,10 @@ func (cmd *enableCommand) run(_ *cobra.Command, args []string) {
cmd.description = fmt.Sprintf("%v@%v", user.Username, hostName) 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) auth := httptransport.APIKeyAuth("X-TOKEN", "header", token)
req := identity.NewEnableParams() req := identity.NewEnableParams()
req.Body = &rest_model_zrok.EnableRequest{ req.Body = &rest_model_zrok.EnableRequest{

View File

@ -69,7 +69,10 @@ func (self *httpBackendCommand) run(_ *cobra.Command, args []string) {
EndpointAddress: args[0], EndpointAddress: args[0],
} }
zrok := newZrokClient() zrok, err := newZrokClient()
if err != nil {
panic(err)
}
auth := httptransport.APIKeyAuth("X-TOKEN", "header", env.ZrokToken) auth := httptransport.APIKeyAuth("X-TOKEN", "header", env.ZrokToken)
req := tunnel.NewTunnelParams() req := tunnel.NewTunnelParams()
req.Body = &rest_model_zrok.TunnelRequest{ req.Body = &rest_model_zrok.TunnelRequest{

View File

@ -6,8 +6,10 @@ import (
"github.com/go-openapi/strfmt" "github.com/go-openapi/strfmt"
"github.com/michaelquigley/pfxlog" "github.com/michaelquigley/pfxlog"
"github.com/openziti-test-kitchen/zrok/rest_client_zrok" "github.com/openziti-test-kitchen/zrok/rest_client_zrok"
"github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"net/url"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -18,7 +20,7 @@ func init() {
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose logging") rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose logging")
apiEndpointDefault := os.Getenv("ZROK_API_ENDPOINT") apiEndpointDefault := os.Getenv("ZROK_API_ENDPOINT")
if apiEndpointDefault == "" { if apiEndpointDefault == "" {
apiEndpointDefault = "api.zrok.io" apiEndpointDefault = "https://api.zrok.io"
} }
rootCmd.PersistentFlags().StringVarP(&apiEndpoint, "endpoint", "e", apiEndpointDefault, "zrok API endpoint address") rootCmd.PersistentFlags().StringVarP(&apiEndpoint, "endpoint", "e", apiEndpointDefault, "zrok API endpoint address")
rootCmd.AddCommand(httpCmd) rootCmd.AddCommand(httpCmd)
@ -47,9 +49,13 @@ func main() {
} }
} }
func newZrokClient() *rest_client_zrok.Zrok { func newZrokClient() (*rest_client_zrok.Zrok, error) {
transport := httptransport.New(apiEndpoint, "/api/v1", []string{"https", "http"}) 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.Producers["application/zrok.v1+json"] = runtime.JSONProducer()
transport.Consumers["application/zrok.v1+json"] = runtime.JSONConsumer() 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
} }