diff --git a/controller/tunnel.go b/controller/tunnel.go index 03f4f1e4..5bfac6cd 100644 --- a/controller/tunnel.go +++ b/controller/tunnel.go @@ -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) diff --git a/controller/untunnel.go b/controller/untunnel.go index 10de1932..2adb7871 100644 --- a/controller/untunnel.go +++ b/controller/untunnel.go @@ -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) diff --git a/rest_client_zrok/tunnel/tunnel_responses.go b/rest_client_zrok/tunnel/tunnel_responses.go index bed68225..0de8cff8 100644 --- a/rest_client_zrok/tunnel/tunnel_responses.go +++ b/rest_client_zrok/tunnel/tunnel_responses.go @@ -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 +} diff --git a/rest_server_zrok/embedded_spec.go b/rest_server_zrok/embedded_spec.go index 4859773d..352dd1d8 100644 --- a/rest_server_zrok/embedded_spec.go +++ b/rest_server_zrok/embedded_spec.go @@ -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" } } } diff --git a/rest_server_zrok/operations/tunnel/tunnel_responses.go b/rest_server_zrok/operations/tunnel/tunnel_responses.go index 07c503a0..c16f9cd8 100644 --- a/rest_server_zrok/operations/tunnel/tunnel_responses.go +++ b/rest_server_zrok/operations/tunnel/tunnel_responses.go @@ -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) +} diff --git a/specs/zrok.yml b/specs/zrok.yml index 223818cd..8606aa61 100644 --- a/specs/zrok.yml +++ b/specs/zrok.yml @@ -57,6 +57,8 @@ paths: description: tunnel created schema: $ref: "#/definitions/tunnelResponse" + 500: + description: internal server error /untunnel: delete: tags: