diff --git a/go.mod b/go.mod index f0334a5ea..a16af68b0 100644 --- a/go.mod +++ b/go.mod @@ -24,7 +24,7 @@ require ( github.com/fsnotify/fsnotify v1.4.9 github.com/gin-gonic/gin v1.6.3 github.com/go-co-op/gocron v1.9.0 - github.com/go-openapi/errors v0.19.9 + github.com/go-openapi/errors v0.20.1 github.com/go-openapi/strfmt v0.19.11 github.com/go-openapi/swag v0.19.12 github.com/go-openapi/validate v0.20.0 diff --git a/go.sum b/go.sum index b94c5ff3b..8a7d357cf 100644 --- a/go.sum +++ b/go.sum @@ -202,6 +202,8 @@ github.com/go-openapi/errors v0.19.7/go.mod h1:cM//ZKUKyO06HSwqAelJ5NsEMMcpa6VpX github.com/go-openapi/errors v0.19.8/go.mod h1:cM//ZKUKyO06HSwqAelJ5NsEMMcpa6VpXe8DOa1Mi1M= github.com/go-openapi/errors v0.19.9 h1:9SnKdGhiPZHF3ttwFMiCBEb8jQ4IDdrK+5+a0oTygA4= github.com/go-openapi/errors v0.19.9/go.mod h1:cM//ZKUKyO06HSwqAelJ5NsEMMcpa6VpXe8DOa1Mi1M= +github.com/go-openapi/errors v0.20.1 h1:j23mMDtRxMwIobkpId7sWh7Ddcx4ivaoqUbfXx5P+a8= +github.com/go-openapi/errors v0.20.1/go.mod h1:cM//ZKUKyO06HSwqAelJ5NsEMMcpa6VpXe8DOa1Mi1M= github.com/go-openapi/inflect v0.19.0/go.mod h1:lHpZVlpIQqLyKwJ4N+YSc9hchQy/i12fJykb83CRBH4= github.com/go-openapi/jsonpointer v0.17.0/go.mod h1:cOnomiV+CVVwFLk0A/MExoFMjwdsUdVpsRhURCKh+3M= github.com/go-openapi/jsonpointer v0.18.0/go.mod h1:cOnomiV+CVVwFLk0A/MExoFMjwdsUdVpsRhURCKh+3M= diff --git a/pkg/apiserver/alerts_test.go b/pkg/apiserver/alerts_test.go index 5b3f4fcaa..8c49fa0fd 100644 --- a/pkg/apiserver/alerts_test.go +++ b/pkg/apiserver/alerts_test.go @@ -123,7 +123,7 @@ func TestCreateAlert(t *testing.T) { router.ServeHTTP(w, req) assert.Equal(t, 500, w.Code) - assert.Equal(t, "{\"message\":\"validation failure list:\\nscenario in body is required\\nscenario_hash in body is required\\nscenario_version in body is required\\nsimulated in body is required\\nsource in body is required\"}", w.Body.String()) + assert.Equal(t, "{\"message\":\"validation failure list:\\n0.scenario in body is required\\n0.scenario_hash in body is required\\n0.scenario_version in body is required\\n0.simulated in body is required\\n0.source in body is required\"}", w.Body.String()) // Create Valid Alert alertContentBytes, err = ioutil.ReadFile("./tests/alert_sample.json") diff --git a/pkg/models/add_alerts_request.go b/pkg/models/add_alerts_request.go index ead8662f6..fd7246be0 100644 --- a/pkg/models/add_alerts_request.go +++ b/pkg/models/add_alerts_request.go @@ -6,6 +6,7 @@ package models // Editing this file might prove futile when you re-run the swagger generate command import ( + "context" "strconv" "github.com/go-openapi/errors" @@ -31,6 +32,33 @@ func (m AddAlertsRequest) Validate(formats strfmt.Registry) error { if err := m[i].Validate(formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName(strconv.Itoa(i)) + } + return err + } + } + + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// ContextValidate validate this add alerts request based on the context it is used +func (m AddAlertsRequest) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + for i := 0; i < len(m); i++ { + + if m[i] != nil { + if err := m[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName(strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName(strconv.Itoa(i)) } return err } diff --git a/pkg/models/add_alerts_response.go b/pkg/models/add_alerts_response.go index aeb70bb77..cd8c98f77 100644 --- a/pkg/models/add_alerts_response.go +++ b/pkg/models/add_alerts_response.go @@ -6,6 +6,8 @@ package models // Editing this file might prove futile when you re-run the swagger generate command import ( + "context" + "github.com/go-openapi/strfmt" ) @@ -18,3 +20,8 @@ type AddAlertsResponse []string func (m AddAlertsResponse) Validate(formats strfmt.Registry) error { return nil } + +// ContextValidate validates this add alerts response based on context it is used +func (m AddAlertsResponse) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} diff --git a/pkg/models/add_signals_request.go b/pkg/models/add_signals_request.go index 87b47807d..d9c2b363a 100644 --- a/pkg/models/add_signals_request.go +++ b/pkg/models/add_signals_request.go @@ -6,6 +6,7 @@ package models // Editing this file might prove futile when you re-run the swagger generate command import ( + "context" "strconv" "github.com/go-openapi/errors" @@ -33,6 +34,33 @@ func (m AddSignalsRequest) Validate(formats strfmt.Registry) error { if err := m[i].Validate(formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName(strconv.Itoa(i)) + } + return err + } + } + + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// ContextValidate validate this add signals request based on the context it is used +func (m AddSignalsRequest) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + for i := 0; i < len(m); i++ { + + if m[i] != nil { + if err := m[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName(strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName(strconv.Itoa(i)) } return err } diff --git a/pkg/models/add_signals_request_item.go b/pkg/models/add_signals_request_item.go index 555566cfb..c03930603 100644 --- a/pkg/models/add_signals_request_item.go +++ b/pkg/models/add_signals_request_item.go @@ -6,6 +6,8 @@ package models // Editing this file might prove futile when you re-run the swagger generate command import ( + "context" + "github.com/go-openapi/errors" "github.com/go-openapi/strfmt" "github.com/go-openapi/swag" @@ -136,6 +138,8 @@ func (m *AddSignalsRequestItem) validateSource(formats strfmt.Registry) error { if err := m.Source.Validate(formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("source") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("source") } return err } @@ -162,6 +166,36 @@ func (m *AddSignalsRequestItem) validateStopAt(formats strfmt.Registry) error { return nil } +// ContextValidate validate this add signals request item based on the context it is used +func (m *AddSignalsRequestItem) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateSource(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *AddSignalsRequestItem) contextValidateSource(ctx context.Context, formats strfmt.Registry) error { + + if m.Source != nil { + if err := m.Source.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("source") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("source") + } + return err + } + } + + return nil +} + // MarshalBinary interface implementation func (m *AddSignalsRequestItem) MarshalBinary() ([]byte, error) { if m == nil { diff --git a/pkg/models/alert.go b/pkg/models/alert.go index b9a4c84c2..3d20fa603 100644 --- a/pkg/models/alert.go +++ b/pkg/models/alert.go @@ -6,6 +6,7 @@ package models // Editing this file might prove futile when you re-run the swagger generate command import ( + "context" "strconv" "github.com/go-openapi/errors" @@ -168,7 +169,6 @@ func (m *Alert) validateCapacity(formats strfmt.Registry) error { } func (m *Alert) validateDecisions(formats strfmt.Registry) error { - if swag.IsZero(m.Decisions) { // not required return nil } @@ -182,6 +182,8 @@ func (m *Alert) validateDecisions(formats strfmt.Registry) error { if err := m.Decisions[i].Validate(formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("decisions" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("decisions" + "." + strconv.Itoa(i)) } return err } @@ -207,6 +209,8 @@ func (m *Alert) validateEvents(formats strfmt.Registry) error { if err := m.Events[i].Validate(formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("events" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("events" + "." + strconv.Itoa(i)) } return err } @@ -245,7 +249,6 @@ func (m *Alert) validateMessage(formats strfmt.Registry) error { } func (m *Alert) validateMeta(formats strfmt.Registry) error { - if swag.IsZero(m.Meta) { // not required return nil } @@ -253,6 +256,8 @@ func (m *Alert) validateMeta(formats strfmt.Registry) error { if err := m.Meta.Validate(formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("meta") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("meta") } return err } @@ -306,6 +311,8 @@ func (m *Alert) validateSource(formats strfmt.Registry) error { if err := m.Source.Validate(formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("source") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("source") } return err } @@ -332,6 +339,141 @@ func (m *Alert) validateStopAt(formats strfmt.Registry) error { return nil } +// ContextValidate validate this alert based on the context it is used +func (m *Alert) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateCreatedAt(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidateDecisions(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidateEvents(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidateID(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidateMachineID(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidateMeta(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidateSource(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *Alert) contextValidateCreatedAt(ctx context.Context, formats strfmt.Registry) error { + + if err := validate.ReadOnly(ctx, "created_at", "body", string(m.CreatedAt)); err != nil { + return err + } + + return nil +} + +func (m *Alert) contextValidateDecisions(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.Decisions); i++ { + + if m.Decisions[i] != nil { + if err := m.Decisions[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("decisions" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("decisions" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +func (m *Alert) contextValidateEvents(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.Events); i++ { + + if m.Events[i] != nil { + if err := m.Events[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("events" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("events" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +func (m *Alert) contextValidateID(ctx context.Context, formats strfmt.Registry) error { + + if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil { + return err + } + + return nil +} + +func (m *Alert) contextValidateMachineID(ctx context.Context, formats strfmt.Registry) error { + + if err := validate.ReadOnly(ctx, "machine_id", "body", string(m.MachineID)); err != nil { + return err + } + + return nil +} + +func (m *Alert) contextValidateMeta(ctx context.Context, formats strfmt.Registry) error { + + if err := m.Meta.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("meta") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("meta") + } + return err + } + + return nil +} + +func (m *Alert) contextValidateSource(ctx context.Context, formats strfmt.Registry) error { + + if m.Source != nil { + if err := m.Source.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("source") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("source") + } + return err + } + } + + return nil +} + // MarshalBinary interface implementation func (m *Alert) MarshalBinary() ([]byte, error) { if m == nil { diff --git a/pkg/models/decision.go b/pkg/models/decision.go index de9a78edc..5e317d73f 100644 --- a/pkg/models/decision.go +++ b/pkg/models/decision.go @@ -6,6 +6,8 @@ package models // Editing this file might prove futile when you re-run the swagger generate command import ( + "context" + "github.com/go-openapi/errors" "github.com/go-openapi/strfmt" "github.com/go-openapi/swag" @@ -138,6 +140,42 @@ func (m *Decision) validateValue(formats strfmt.Registry) error { return nil } +// ContextValidate validate this decision based on the context it is used +func (m *Decision) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateID(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidateSimulated(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *Decision) contextValidateID(ctx context.Context, formats strfmt.Registry) error { + + if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil { + return err + } + + return nil +} + +func (m *Decision) contextValidateSimulated(ctx context.Context, formats strfmt.Registry) error { + + if err := validate.ReadOnly(ctx, "simulated", "body", m.Simulated); err != nil { + return err + } + + return nil +} + // MarshalBinary interface implementation func (m *Decision) MarshalBinary() ([]byte, error) { if m == nil { diff --git a/pkg/models/decisions_stream_response.go b/pkg/models/decisions_stream_response.go index 132681cb5..8ec0c6914 100644 --- a/pkg/models/decisions_stream_response.go +++ b/pkg/models/decisions_stream_response.go @@ -6,6 +6,8 @@ package models // Editing this file might prove futile when you re-run the swagger generate command import ( + "context" + "github.com/go-openapi/errors" "github.com/go-openapi/strfmt" "github.com/go-openapi/swag" @@ -42,7 +44,6 @@ func (m *DecisionsStreamResponse) Validate(formats strfmt.Registry) error { } func (m *DecisionsStreamResponse) validateDeleted(formats strfmt.Registry) error { - if swag.IsZero(m.Deleted) { // not required return nil } @@ -50,6 +51,8 @@ func (m *DecisionsStreamResponse) validateDeleted(formats strfmt.Registry) error if err := m.Deleted.Validate(formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("deleted") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("deleted") } return err } @@ -58,7 +61,6 @@ func (m *DecisionsStreamResponse) validateDeleted(formats strfmt.Registry) error } func (m *DecisionsStreamResponse) validateNew(formats strfmt.Registry) error { - if swag.IsZero(m.New) { // not required return nil } @@ -66,6 +68,54 @@ func (m *DecisionsStreamResponse) validateNew(formats strfmt.Registry) error { if err := m.New.Validate(formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("new") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("new") + } + return err + } + + return nil +} + +// ContextValidate validate this decisions stream response based on the context it is used +func (m *DecisionsStreamResponse) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateDeleted(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidateNew(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *DecisionsStreamResponse) contextValidateDeleted(ctx context.Context, formats strfmt.Registry) error { + + if err := m.Deleted.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("deleted") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("deleted") + } + return err + } + + return nil +} + +func (m *DecisionsStreamResponse) contextValidateNew(ctx context.Context, formats strfmt.Registry) error { + + if err := m.New.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("new") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("new") } return err } diff --git a/pkg/models/delete_alerts_response.go b/pkg/models/delete_alerts_response.go index f13688954..67306e449 100644 --- a/pkg/models/delete_alerts_response.go +++ b/pkg/models/delete_alerts_response.go @@ -6,6 +6,8 @@ package models // Editing this file might prove futile when you re-run the swagger generate command import ( + "context" + "github.com/go-openapi/strfmt" "github.com/go-openapi/swag" ) @@ -24,6 +26,11 @@ func (m *DeleteAlertsResponse) Validate(formats strfmt.Registry) error { return nil } +// ContextValidate validates this delete alerts response based on context it is used +func (m *DeleteAlertsResponse) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + // MarshalBinary interface implementation func (m *DeleteAlertsResponse) MarshalBinary() ([]byte, error) { if m == nil { diff --git a/pkg/models/delete_decision_response.go b/pkg/models/delete_decision_response.go index d934bd56a..70423d661 100644 --- a/pkg/models/delete_decision_response.go +++ b/pkg/models/delete_decision_response.go @@ -6,6 +6,8 @@ package models // Editing this file might prove futile when you re-run the swagger generate command import ( + "context" + "github.com/go-openapi/strfmt" "github.com/go-openapi/swag" ) @@ -24,6 +26,11 @@ func (m *DeleteDecisionResponse) Validate(formats strfmt.Registry) error { return nil } +// ContextValidate validates this delete decision response based on context it is used +func (m *DeleteDecisionResponse) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + // MarshalBinary interface implementation func (m *DeleteDecisionResponse) MarshalBinary() ([]byte, error) { if m == nil { diff --git a/pkg/models/error_response.go b/pkg/models/error_response.go index 2ef64302e..db62a4d98 100644 --- a/pkg/models/error_response.go +++ b/pkg/models/error_response.go @@ -6,6 +6,8 @@ package models // Editing this file might prove futile when you re-run the swagger generate command import ( + "context" + "github.com/go-openapi/errors" "github.com/go-openapi/strfmt" "github.com/go-openapi/swag" @@ -50,6 +52,11 @@ func (m *ErrorResponse) validateMessage(formats strfmt.Registry) error { return nil } +// ContextValidate validates this error response based on context it is used +func (m *ErrorResponse) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + // MarshalBinary interface implementation func (m *ErrorResponse) MarshalBinary() ([]byte, error) { if m == nil { diff --git a/pkg/models/event.go b/pkg/models/event.go index b9ff31917..6e165eb9b 100644 --- a/pkg/models/event.go +++ b/pkg/models/event.go @@ -6,6 +6,8 @@ package models // Editing this file might prove futile when you re-run the swagger generate command import ( + "context" + "github.com/go-openapi/errors" "github.com/go-openapi/strfmt" "github.com/go-openapi/swag" @@ -53,6 +55,8 @@ func (m *Event) validateMeta(formats strfmt.Registry) error { if err := m.Meta.Validate(formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("meta") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("meta") } return err } @@ -69,6 +73,34 @@ func (m *Event) validateTimestamp(formats strfmt.Registry) error { return nil } +// ContextValidate validate this event based on the context it is used +func (m *Event) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateMeta(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *Event) contextValidateMeta(ctx context.Context, formats strfmt.Registry) error { + + if err := m.Meta.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("meta") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("meta") + } + return err + } + + return nil +} + // MarshalBinary interface implementation func (m *Event) MarshalBinary() ([]byte, error) { if m == nil { diff --git a/pkg/models/get_alerts_response.go b/pkg/models/get_alerts_response.go index 2c673d650..41b9d5afd 100644 --- a/pkg/models/get_alerts_response.go +++ b/pkg/models/get_alerts_response.go @@ -6,6 +6,7 @@ package models // Editing this file might prove futile when you re-run the swagger generate command import ( + "context" "strconv" "github.com/go-openapi/errors" @@ -31,6 +32,33 @@ func (m GetAlertsResponse) Validate(formats strfmt.Registry) error { if err := m[i].Validate(formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName(strconv.Itoa(i)) + } + return err + } + } + + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// ContextValidate validate this get alerts response based on the context it is used +func (m GetAlertsResponse) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + for i := 0; i < len(m); i++ { + + if m[i] != nil { + if err := m[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName(strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName(strconv.Itoa(i)) } return err } diff --git a/pkg/models/get_decisions_response.go b/pkg/models/get_decisions_response.go index 7113212ba..b65b950fc 100644 --- a/pkg/models/get_decisions_response.go +++ b/pkg/models/get_decisions_response.go @@ -6,6 +6,7 @@ package models // Editing this file might prove futile when you re-run the swagger generate command import ( + "context" "strconv" "github.com/go-openapi/errors" @@ -31,6 +32,33 @@ func (m GetDecisionsResponse) Validate(formats strfmt.Registry) error { if err := m[i].Validate(formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName(strconv.Itoa(i)) + } + return err + } + } + + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// ContextValidate validate this get decisions response based on the context it is used +func (m GetDecisionsResponse) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + for i := 0; i < len(m); i++ { + + if m[i] != nil { + if err := m[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName(strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName(strconv.Itoa(i)) } return err } diff --git a/pkg/models/localapi_swagger.yaml b/pkg/models/localapi_swagger.yaml index 680f39a47..b30036fc2 100644 --- a/pkg/models/localapi_swagger.yaml +++ b/pkg/models/localapi_swagger.yaml @@ -45,7 +45,6 @@ paths: required: false type: string description: 'Comma separated scopes of decisions to fetch' - example: ip,range,country responses: '200': description: successful operation @@ -406,6 +405,11 @@ paths: required: false type: number description: 'number of alerts to return' + - name: origin + in: query + required: false + type: string + description: 'restrict results to this origin (ie. lists,CAPI,cscli)' responses: '200': description: successful operation @@ -485,6 +489,11 @@ paths: required: false type: number description: 'number of alerts to return' + - name: origin + in: query + required: false + type: string + description: 'restrict results to this origin (ie. lists,CAPI,cscli)' responses: '200': description: successful operation diff --git a/pkg/models/meta.go b/pkg/models/meta.go index 74e7532fc..6ad20856d 100644 --- a/pkg/models/meta.go +++ b/pkg/models/meta.go @@ -6,6 +6,7 @@ package models // Editing this file might prove futile when you re-run the swagger generate command import ( + "context" "strconv" "github.com/go-openapi/errors" @@ -33,6 +34,33 @@ func (m Meta) Validate(formats strfmt.Registry) error { if err := m[i].Validate(formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName(strconv.Itoa(i)) + } + return err + } + } + + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// ContextValidate validate this meta based on the context it is used +func (m Meta) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + for i := 0; i < len(m); i++ { + + if m[i] != nil { + if err := m[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName(strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName(strconv.Itoa(i)) } return err } @@ -63,6 +91,11 @@ func (m *MetaItems0) Validate(formats strfmt.Registry) error { return nil } +// ContextValidate validates this meta items0 based on context it is used +func (m *MetaItems0) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + // MarshalBinary interface implementation func (m *MetaItems0) MarshalBinary() ([]byte, error) { if m == nil { diff --git a/pkg/models/metrics.go b/pkg/models/metrics.go index 1e96d37c1..5b647bfbd 100644 --- a/pkg/models/metrics.go +++ b/pkg/models/metrics.go @@ -6,6 +6,7 @@ package models // Editing this file might prove futile when you re-run the swagger generate command import ( + "context" "strconv" "github.com/go-openapi/errors" @@ -78,6 +79,8 @@ func (m *Metrics) validateBouncers(formats strfmt.Registry) error { if err := m.Bouncers[i].Validate(formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("bouncers" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("bouncers" + "." + strconv.Itoa(i)) } return err } @@ -103,6 +106,66 @@ func (m *Metrics) validateMachines(formats strfmt.Registry) error { if err := m.Machines[i].Validate(formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("machines" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("machines" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +// ContextValidate validate this metrics based on the context it is used +func (m *Metrics) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateBouncers(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidateMachines(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *Metrics) contextValidateBouncers(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.Bouncers); i++ { + + if m.Bouncers[i] != nil { + if err := m.Bouncers[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("bouncers" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("bouncers" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +func (m *Metrics) contextValidateMachines(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.Machines); i++ { + + if m.Machines[i] != nil { + if err := m.Machines[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("machines" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("machines" + "." + strconv.Itoa(i)) } return err } diff --git a/pkg/models/metrics_soft_info.go b/pkg/models/metrics_soft_info.go index 60aa727bb..cd5be2c07 100644 --- a/pkg/models/metrics_soft_info.go +++ b/pkg/models/metrics_soft_info.go @@ -6,6 +6,8 @@ package models // Editing this file might prove futile when you re-run the swagger generate command import ( + "context" + "github.com/go-openapi/strfmt" "github.com/go-openapi/swag" ) @@ -29,6 +31,11 @@ func (m *MetricsSoftInfo) Validate(formats strfmt.Registry) error { return nil } +// ContextValidate validates this metrics soft info based on context it is used +func (m *MetricsSoftInfo) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + // MarshalBinary interface implementation func (m *MetricsSoftInfo) MarshalBinary() ([]byte, error) { if m == nil { diff --git a/pkg/models/source.go b/pkg/models/source.go index c6dc57905..8b3a81aeb 100644 --- a/pkg/models/source.go +++ b/pkg/models/source.go @@ -6,6 +6,8 @@ package models // Editing this file might prove futile when you re-run the swagger generate command import ( + "context" + "github.com/go-openapi/errors" "github.com/go-openapi/strfmt" "github.com/go-openapi/swag" @@ -83,6 +85,11 @@ func (m *Source) validateValue(formats strfmt.Registry) error { return nil } +// ContextValidate validates this source based on context it is used +func (m *Source) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + // MarshalBinary interface implementation func (m *Source) MarshalBinary() ([]byte, error) { if m == nil { diff --git a/pkg/models/watcher_auth_request.go b/pkg/models/watcher_auth_request.go index 1be134a8b..52347c581 100644 --- a/pkg/models/watcher_auth_request.go +++ b/pkg/models/watcher_auth_request.go @@ -6,6 +6,8 @@ package models // Editing this file might prove futile when you re-run the swagger generate command import ( + "context" + "github.com/go-openapi/errors" "github.com/go-openapi/strfmt" "github.com/go-openapi/swag" @@ -70,6 +72,11 @@ func (m *WatcherAuthRequest) validatePassword(formats strfmt.Registry) error { return nil } +// ContextValidate validates this watcher auth request based on context it is used +func (m *WatcherAuthRequest) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + // MarshalBinary interface implementation func (m *WatcherAuthRequest) MarshalBinary() ([]byte, error) { if m == nil { diff --git a/pkg/models/watcher_auth_response.go b/pkg/models/watcher_auth_response.go index 185aa875e..296812dc8 100644 --- a/pkg/models/watcher_auth_response.go +++ b/pkg/models/watcher_auth_response.go @@ -6,6 +6,8 @@ package models // Editing this file might prove futile when you re-run the swagger generate command import ( + "context" + "github.com/go-openapi/strfmt" "github.com/go-openapi/swag" ) @@ -32,6 +34,11 @@ func (m *WatcherAuthResponse) Validate(formats strfmt.Registry) error { return nil } +// ContextValidate validates this watcher auth response based on context it is used +func (m *WatcherAuthResponse) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + // MarshalBinary interface implementation func (m *WatcherAuthResponse) MarshalBinary() ([]byte, error) { if m == nil { diff --git a/pkg/models/watcher_registration_request.go b/pkg/models/watcher_registration_request.go index 194a1e715..8be802ea3 100644 --- a/pkg/models/watcher_registration_request.go +++ b/pkg/models/watcher_registration_request.go @@ -6,6 +6,8 @@ package models // Editing this file might prove futile when you re-run the swagger generate command import ( + "context" + "github.com/go-openapi/errors" "github.com/go-openapi/strfmt" "github.com/go-openapi/swag" @@ -67,6 +69,11 @@ func (m *WatcherRegistrationRequest) validatePassword(formats strfmt.Registry) e return nil } +// ContextValidate validates this watcher registration request based on context it is used +func (m *WatcherRegistrationRequest) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + // MarshalBinary interface implementation func (m *WatcherRegistrationRequest) MarshalBinary() ([]byte, error) { if m == nil {