mirror of
https://github.com/openziti/zrok.git
synced 2024-11-21 23:53:19 +01:00
de-linting (#3)
This commit is contained in:
parent
06b523d39f
commit
cfa603ea0c
@ -6,6 +6,7 @@ import (
|
||||
"github.com/go-openapi/runtime/middleware"
|
||||
"github.com/openziti-test-kitchen/zrok/rest_model_zrok"
|
||||
"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/openziti/edge/rest_management_api_client/service"
|
||||
"github.com/openziti/edge/rest_management_api_client/service_edge_router_policy"
|
||||
@ -22,113 +23,154 @@ func tunnelHandler(params tunnel.TunnelParams) middleware.Responder {
|
||||
return middleware.Error(500, err.Error())
|
||||
}
|
||||
|
||||
serviceId, err := randomId()
|
||||
svcName, err := randomId()
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
return middleware.Error(500, err.Error())
|
||||
}
|
||||
logrus.Infof("using service '%v'", serviceId)
|
||||
logrus.Infof("allocated service '%v'", svcName)
|
||||
|
||||
semantic := rest_model.SemanticAllOf
|
||||
|
||||
// Service
|
||||
svcConfigs := make([]string, 0)
|
||||
svcEnc := true
|
||||
svc := &rest_model.ServiceCreate{
|
||||
Configs: svcConfigs,
|
||||
EncryptionRequired: &svcEnc,
|
||||
Name: &serviceId,
|
||||
svcId, err := createService(svcName, edge)
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
return middleware.Error(500, err.Error())
|
||||
}
|
||||
svcParams := &service.CreateServiceParams{
|
||||
envId := params.Body.Identity
|
||||
|
||||
if err := createServicePolicyBind(svcName, svcId, envId, edge); err != nil {
|
||||
logrus.Error(err)
|
||||
return middleware.Error(500, err.Error())
|
||||
}
|
||||
|
||||
if err := createServicePolicyDial(svcName, svcId, edge); err != nil {
|
||||
logrus.Error(err)
|
||||
return middleware.Error(500, err.Error())
|
||||
}
|
||||
|
||||
if err := createServiceEdgeRouterPolicy(svcName, svcId, edge); err != nil {
|
||||
logrus.Error(err)
|
||||
return middleware.Error(500, err.Error())
|
||||
}
|
||||
|
||||
if err := createEdgeRouterPolicy(svcName, envId, edge); err != nil {
|
||||
logrus.Error(err)
|
||||
return middleware.Error(500, err.Error())
|
||||
}
|
||||
|
||||
resp := tunnel.NewTunnelCreated().WithPayload(&rest_model_zrok.TunnelResponse{
|
||||
Service: svcName,
|
||||
})
|
||||
return resp
|
||||
}
|
||||
|
||||
func createService(name string, edge *rest_management_api_client.ZitiEdgeManagement) (serviceId string, err error) {
|
||||
configs := make([]string, 0)
|
||||
encryptionRequired := true
|
||||
svc := &rest_model.ServiceCreate{
|
||||
Configs: configs,
|
||||
EncryptionRequired: &encryptionRequired,
|
||||
Name: &name,
|
||||
}
|
||||
req := &service.CreateServiceParams{
|
||||
Service: svc,
|
||||
Context: context.Background(),
|
||||
}
|
||||
svcParams.SetTimeout(30 * time.Second)
|
||||
svcResp, err := edge.Service.CreateService(svcParams, nil)
|
||||
req.SetTimeout(30 * time.Second)
|
||||
resp, err := edge.Service.CreateService(req, nil)
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
return middleware.Error(500, err.Error())
|
||||
return "", err
|
||||
}
|
||||
logrus.Infof("created service '%v'", serviceId)
|
||||
logrus.Infof("created service '%v'", resp.Payload.Data.ID)
|
||||
return resp.Payload.Data.ID, nil
|
||||
}
|
||||
|
||||
// Service Policy (Bind)
|
||||
svcpIdRoles := []string{fmt.Sprintf("@%v", params.Body.Identity)}
|
||||
svcpName := fmt.Sprintf("%v-bind", serviceId)
|
||||
svcpPcRoles := []string{}
|
||||
svcpSvcRoles := []string{fmt.Sprintf("@%v", svcResp.Payload.Data.ID)}
|
||||
svcpDialBind := rest_model.DialBindBind
|
||||
func createServicePolicyBind(svcName, svcId, envId string, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
semantic := rest_model.SemanticAllOf
|
||||
identityRoles := []string{fmt.Sprintf("@%v", envId)}
|
||||
name := fmt.Sprintf("%v-bind", svcName)
|
||||
postureCheckRoles := []string{}
|
||||
serviceRoles := []string{fmt.Sprintf("@%v", svcId)}
|
||||
dialBind := rest_model.DialBindBind
|
||||
svcp := &rest_model.ServicePolicyCreate{
|
||||
IdentityRoles: svcpIdRoles,
|
||||
Name: &svcpName,
|
||||
PostureCheckRoles: svcpPcRoles,
|
||||
IdentityRoles: identityRoles,
|
||||
Name: &name,
|
||||
PostureCheckRoles: postureCheckRoles,
|
||||
Semantic: &semantic,
|
||||
ServiceRoles: svcpSvcRoles,
|
||||
Type: &svcpDialBind,
|
||||
ServiceRoles: serviceRoles,
|
||||
Type: &dialBind,
|
||||
}
|
||||
svcpParams := &service_policy.CreateServicePolicyParams{
|
||||
req := &service_policy.CreateServicePolicyParams{
|
||||
Policy: svcp,
|
||||
Context: context.Background(),
|
||||
}
|
||||
svcpParams.SetTimeout(30 * time.Second)
|
||||
_, err = edge.ServicePolicy.CreateServicePolicy(svcpParams, nil)
|
||||
req.SetTimeout(30 * time.Second)
|
||||
_, err := edge.ServicePolicy.CreateServicePolicy(req, nil)
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
return middleware.Error(500, err.Error())
|
||||
return err
|
||||
}
|
||||
logrus.Infof("created service policy '%v' (bind)", serviceId)
|
||||
logrus.Infof("created service policy '%v'", name)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Service Policy (Dial)
|
||||
svcpIdRoles = []string{"@PyB606.S."} // @proxy
|
||||
svcpName = fmt.Sprintf("%v-dial", serviceId)
|
||||
svcpDialBind = rest_model.DialBindDial
|
||||
svcp = &rest_model.ServicePolicyCreate{
|
||||
IdentityRoles: svcpIdRoles,
|
||||
Name: &svcpName,
|
||||
PostureCheckRoles: svcpPcRoles,
|
||||
func createServicePolicyDial(svcName, svcId string, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
identityRoles := []string{"@PyB606.S."} // @proxy
|
||||
name := fmt.Sprintf("%v-dial", svcName)
|
||||
postureCheckRoles := []string{}
|
||||
semantic := rest_model.SemanticAllOf
|
||||
serviceRoles := []string{fmt.Sprintf("@%v", svcId)}
|
||||
dialBind := rest_model.DialBindDial
|
||||
svcp := &rest_model.ServicePolicyCreate{
|
||||
IdentityRoles: identityRoles,
|
||||
Name: &name,
|
||||
PostureCheckRoles: postureCheckRoles,
|
||||
Semantic: &semantic,
|
||||
ServiceRoles: svcpSvcRoles,
|
||||
Type: &svcpDialBind,
|
||||
ServiceRoles: serviceRoles,
|
||||
Type: &dialBind,
|
||||
}
|
||||
svcpParams = &service_policy.CreateServicePolicyParams{
|
||||
req := &service_policy.CreateServicePolicyParams{
|
||||
Policy: svcp,
|
||||
Context: context.Background(),
|
||||
}
|
||||
svcpParams.SetTimeout(30 * time.Second)
|
||||
_, err = edge.ServicePolicy.CreateServicePolicy(svcpParams, nil)
|
||||
req.SetTimeout(30 * time.Second)
|
||||
_, err := edge.ServicePolicy.CreateServicePolicy(req, nil)
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
return middleware.Error(500, err.Error())
|
||||
return err
|
||||
}
|
||||
logrus.Infof("created service policy '%v' (dial)", serviceId)
|
||||
logrus.Infof("created service policy '%v'", name)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Service Edge Router Policy
|
||||
serpErRoles := []string{"@tDnhG8jkG9"} // @linux-edge-router
|
||||
serpSvcRoles := []string{fmt.Sprintf("@%v", svcResp.Payload.Data.ID)}
|
||||
func createServiceEdgeRouterPolicy(svcName, svcId string, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
edgeRouterRoles := []string{"@tDnhG8jkG9"} // @linux-edge-router
|
||||
semantic := rest_model.SemanticAllOf
|
||||
serviceRoles := []string{fmt.Sprintf("@%v", svcId)}
|
||||
serp := &rest_model.ServiceEdgeRouterPolicyCreate{
|
||||
EdgeRouterRoles: serpErRoles,
|
||||
Name: &serviceId,
|
||||
EdgeRouterRoles: edgeRouterRoles,
|
||||
Name: &svcName,
|
||||
Semantic: &semantic,
|
||||
ServiceRoles: serpSvcRoles,
|
||||
ServiceRoles: serviceRoles,
|
||||
}
|
||||
serpParams := &service_edge_router_policy.CreateServiceEdgeRouterPolicyParams{
|
||||
Policy: serp,
|
||||
Context: context.Background(),
|
||||
}
|
||||
serpParams.SetTimeout(30 * time.Second)
|
||||
_, err = edge.ServiceEdgeRouterPolicy.CreateServiceEdgeRouterPolicy(serpParams, nil)
|
||||
_, err := edge.ServiceEdgeRouterPolicy.CreateServiceEdgeRouterPolicy(serpParams, nil)
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
return middleware.Error(500, err.Error())
|
||||
return err
|
||||
}
|
||||
logrus.Infof("created service edge router policy '%v'", serviceId)
|
||||
logrus.Infof("created service edge router policy '%v'", svcName)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Edge Router Policy
|
||||
erpErRoles := []string{"@tDnhG8jkG9"} // @linux-edge-router
|
||||
erpIdRoles := []string{fmt.Sprintf("@%v", params.Body.Identity)}
|
||||
func createEdgeRouterPolicy(svcName, envId string, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
edgeRouterRoles := []string{"@tDnhG8jkG9"} // @linux-edge-router
|
||||
identityRoles := []string{fmt.Sprintf("@%v", envId)}
|
||||
semantic := rest_model.SemanticAllOf
|
||||
erp := &rest_model.EdgeRouterPolicyCreate{
|
||||
EdgeRouterRoles: erpErRoles,
|
||||
IdentityRoles: erpIdRoles,
|
||||
Name: &serviceId,
|
||||
EdgeRouterRoles: edgeRouterRoles,
|
||||
IdentityRoles: identityRoles,
|
||||
Name: &svcName,
|
||||
Semantic: &semantic,
|
||||
}
|
||||
erpParams := &edge_router_policy.CreateEdgeRouterPolicyParams{
|
||||
@ -136,15 +178,10 @@ func tunnelHandler(params tunnel.TunnelParams) middleware.Responder {
|
||||
Context: context.Background(),
|
||||
}
|
||||
erpParams.SetTimeout(30 * time.Second)
|
||||
_, err = edge.EdgeRouterPolicy.CreateEdgeRouterPolicy(erpParams, nil)
|
||||
_, err := edge.EdgeRouterPolicy.CreateEdgeRouterPolicy(erpParams, nil)
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
return middleware.Error(500, err.Error())
|
||||
return err
|
||||
}
|
||||
logrus.Infof("created edge router policy '%v'", serviceId)
|
||||
|
||||
resp := tunnel.NewTunnelCreated().WithPayload(&rest_model_zrok.TunnelResponse{
|
||||
Service: serviceId,
|
||||
})
|
||||
return resp
|
||||
logrus.Infof("created edge router policy '%v'", svcName)
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user