tunnel/untunnel handler cleanups (#3)

This commit is contained in:
Michael Quigley 2022-07-27 13:17:47 -04:00
parent ae496beb92
commit d44ebb9e80
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
6 changed files with 66 additions and 13 deletions

View File

@ -20,39 +20,34 @@ func tunnelHandler(params tunnel.TunnelParams) middleware.Responder {
edge, err := edgeClient()
if err != nil {
logrus.Error(err)
return middleware.Error(500, err.Error())
return tunnel.NewTunnelInternalServerError()
}
svcName, err := randomId()
if err != nil {
logrus.Error(err)
return middleware.Error(500, err.Error())
return tunnel.NewTunnelInternalServerError()
}
svcId, err := createService(svcName, edge)
if err != nil {
logrus.Error(err)
return middleware.Error(500, err.Error())
return tunnel.NewTunnelInternalServerError()
}
envId := params.Body.Identity
if err := createServicePolicyBind(svcName, svcId, envId, edge); err != nil {
logrus.Error(err)
return middleware.Error(500, err.Error())
return tunnel.NewTunnelInternalServerError()
}
if err := createServicePolicyDial(svcName, svcId, edge); err != nil {
logrus.Error(err)
return middleware.Error(500, err.Error())
return tunnel.NewTunnelInternalServerError()
}
if err := createServiceEdgeRouterPolicy(svcName, svcId, edge); err != nil {
logrus.Error(err)
return middleware.Error(500, err.Error())
return tunnel.NewTunnelInternalServerError()
}
if err := createEdgeRouterPolicy(svcName, envId, edge); err != nil {
logrus.Error(err)
return middleware.Error(500, err.Error())
return tunnel.NewTunnelInternalServerError()
}
logrus.Infof("allocated service '%v'", svcName)

View File

@ -20,7 +20,6 @@ func untunnelHandler(params tunnel.UntunnelParams) middleware.Responder {
logrus.Error(err)
return tunnel.NewUntunnelInternalServerError()
}
svcName := params.Body.Service
if err := deleteEdgeRouterPolicy(svcName, edge); err != nil {
logrus.Error(err)

View File

@ -29,6 +29,12 @@ func (o *TunnelReader) ReadResponse(response runtime.ClientResponse, consumer ru
return nil, err
}
return result, nil
case 500:
result := NewTunnelInternalServerError()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return nil, result
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())
}
@ -65,3 +71,24 @@ func (o *TunnelCreated) readResponse(response runtime.ClientResponse, consumer r
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
}

View File

@ -117,6 +117,9 @@ func init() {
"schema": {
"$ref": "#/definitions/tunnelResponse"
}
},
"500": {
"description": "internal server error"
}
}
}
@ -339,6 +342,9 @@ func init() {
"schema": {
"$ref": "#/definitions/tunnelResponse"
}
},
"500": {
"description": "internal server error"
}
}
}

View File

@ -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)
}

View File

@ -57,6 +57,8 @@ paths:
description: tunnel created
schema:
$ref: "#/definitions/tunnelResponse"
500:
description: internal server error
/untunnel:
delete:
tags: