mirror of
https://github.com/openziti/zrok.git
synced 2025-06-19 17:27:54 +02:00
looper; just starting and stopping endpoints in parallel for now (#40)
This commit is contained in:
parent
00c0328661
commit
be41138929
@ -1,8 +1,16 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
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/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"math/rand"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -54,4 +62,36 @@ func (l *looper) run() {
|
|||||||
logrus.Infof("starting #%d", l.id)
|
logrus.Infof("starting #%d", l.id)
|
||||||
defer close(l.done)
|
defer close(l.done)
|
||||||
defer logrus.Infof("stopping #%d", l.id)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user