From ffd258c5c567fbbf2ad3c78cfbb86fc15646abd4 Mon Sep 17 00:00:00 2001 From: inho Date: Fri, 24 May 2024 16:34:19 +0900 Subject: [PATCH] Added BGP Policy API --- .../post_config_bgp_policy_apply.go | 58 +++ ...post_config_bgp_policy_apply_parameters.go | 84 +++++ .../post_config_bgp_policy_apply_responses.go | 354 ++++++++++++++++++ ...post_config_bgp_policy_apply_urlbuilder.go | 87 +++++ 4 files changed, 583 insertions(+) create mode 100644 api/restapi/operations/post_config_bgp_policy_apply.go create mode 100644 api/restapi/operations/post_config_bgp_policy_apply_parameters.go create mode 100644 api/restapi/operations/post_config_bgp_policy_apply_responses.go create mode 100644 api/restapi/operations/post_config_bgp_policy_apply_urlbuilder.go diff --git a/api/restapi/operations/post_config_bgp_policy_apply.go b/api/restapi/operations/post_config_bgp_policy_apply.go new file mode 100644 index 000000000..4375d8707 --- /dev/null +++ b/api/restapi/operations/post_config_bgp_policy_apply.go @@ -0,0 +1,58 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// PostConfigBgpPolicyApplyHandlerFunc turns a function with the right signature into a post config bgp policy apply handler +type PostConfigBgpPolicyApplyHandlerFunc func(PostConfigBgpPolicyApplyParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn PostConfigBgpPolicyApplyHandlerFunc) Handle(params PostConfigBgpPolicyApplyParams) middleware.Responder { + return fn(params) +} + +// PostConfigBgpPolicyApplyHandler interface for that can handle valid post config bgp policy apply params +type PostConfigBgpPolicyApplyHandler interface { + Handle(PostConfigBgpPolicyApplyParams) middleware.Responder +} + +// NewPostConfigBgpPolicyApply creates a new http.Handler for the post config bgp policy apply operation +func NewPostConfigBgpPolicyApply(ctx *middleware.Context, handler PostConfigBgpPolicyApplyHandler) *PostConfigBgpPolicyApply { + return &PostConfigBgpPolicyApply{Context: ctx, Handler: handler} +} + +/* + PostConfigBgpPolicyApply swagger:route POST /config/bgp/policy/apply postConfigBgpPolicyApply + +# Apply BGP Policy in neighbor + +Apply BGP Policy in neighbor +*/ +type PostConfigBgpPolicyApply struct { + Context *middleware.Context + Handler PostConfigBgpPolicyApplyHandler +} + +func (o *PostConfigBgpPolicyApply) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewPostConfigBgpPolicyApplyParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/api/restapi/operations/post_config_bgp_policy_apply_parameters.go b/api/restapi/operations/post_config_bgp_policy_apply_parameters.go new file mode 100644 index 000000000..dec0aef74 --- /dev/null +++ b/api/restapi/operations/post_config_bgp_policy_apply_parameters.go @@ -0,0 +1,84 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "io" + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/validate" + + "github.com/loxilb-io/loxilb/api/models" +) + +// NewPostConfigBgpPolicyApplyParams creates a new PostConfigBgpPolicyApplyParams object +// +// There are no default values defined in the spec. +func NewPostConfigBgpPolicyApplyParams() PostConfigBgpPolicyApplyParams { + + return PostConfigBgpPolicyApplyParams{} +} + +// PostConfigBgpPolicyApplyParams contains all the bound params for the post config bgp policy apply operation +// typically these are obtained from a http.Request +// +// swagger:parameters PostConfigBgpPolicyApply +type PostConfigBgpPolicyApplyParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /*Attributes of bgp neighbor + Required: true + In: body + */ + Attr *models.BGPApplyPolicyToNeighborMod +} + +// BindRequest 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. +// +// To ensure default values, the struct must have been initialized with NewPostConfigBgpPolicyApplyParams() beforehand. +func (o *PostConfigBgpPolicyApplyParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + if runtime.HasBody(r) { + defer r.Body.Close() + var body models.BGPApplyPolicyToNeighborMod + if err := route.Consumer.Consume(r.Body, &body); err != nil { + if err == io.EOF { + res = append(res, errors.Required("attr", "body", "")) + } else { + res = append(res, errors.NewParseError("attr", "body", "", err)) + } + } else { + // validate body object + if err := body.Validate(route.Formats); err != nil { + res = append(res, err) + } + + ctx := validate.WithOperationRequest(r.Context()) + if err := body.ContextValidate(ctx, route.Formats); err != nil { + res = append(res, err) + } + + if len(res) == 0 { + o.Attr = &body + } + } + } else { + res = append(res, errors.Required("attr", "body", "")) + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/api/restapi/operations/post_config_bgp_policy_apply_responses.go b/api/restapi/operations/post_config_bgp_policy_apply_responses.go new file mode 100644 index 000000000..8201dd909 --- /dev/null +++ b/api/restapi/operations/post_config_bgp_policy_apply_responses.go @@ -0,0 +1,354 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + "github.com/loxilb-io/loxilb/api/models" +) + +// PostConfigBgpPolicyApplyNoContentCode is the HTTP code returned for type PostConfigBgpPolicyApplyNoContent +const PostConfigBgpPolicyApplyNoContentCode int = 204 + +/* +PostConfigBgpPolicyApplyNoContent OK + +swagger:response postConfigBgpPolicyApplyNoContent +*/ +type PostConfigBgpPolicyApplyNoContent struct { +} + +// NewPostConfigBgpPolicyApplyNoContent creates PostConfigBgpPolicyApplyNoContent with default headers values +func NewPostConfigBgpPolicyApplyNoContent() *PostConfigBgpPolicyApplyNoContent { + + return &PostConfigBgpPolicyApplyNoContent{} +} + +// WriteResponse to the client +func (o *PostConfigBgpPolicyApplyNoContent) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses + + rw.WriteHeader(204) +} + +// PostConfigBgpPolicyApplyBadRequestCode is the HTTP code returned for type PostConfigBgpPolicyApplyBadRequest +const PostConfigBgpPolicyApplyBadRequestCode int = 400 + +/* +PostConfigBgpPolicyApplyBadRequest Malformed arguments for API call + +swagger:response postConfigBgpPolicyApplyBadRequest +*/ +type PostConfigBgpPolicyApplyBadRequest struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewPostConfigBgpPolicyApplyBadRequest creates PostConfigBgpPolicyApplyBadRequest with default headers values +func NewPostConfigBgpPolicyApplyBadRequest() *PostConfigBgpPolicyApplyBadRequest { + + return &PostConfigBgpPolicyApplyBadRequest{} +} + +// WithPayload adds the payload to the post config bgp policy apply bad request response +func (o *PostConfigBgpPolicyApplyBadRequest) WithPayload(payload *models.Error) *PostConfigBgpPolicyApplyBadRequest { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post config bgp policy apply bad request response +func (o *PostConfigBgpPolicyApplyBadRequest) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostConfigBgpPolicyApplyBadRequest) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(400) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// PostConfigBgpPolicyApplyUnauthorizedCode is the HTTP code returned for type PostConfigBgpPolicyApplyUnauthorized +const PostConfigBgpPolicyApplyUnauthorizedCode int = 401 + +/* +PostConfigBgpPolicyApplyUnauthorized Invalid authentication credentials + +swagger:response postConfigBgpPolicyApplyUnauthorized +*/ +type PostConfigBgpPolicyApplyUnauthorized struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewPostConfigBgpPolicyApplyUnauthorized creates PostConfigBgpPolicyApplyUnauthorized with default headers values +func NewPostConfigBgpPolicyApplyUnauthorized() *PostConfigBgpPolicyApplyUnauthorized { + + return &PostConfigBgpPolicyApplyUnauthorized{} +} + +// WithPayload adds the payload to the post config bgp policy apply unauthorized response +func (o *PostConfigBgpPolicyApplyUnauthorized) WithPayload(payload *models.Error) *PostConfigBgpPolicyApplyUnauthorized { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post config bgp policy apply unauthorized response +func (o *PostConfigBgpPolicyApplyUnauthorized) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostConfigBgpPolicyApplyUnauthorized) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(401) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// PostConfigBgpPolicyApplyForbiddenCode is the HTTP code returned for type PostConfigBgpPolicyApplyForbidden +const PostConfigBgpPolicyApplyForbiddenCode int = 403 + +/* +PostConfigBgpPolicyApplyForbidden Capacity insufficient + +swagger:response postConfigBgpPolicyApplyForbidden +*/ +type PostConfigBgpPolicyApplyForbidden struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewPostConfigBgpPolicyApplyForbidden creates PostConfigBgpPolicyApplyForbidden with default headers values +func NewPostConfigBgpPolicyApplyForbidden() *PostConfigBgpPolicyApplyForbidden { + + return &PostConfigBgpPolicyApplyForbidden{} +} + +// WithPayload adds the payload to the post config bgp policy apply forbidden response +func (o *PostConfigBgpPolicyApplyForbidden) WithPayload(payload *models.Error) *PostConfigBgpPolicyApplyForbidden { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post config bgp policy apply forbidden response +func (o *PostConfigBgpPolicyApplyForbidden) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostConfigBgpPolicyApplyForbidden) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(403) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// PostConfigBgpPolicyApplyNotFoundCode is the HTTP code returned for type PostConfigBgpPolicyApplyNotFound +const PostConfigBgpPolicyApplyNotFoundCode int = 404 + +/* +PostConfigBgpPolicyApplyNotFound Resource not found + +swagger:response postConfigBgpPolicyApplyNotFound +*/ +type PostConfigBgpPolicyApplyNotFound struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewPostConfigBgpPolicyApplyNotFound creates PostConfigBgpPolicyApplyNotFound with default headers values +func NewPostConfigBgpPolicyApplyNotFound() *PostConfigBgpPolicyApplyNotFound { + + return &PostConfigBgpPolicyApplyNotFound{} +} + +// WithPayload adds the payload to the post config bgp policy apply not found response +func (o *PostConfigBgpPolicyApplyNotFound) WithPayload(payload *models.Error) *PostConfigBgpPolicyApplyNotFound { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post config bgp policy apply not found response +func (o *PostConfigBgpPolicyApplyNotFound) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostConfigBgpPolicyApplyNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(404) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// PostConfigBgpPolicyApplyConflictCode is the HTTP code returned for type PostConfigBgpPolicyApplyConflict +const PostConfigBgpPolicyApplyConflictCode int = 409 + +/* +PostConfigBgpPolicyApplyConflict Resource Conflict. + +swagger:response postConfigBgpPolicyApplyConflict +*/ +type PostConfigBgpPolicyApplyConflict struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewPostConfigBgpPolicyApplyConflict creates PostConfigBgpPolicyApplyConflict with default headers values +func NewPostConfigBgpPolicyApplyConflict() *PostConfigBgpPolicyApplyConflict { + + return &PostConfigBgpPolicyApplyConflict{} +} + +// WithPayload adds the payload to the post config bgp policy apply conflict response +func (o *PostConfigBgpPolicyApplyConflict) WithPayload(payload *models.Error) *PostConfigBgpPolicyApplyConflict { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post config bgp policy apply conflict response +func (o *PostConfigBgpPolicyApplyConflict) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostConfigBgpPolicyApplyConflict) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(409) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// PostConfigBgpPolicyApplyInternalServerErrorCode is the HTTP code returned for type PostConfigBgpPolicyApplyInternalServerError +const PostConfigBgpPolicyApplyInternalServerErrorCode int = 500 + +/* +PostConfigBgpPolicyApplyInternalServerError Internal service error + +swagger:response postConfigBgpPolicyApplyInternalServerError +*/ +type PostConfigBgpPolicyApplyInternalServerError struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewPostConfigBgpPolicyApplyInternalServerError creates PostConfigBgpPolicyApplyInternalServerError with default headers values +func NewPostConfigBgpPolicyApplyInternalServerError() *PostConfigBgpPolicyApplyInternalServerError { + + return &PostConfigBgpPolicyApplyInternalServerError{} +} + +// WithPayload adds the payload to the post config bgp policy apply internal server error response +func (o *PostConfigBgpPolicyApplyInternalServerError) WithPayload(payload *models.Error) *PostConfigBgpPolicyApplyInternalServerError { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post config bgp policy apply internal server error response +func (o *PostConfigBgpPolicyApplyInternalServerError) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostConfigBgpPolicyApplyInternalServerError) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(500) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// PostConfigBgpPolicyApplyServiceUnavailableCode is the HTTP code returned for type PostConfigBgpPolicyApplyServiceUnavailable +const PostConfigBgpPolicyApplyServiceUnavailableCode int = 503 + +/* +PostConfigBgpPolicyApplyServiceUnavailable Maintanence mode + +swagger:response postConfigBgpPolicyApplyServiceUnavailable +*/ +type PostConfigBgpPolicyApplyServiceUnavailable struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewPostConfigBgpPolicyApplyServiceUnavailable creates PostConfigBgpPolicyApplyServiceUnavailable with default headers values +func NewPostConfigBgpPolicyApplyServiceUnavailable() *PostConfigBgpPolicyApplyServiceUnavailable { + + return &PostConfigBgpPolicyApplyServiceUnavailable{} +} + +// WithPayload adds the payload to the post config bgp policy apply service unavailable response +func (o *PostConfigBgpPolicyApplyServiceUnavailable) WithPayload(payload *models.Error) *PostConfigBgpPolicyApplyServiceUnavailable { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post config bgp policy apply service unavailable response +func (o *PostConfigBgpPolicyApplyServiceUnavailable) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostConfigBgpPolicyApplyServiceUnavailable) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(503) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} diff --git a/api/restapi/operations/post_config_bgp_policy_apply_urlbuilder.go b/api/restapi/operations/post_config_bgp_policy_apply_urlbuilder.go new file mode 100644 index 000000000..05bea9319 --- /dev/null +++ b/api/restapi/operations/post_config_bgp_policy_apply_urlbuilder.go @@ -0,0 +1,87 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" +) + +// PostConfigBgpPolicyApplyURL generates an URL for the post config bgp policy apply operation +type PostConfigBgpPolicyApplyURL struct { + _basePath string +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *PostConfigBgpPolicyApplyURL) WithBasePath(bp string) *PostConfigBgpPolicyApplyURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *PostConfigBgpPolicyApplyURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *PostConfigBgpPolicyApplyURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/config/bgp/policy/apply" + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/netlox/v1" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *PostConfigBgpPolicyApplyURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *PostConfigBgpPolicyApplyURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *PostConfigBgpPolicyApplyURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on PostConfigBgpPolicyApplyURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on PostConfigBgpPolicyApplyURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *PostConfigBgpPolicyApplyURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +}