mirror of
https://github.com/openziti/zrok.git
synced 2025-06-20 09:48:07 +02:00
add shutdown hook to access private tunnel (#305)
This commit is contained in:
parent
fdc038c12d
commit
35dec16236
@ -153,11 +153,11 @@ func (cmd *accessPrivateCommand) run(_ *cobra.Command, args []string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cmd *accessPrivateCommand) destroy(frotendName, envZId, shrToken string, zrok *rest_client_zrok.Zrok, auth runtime.ClientAuthInfoWriter) {
|
func (cmd *accessPrivateCommand) destroy(frontendName, envZId, shrToken string, zrok *rest_client_zrok.Zrok, auth runtime.ClientAuthInfoWriter) {
|
||||||
logrus.Debugf("shutting down '%v'", shrToken)
|
logrus.Debugf("shutting down '%v'", shrToken)
|
||||||
req := share.NewUnaccessParams()
|
req := share.NewUnaccessParams()
|
||||||
req.Body = &rest_model_zrok.UnaccessRequest{
|
req.Body = &rest_model_zrok.UnaccessRequest{
|
||||||
FrontendToken: frotendName,
|
FrontendToken: frontendName,
|
||||||
ShrToken: shrToken,
|
ShrToken: shrToken,
|
||||||
EnvZID: envZId,
|
EnvZID: envZId,
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,19 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/go-openapi/runtime"
|
||||||
httptransport "github.com/go-openapi/runtime/client"
|
httptransport "github.com/go-openapi/runtime/client"
|
||||||
"github.com/openziti/zrok/endpoints/tcpTunnel"
|
"github.com/openziti/zrok/endpoints/tcpTunnel"
|
||||||
|
"github.com/openziti/zrok/rest_client_zrok"
|
||||||
"github.com/openziti/zrok/rest_client_zrok/share"
|
"github.com/openziti/zrok/rest_client_zrok/share"
|
||||||
"github.com/openziti/zrok/rest_model_zrok"
|
"github.com/openziti/zrok/rest_model_zrok"
|
||||||
"github.com/openziti/zrok/tui"
|
"github.com/openziti/zrok/tui"
|
||||||
"github.com/openziti/zrok/zrokdir"
|
"github.com/openziti/zrok/zrokdir"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -63,6 +68,14 @@ func (cmd *accessPrivateTunnelCommand) run(_ *cobra.Command, args []string) {
|
|||||||
}
|
}
|
||||||
logrus.Infof("allocated frontend '%v'", accessResp.Payload.FrontendToken)
|
logrus.Infof("allocated frontend '%v'", accessResp.Payload.FrontendToken)
|
||||||
|
|
||||||
|
c := make(chan os.Signal)
|
||||||
|
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||||
|
go func() {
|
||||||
|
<-c
|
||||||
|
cmd.destroy(accessResp.Payload.FrontendToken, zrd.Env.ZId, args[0], zrok, auth)
|
||||||
|
os.Exit(0)
|
||||||
|
}()
|
||||||
|
|
||||||
fe, err := tcpTunnel.NewFrontend(&tcpTunnel.FrontendConfig{
|
fe, err := tcpTunnel.NewFrontend(&tcpTunnel.FrontendConfig{
|
||||||
BindAddress: cmd.bindAddress,
|
BindAddress: cmd.bindAddress,
|
||||||
IdentityName: "backend",
|
IdentityName: "backend",
|
||||||
@ -78,3 +91,18 @@ func (cmd *accessPrivateTunnelCommand) run(_ *cobra.Command, args []string) {
|
|||||||
time.Sleep(50)
|
time.Sleep(50)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (cmd *accessPrivateTunnelCommand) destroy(frontendName, envZId, shrToken string, zrok *rest_client_zrok.Zrok, auth runtime.ClientAuthInfoWriter) {
|
||||||
|
logrus.Debugf("shutting down '%v'", shrToken)
|
||||||
|
req := share.NewUnaccessParams()
|
||||||
|
req.Body = &rest_model_zrok.UnaccessRequest{
|
||||||
|
FrontendToken: frontendName,
|
||||||
|
ShrToken: shrToken,
|
||||||
|
EnvZID: envZId,
|
||||||
|
}
|
||||||
|
if _, err := zrok.Share.Unaccess(req, auth); err == nil {
|
||||||
|
logrus.Debugf("shutdown complete")
|
||||||
|
} else {
|
||||||
|
logrus.Errorf("error shutting down: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user