looper; just starting and stopping endpoints in parallel for now (#40)

This commit is contained in:
Michael Quigley 2022-10-03 12:38:24 -04:00
parent 00c0328661
commit be41138929
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62

View File

@ -1,8 +1,16 @@
package main
import (
"fmt"
httptransport "github.com/go-openapi/runtime/client"
"github.com/openziti-test-kitchen/zrok/model"
"github.com/openziti-test-kitchen/zrok/rest_client_zrok/tunnel"
"github.com/openziti-test-kitchen/zrok/rest_model_zrok"
"github.com/openziti-test-kitchen/zrok/zrokdir"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"math/rand"
"time"
)
func init() {
@ -54,4 +62,36 @@ func (l *looper) run() {
logrus.Infof("starting #%d", l.id)
defer close(l.done)
defer logrus.Infof("stopping #%d", l.id)
env, err := zrokdir.LoadEnvironment()
if err != nil {
panic(err)
}
zrok, err := zrokdir.ZrokClient(env.ApiEndpoint)
if err != nil {
panic(err)
}
auth := httptransport.APIKeyAuth("x-token", "header", env.ZrokToken)
tunnelReq := tunnel.NewTunnelParams()
tunnelReq.Body = &rest_model_zrok.TunnelRequest{
ZitiIdentityID: env.ZitiIdentityId,
Endpoint: fmt.Sprintf("looper#%d", l.id),
AuthScheme: string(model.None),
}
tunnelResp, err := zrok.Tunnel.Tunnel(tunnelReq, auth)
if err != nil {
panic(err)
}
logrus.Infof("service: %v, frontend: %v", tunnelResp.Payload.Service, tunnelResp.Payload.ProxyEndpoint)
time.Sleep(time.Duration(rand.Intn(5000)) * time.Millisecond)
untunnelReq := tunnel.NewUntunnelParams()
untunnelReq.Body = &rest_model_zrok.UntunnelRequest{
ZitiIdentityID: env.ZitiIdentityId,
Service: tunnelResp.Payload.Service,
}
if _, err := zrok.Tunnel.Untunnel(untunnelReq, auth); err != nil {
logrus.Errorf("error shutting down looper #%d: %v", l.id, err)
}
}