mirror of
https://github.com/openziti/ziti.git
synced 2026-10-13 07:41:17 +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
86 lines
1.7 KiB
Go
86 lines
1.7 KiB
Go
package cmd
|
|
|
|
import (
|
|
"log"
|
|
"net"
|
|
"net/http"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
"time"
|
|
|
|
"github.com/openziti/sdk-golang/ziti"
|
|
"github.com/openziti/sdk-golang/ziti/config"
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var serverCmd = &cobra.Command{
|
|
Use: "server",
|
|
Short: "Simple Ziti enabled echo serer",
|
|
Run: runServer,
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(serverCmd)
|
|
}
|
|
|
|
func runServer(cmd *cobra.Command, args []string) {
|
|
sigs := make(chan os.Signal, 1)
|
|
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
|
|
|
echoServer := &zitiEchoServer{
|
|
identityJson: identityFile,
|
|
}
|
|
|
|
if err := echoServer.run(); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
for {
|
|
select {
|
|
case <-time.After(10 * time.Second):
|
|
logrus.Debug("Beating to show server still running")
|
|
case <-sigs:
|
|
logrus.Info("Server shutting down...")
|
|
return
|
|
}
|
|
}
|
|
}
|
|
|
|
type zitiEchoServer struct {
|
|
identityJson string
|
|
listener net.Listener
|
|
}
|
|
|
|
func (s *zitiEchoServer) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
|
|
input := r.URL.Query().Get("input")
|
|
result := input
|
|
logrus.Infof("\nziti-http-echo-server: ")
|
|
logrus.Infof("received input '%v'\n", input)
|
|
if _, err := rw.Write([]byte(result)); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func (s *zitiEchoServer) run() (err error) {
|
|
config, err := config.NewFromFile(s.identityJson)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
zitiContext := ziti.NewContextWithConfig(config)
|
|
if s.listener, err = zitiContext.Listen("echo"); err != nil {
|
|
return err
|
|
}
|
|
|
|
logrus.Info("\nziti-http-echo-server: ")
|
|
logrus.Info("listening for connections from echo server")
|
|
go func() { _ = http.Serve(s.listener, http.HandlerFunc(s.ServeHTTP)) }()
|
|
return nil
|
|
}
|
|
|
|
func (s *zitiEchoServer) stop() error {
|
|
return s.listener.Close()
|
|
}
|