mirror of
https://github.com/openziti/zrok.git
synced 2024-11-22 16:13:47 +01:00
parent
b852518a0d
commit
91849caf25
@ -61,4 +61,13 @@ func handleHttp(_ *cobra.Command, args []string) {
|
|||||||
|
|
||||||
func cleanupHttp(cfg *http.Config, zrok *rest_client_zrok.Zrok) {
|
func cleanupHttp(cfg *http.Config, zrok *rest_client_zrok.Zrok) {
|
||||||
logrus.Infof("shutting down '%v'", cfg.Service)
|
logrus.Infof("shutting down '%v'", cfg.Service)
|
||||||
|
req := tunnel.NewUntunnelParams()
|
||||||
|
req.Body = &rest_model_zrok.UntunnelRequest{
|
||||||
|
Service: cfg.Service,
|
||||||
|
}
|
||||||
|
if _, err := zrok.Tunnel.Untunnel(req); err == nil {
|
||||||
|
logrus.Infof("shutdown complete")
|
||||||
|
} else {
|
||||||
|
logrus.Errorf("error shutting down: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ func Run(cfg *Config) error {
|
|||||||
api.IdentityCreateAccountHandler = identity.CreateAccountHandlerFunc(createAccountHandler)
|
api.IdentityCreateAccountHandler = identity.CreateAccountHandlerFunc(createAccountHandler)
|
||||||
api.IdentityEnableHandler = identity.EnableHandlerFunc(enableHandler)
|
api.IdentityEnableHandler = identity.EnableHandlerFunc(enableHandler)
|
||||||
api.TunnelTunnelHandler = tunnel.TunnelHandlerFunc(tunnelHandler)
|
api.TunnelTunnelHandler = tunnel.TunnelHandlerFunc(tunnelHandler)
|
||||||
|
api.TunnelUntunnelHandler = tunnel.UntunnelHandlerFunc(untunnelHandler)
|
||||||
|
|
||||||
server := rest_server_zrok.NewServer(api)
|
server := rest_server_zrok.NewServer(api)
|
||||||
defer func() { _ = server.Shutdown() }()
|
defer func() { _ = server.Shutdown() }()
|
||||||
|
@ -173,12 +173,12 @@ func createEdgeRouterPolicy(svcName, envId string, edge *rest_management_api_cli
|
|||||||
Name: &svcName,
|
Name: &svcName,
|
||||||
Semantic: &semantic,
|
Semantic: &semantic,
|
||||||
}
|
}
|
||||||
erpParams := &edge_router_policy.CreateEdgeRouterPolicyParams{
|
req := &edge_router_policy.CreateEdgeRouterPolicyParams{
|
||||||
Policy: erp,
|
Policy: erp,
|
||||||
Context: context.Background(),
|
Context: context.Background(),
|
||||||
}
|
}
|
||||||
erpParams.SetTimeout(30 * time.Second)
|
req.SetTimeout(30 * time.Second)
|
||||||
_, err := edge.EdgeRouterPolicy.CreateEdgeRouterPolicy(erpParams, nil)
|
_, err := edge.EdgeRouterPolicy.CreateEdgeRouterPolicy(req, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
63
controller/untunnel.go
Normal file
63
controller/untunnel.go
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"github.com/go-openapi/runtime/middleware"
|
||||||
|
"github.com/openziti-test-kitchen/zrok/rest_server_zrok/operations/tunnel"
|
||||||
|
"github.com/openziti/edge/rest_management_api_client"
|
||||||
|
"github.com/openziti/edge/rest_management_api_client/edge_router_policy"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func untunnelHandler(params tunnel.UntunnelParams) middleware.Responder {
|
||||||
|
edge, err := edgeClient()
|
||||||
|
if err != nil {
|
||||||
|
logrus.Error(err)
|
||||||
|
return tunnel.NewUntunnelInternalServerError()
|
||||||
|
}
|
||||||
|
|
||||||
|
svcId := params.Body.Service
|
||||||
|
if err := deleteEdgeRouterPolicy(svcId, edge); err != nil {
|
||||||
|
logrus.Error(err)
|
||||||
|
return middleware.Error(500, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
return tunnel.NewUntunnelOK()
|
||||||
|
}
|
||||||
|
|
||||||
|
func deleteEdgeRouterPolicy(svcId string, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||||
|
filter := fmt.Sprintf("name=\"%v\"", svcId)
|
||||||
|
limit := int64(1)
|
||||||
|
offset := int64(0)
|
||||||
|
|
||||||
|
listReq := &edge_router_policy.ListEdgeRouterPoliciesParams{
|
||||||
|
Filter: &filter,
|
||||||
|
Limit: &limit,
|
||||||
|
Offset: &offset,
|
||||||
|
Context: context.Background(),
|
||||||
|
}
|
||||||
|
listReq.SetTimeout(30 * time.Second)
|
||||||
|
listResp, err := edge.EdgeRouterPolicy.ListEdgeRouterPolicies(listReq, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if len(listResp.Payload.Data) == 1 {
|
||||||
|
erpId := *(listResp.Payload.Data[0].ID)
|
||||||
|
logrus.Infof("found edge router policy '%v'", erpId)
|
||||||
|
deleteReq := &edge_router_policy.DeleteEdgeRouterPolicyParams{
|
||||||
|
ID: erpId,
|
||||||
|
Context: context.Background(),
|
||||||
|
}
|
||||||
|
deleteReq.SetTimeout(30 * time.Second)
|
||||||
|
_, err := edge.EdgeRouterPolicy.DeleteEdgeRouterPolicy(deleteReq, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
logrus.Infof("deleted edge router policy '%v'", erpId)
|
||||||
|
} else {
|
||||||
|
logrus.Infof("did not find an edge router policy")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user