mirror of
https://github.com/openziti/zrok.git
synced 2025-01-03 04:29:19 +01:00
tunnel/untunnel handler cleanups (#3)
This commit is contained in:
parent
ae496beb92
commit
d44ebb9e80
@ -20,39 +20,34 @@ func tunnelHandler(params tunnel.TunnelParams) middleware.Responder {
|
|||||||
edge, err := edgeClient()
|
edge, err := edgeClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
return middleware.Error(500, err.Error())
|
return tunnel.NewTunnelInternalServerError()
|
||||||
}
|
}
|
||||||
|
|
||||||
svcName, err := randomId()
|
svcName, err := randomId()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
return middleware.Error(500, err.Error())
|
return tunnel.NewTunnelInternalServerError()
|
||||||
}
|
}
|
||||||
svcId, err := createService(svcName, edge)
|
svcId, err := createService(svcName, edge)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
return middleware.Error(500, err.Error())
|
return tunnel.NewTunnelInternalServerError()
|
||||||
}
|
}
|
||||||
envId := params.Body.Identity
|
envId := params.Body.Identity
|
||||||
|
|
||||||
if err := createServicePolicyBind(svcName, svcId, envId, edge); err != nil {
|
if err := createServicePolicyBind(svcName, svcId, envId, edge); err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
return middleware.Error(500, err.Error())
|
return tunnel.NewTunnelInternalServerError()
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := createServicePolicyDial(svcName, svcId, edge); err != nil {
|
if err := createServicePolicyDial(svcName, svcId, edge); err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
return middleware.Error(500, err.Error())
|
return tunnel.NewTunnelInternalServerError()
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := createServiceEdgeRouterPolicy(svcName, svcId, edge); err != nil {
|
if err := createServiceEdgeRouterPolicy(svcName, svcId, edge); err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
return middleware.Error(500, err.Error())
|
return tunnel.NewTunnelInternalServerError()
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := createEdgeRouterPolicy(svcName, envId, edge); err != nil {
|
if err := createEdgeRouterPolicy(svcName, envId, edge); err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
return middleware.Error(500, err.Error())
|
return tunnel.NewTunnelInternalServerError()
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.Infof("allocated service '%v'", svcName)
|
logrus.Infof("allocated service '%v'", svcName)
|
||||||
|
@ -20,7 +20,6 @@ func untunnelHandler(params tunnel.UntunnelParams) middleware.Responder {
|
|||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
return tunnel.NewUntunnelInternalServerError()
|
return tunnel.NewUntunnelInternalServerError()
|
||||||
}
|
}
|
||||||
|
|
||||||
svcName := params.Body.Service
|
svcName := params.Body.Service
|
||||||
if err := deleteEdgeRouterPolicy(svcName, edge); err != nil {
|
if err := deleteEdgeRouterPolicy(svcName, edge); err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
|
@ -29,6 +29,12 @@ func (o *TunnelReader) ReadResponse(response runtime.ClientResponse, consumer ru
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return result, nil
|
return result, nil
|
||||||
|
case 500:
|
||||||
|
result := NewTunnelInternalServerError()
|
||||||
|
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return nil, result
|
||||||
default:
|
default:
|
||||||
return nil, runtime.NewAPIError("response status code does not match any response statuses defined for this endpoint in the swagger spec", response, response.Code())
|
return nil, runtime.NewAPIError("response status code does not match any response statuses defined for this endpoint in the swagger spec", response, response.Code())
|
||||||
}
|
}
|
||||||
@ -65,3 +71,24 @@ func (o *TunnelCreated) readResponse(response runtime.ClientResponse, consumer r
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewTunnelInternalServerError creates a TunnelInternalServerError with default headers values
|
||||||
|
func NewTunnelInternalServerError() *TunnelInternalServerError {
|
||||||
|
return &TunnelInternalServerError{}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TunnelInternalServerError describes a response with status code 500, with default header values.
|
||||||
|
|
||||||
|
internal server error
|
||||||
|
*/
|
||||||
|
type TunnelInternalServerError struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *TunnelInternalServerError) Error() string {
|
||||||
|
return fmt.Sprintf("[POST /tunnel][%d] tunnelInternalServerError ", 500)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *TunnelInternalServerError) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -117,6 +117,9 @@ func init() {
|
|||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/tunnelResponse"
|
"$ref": "#/definitions/tunnelResponse"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "internal server error"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -339,6 +342,9 @@ func init() {
|
|||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/tunnelResponse"
|
"$ref": "#/definitions/tunnelResponse"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "internal server error"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,3 +56,27 @@ func (o *TunnelCreated) WriteResponse(rw http.ResponseWriter, producer runtime.P
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TunnelInternalServerErrorCode is the HTTP code returned for type TunnelInternalServerError
|
||||||
|
const TunnelInternalServerErrorCode int = 500
|
||||||
|
|
||||||
|
/*TunnelInternalServerError internal server error
|
||||||
|
|
||||||
|
swagger:response tunnelInternalServerError
|
||||||
|
*/
|
||||||
|
type TunnelInternalServerError struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewTunnelInternalServerError creates TunnelInternalServerError with default headers values
|
||||||
|
func NewTunnelInternalServerError() *TunnelInternalServerError {
|
||||||
|
|
||||||
|
return &TunnelInternalServerError{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WriteResponse to the client
|
||||||
|
func (o *TunnelInternalServerError) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
|
||||||
|
|
||||||
|
rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses
|
||||||
|
|
||||||
|
rw.WriteHeader(500)
|
||||||
|
}
|
||||||
|
@ -57,6 +57,8 @@ paths:
|
|||||||
description: tunnel created
|
description: tunnel created
|
||||||
schema:
|
schema:
|
||||||
$ref: "#/definitions/tunnelResponse"
|
$ref: "#/definitions/tunnelResponse"
|
||||||
|
500:
|
||||||
|
description: internal server error
|
||||||
/untunnel:
|
/untunnel:
|
||||||
delete:
|
delete:
|
||||||
tags:
|
tags:
|
||||||
|
Loading…
Reference in New Issue
Block a user