mirror of
https://github.com/openziti/zrok.git
synced 2024-11-22 16:13:47 +01:00
moved zrok client creation into zrokdir, to better support the new zrokloop utility (#40)
This commit is contained in:
parent
02d6b7fce9
commit
175f8e8167
@ -36,7 +36,7 @@ func (cmd *disableCommand) run(_ *cobra.Command, args []string) {
|
||||
}
|
||||
panic(err)
|
||||
}
|
||||
zrok, err := newZrokClient(env.ApiEndpoint)
|
||||
zrok, err := zrokdir.ZrokClient(env.ApiEndpoint)
|
||||
if err != nil {
|
||||
if !panicInstead {
|
||||
showError("could not create zrok service client", err)
|
||||
|
@ -56,7 +56,7 @@ func (cmd *enableCommand) run(_ *cobra.Command, args []string) {
|
||||
cmd.description = fmt.Sprintf("%v@%v", user.Username, hostName)
|
||||
}
|
||||
|
||||
zrok, err := newZrokClient(apiEndpoint)
|
||||
zrok, err := zrokdir.ZrokClient(apiEndpoint)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ func (self *httpBackendCommand) run(_ *cobra.Command, args []string) {
|
||||
EndpointAddress: args[0],
|
||||
}
|
||||
|
||||
zrok, err := newZrokClient(env.ApiEndpoint)
|
||||
zrok, err := zrokdir.ZrokClient(env.ApiEndpoint)
|
||||
if err != nil {
|
||||
ui.Close()
|
||||
if !panicInstead {
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/openziti-test-kitchen/zrok/rest_client_zrok/identity"
|
||||
"github.com/openziti-test-kitchen/zrok/rest_model_zrok"
|
||||
"github.com/openziti-test-kitchen/zrok/zrokdir"
|
||||
"github.com/openziti/foundation/v2/term"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
@ -40,7 +41,7 @@ func (cmd *inviteCommand) run(_ *cobra.Command, _ []string) {
|
||||
showError("entered emails do not match... aborting!", nil)
|
||||
}
|
||||
|
||||
zrok, err := newZrokClient(apiEndpoint)
|
||||
zrok, err := zrokdir.ZrokClient(apiEndpoint)
|
||||
if err != nil {
|
||||
if !panicInstead {
|
||||
showError("error creating zrok api client", err)
|
||||
|
@ -1,15 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/go-openapi/runtime"
|
||||
httptransport "github.com/go-openapi/runtime/client"
|
||||
"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"
|
||||
@ -50,14 +44,3 @@ func main() {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func newZrokClient(endpoint string) (*rest_client_zrok.Zrok, error) {
|
||||
apiUrl, err := url.Parse(endpoint)
|
||||
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), nil
|
||||
}
|
||||
|
27
cmd/zrokloop/main.go
Normal file
27
cmd/zrokloop/main.go
Normal file
@ -0,0 +1,27 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: strings.TrimSuffix(filepath.Base(os.Args[0]), filepath.Ext(os.Args[0])),
|
||||
Short: "zrok loopback harness",
|
||||
PersistentPreRun: func(_ *cobra.Command, _ []string) {
|
||||
if verbose {
|
||||
logrus.SetLevel(logrus.DebugLevel)
|
||||
}
|
||||
},
|
||||
}
|
||||
var verbose bool
|
||||
var apiEndpoint string
|
||||
|
||||
func main() {
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
21
zrokdir/client.go
Normal file
21
zrokdir/client.go
Normal file
@ -0,0 +1,21 @@
|
||||
package zrokdir
|
||||
|
||||
import (
|
||||
"github.com/go-openapi/runtime"
|
||||
httptransport "github.com/go-openapi/runtime/client"
|
||||
"github.com/go-openapi/strfmt"
|
||||
"github.com/openziti-test-kitchen/zrok/rest_client_zrok"
|
||||
"github.com/pkg/errors"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
func ZrokClient(endpoint string) (*rest_client_zrok.Zrok, error) {
|
||||
apiUrl, err := url.Parse(endpoint)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "error parsing api endpoint '%v'", endpoint)
|
||||
}
|
||||
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), nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user