mirror of
https://github.com/SecurityBrewery/catalyst.git
synced 2025-12-12 18:22:49 +01:00
Release catalyst
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
package playbooks
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/runtime"
|
||||
|
||||
"github.com/SecurityBrewery/catalyst/generated/models"
|
||||
"github.com/SecurityBrewery/catalyst/generated/restapi/api"
|
||||
)
|
||||
|
||||
// CreatePlaybookEndpoint executes the core logic of the related
|
||||
// route endpoint.
|
||||
func CreatePlaybookEndpoint(handler func(ctx context.Context, params *CreatePlaybookParams) *api.Response) gin.HandlerFunc {
|
||||
return func(ctx *gin.Context) {
|
||||
|
||||
// generate params from request
|
||||
params := NewCreatePlaybookParams()
|
||||
err := params.ReadRequest(ctx)
|
||||
if err != nil {
|
||||
errObj := err.(*errors.CompositeError)
|
||||
ctx.Writer.Header().Set("Content-Type", "application/problem+json")
|
||||
ctx.JSON(int(errObj.Code()), gin.H{"error": errObj.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
resp := handler(ctx, params)
|
||||
|
||||
switch resp.Code {
|
||||
case http.StatusNoContent:
|
||||
ctx.AbortWithStatus(resp.Code)
|
||||
default:
|
||||
ctx.JSON(resp.Code, resp.Body)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// NewCreatePlaybookParams creates a new CreatePlaybookParams object
|
||||
// with the default values initialized.
|
||||
func NewCreatePlaybookParams() *CreatePlaybookParams {
|
||||
var ()
|
||||
return &CreatePlaybookParams{}
|
||||
}
|
||||
|
||||
// CreatePlaybookParams contains all the bound params for the create playbook operation
|
||||
// typically these are obtained from a http.Request
|
||||
//
|
||||
// swagger:parameters createPlaybook
|
||||
type CreatePlaybookParams struct {
|
||||
|
||||
/*New playbook
|
||||
Required: true
|
||||
In: body
|
||||
*/
|
||||
Playbook *models.PlaybookTemplateForm
|
||||
}
|
||||
|
||||
// ReadRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
|
||||
// for simple values it will use straight method calls
|
||||
func (o *CreatePlaybookParams) ReadRequest(ctx *gin.Context) error {
|
||||
var res []error
|
||||
|
||||
if runtime.HasBody(ctx.Request) {
|
||||
var body models.PlaybookTemplateForm
|
||||
if err := ctx.BindJSON(&body); err != nil {
|
||||
if err == io.EOF {
|
||||
res = append(res, errors.Required("playbook", "body", ""))
|
||||
} else {
|
||||
res = append(res, errors.NewParseError("playbook", "body", "", err))
|
||||
}
|
||||
|
||||
} else {
|
||||
o.Playbook = &body
|
||||
}
|
||||
} else {
|
||||
res = append(res, errors.Required("playbook", "body", ""))
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user