mirror of
https://github.com/openziti/ziti.git
synced 2026-10-13 15:51:21 +00:00
4b2d97d293
* Merge branch 'action-test' of github.com:openziti/ziti into simple-transfer-test * added metricbeat initialization * updates to the simple network testing * update zitilab and fablad deps and integrate env variables * removed incorrect file * move env up to top * added run and test * mod tidy * mod got out of sync * remove influx logging from ziti-probe due to being removed from metrics * add ls to see why simple-transfer isnt built * dig deeper * need to copy not move * back to release dir * might need to sudo * mke files executable * bootsrap from correct directory * add extra restart to confirm network spins up * add retry for inrastructure * build correct binaries * add build ignore ot stages as well * don't return error after successful retry * fix err assign * update zitilab version * removed local testing paths * update configs and env variables * added env prepend * remove build number for debugging * add different formatting * updated build/run number * paren in incorrect place * added specific version of metricbeat to install * flip back correct ziti loc * removed builds for mac & windows * Removed test build for mac & windows * remove ziti-probe * flip ziti test to run alongside mac & windows builds * remove unneeded needs * remove for sanity check * remove old uploads * remove space * setup ziti version properly * remove zitilab testing to confirm running * try removing all changes? * remove even comments? * I dont understand * revert * start from scratch. Small increments. * simplify first job? * try spearating build and publish * run all 3 builds at the same time * missed env variables * update to run zitilab tests * corrected dirs * fixing ziti root * redo build in publish step * applied pr comments * add in mkdir and remove buildint test binaries in publish step * forgot to remove move * update linux build requirement to 1.19
77 lines
1.4 KiB
Go
77 lines
1.4 KiB
Go
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
"log"
|
|
"net"
|
|
"net/http"
|
|
"net/url"
|
|
"strings"
|
|
|
|
"github.com/openziti/sdk-golang/ziti"
|
|
"github.com/openziti/sdk-golang/ziti/config"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var clientCmd = &cobra.Command{
|
|
Use: "client {string-to-echo}",
|
|
Short: "Simple ziti enabled echo client",
|
|
Args: cobra.MinimumNArgs(1),
|
|
Run: echoClient,
|
|
}
|
|
|
|
func init() {
|
|
clientCmd.Flags().SetInterspersed(true)
|
|
rootCmd.AddCommand(clientCmd)
|
|
}
|
|
|
|
func echoClient(cmd *cobra.Command, args []string) {
|
|
cfg, err := config.NewFromFile(identityFile)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
zitiContext := ziti.NewContextWithConfig(cfg)
|
|
|
|
dial := func(_ context.Context, _, addr string) (net.Conn, error) {
|
|
service := strings.Split(addr, ":")[0]
|
|
return zitiContext.Dial(service)
|
|
}
|
|
|
|
zitiTransport := http.DefaultTransport.(*http.Transport).Clone()
|
|
zitiTransport.DialContext = dial
|
|
|
|
zec := &zitiEchoClient{
|
|
client: &http.Client{Transport: zitiTransport},
|
|
}
|
|
|
|
resp, err := zec.Echo(strings.Join(args, " "))
|
|
if resp != "" {
|
|
fmt.Print(resp)
|
|
}
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
|
|
type zitiEchoClient struct {
|
|
client *http.Client
|
|
}
|
|
|
|
func (zec *zitiEchoClient) Echo(input string) (string, error) {
|
|
u := fmt.Sprintf("http://echo?input=%v", url.QueryEscape(input))
|
|
resp, err := zec.client.Get(u)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
b, err := io.ReadAll(resp.Body)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return string(b), err
|
|
}
|