fix the swagger model
This commit is contained in:
parent
03dbce1e50
commit
1372c49505
3 changed files with 64 additions and 2 deletions
|
@ -78,7 +78,7 @@ func (a *apic) FetchScenariosListFromDB() ([]string, error) {
|
|||
}
|
||||
|
||||
func AlertToSignal(alert *models.Alert, scenarioTrust string, keepDecisions bool) *models.AddSignalsRequestItem {
|
||||
return &models.AddSignalsRequestItem{
|
||||
signal := &models.AddSignalsRequestItem{
|
||||
Message: alert.Message,
|
||||
Scenario: alert.Scenario,
|
||||
ScenarioHash: alert.ScenarioHash,
|
||||
|
@ -88,7 +88,13 @@ func AlertToSignal(alert *models.Alert, scenarioTrust string, keepDecisions bool
|
|||
StopAt: alert.StopAt,
|
||||
CreatedAt: alert.CreatedAt,
|
||||
MachineID: alert.MachineID,
|
||||
ScenarioTrust: &scenarioTrust,
|
||||
}
|
||||
if keepDecisions {
|
||||
log.Printf("Keeping decisions to send to CAPI")
|
||||
signal.Decisions = alert.Decisions
|
||||
}
|
||||
return signal
|
||||
}
|
||||
|
||||
func NewAPIC(config *csconfig.OnlineApiClientCfg, dbClient *database.Client, consoleConfig *csconfig.ConsoleConfig) (*apic, error) {
|
||||
|
|
|
@ -6,6 +6,8 @@ package models
|
|||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/strfmt"
|
||||
"github.com/go-openapi/swag"
|
||||
|
@ -20,6 +22,9 @@ type AddSignalsRequestItem struct {
|
|||
// created at
|
||||
CreatedAt string `json:"created_at,omitempty"`
|
||||
|
||||
// decisions
|
||||
Decisions []*Decision `json:"decisions"`
|
||||
|
||||
// machine id
|
||||
MachineID string `json:"machine_id,omitempty"`
|
||||
|
||||
|
@ -35,6 +40,10 @@ type AddSignalsRequestItem struct {
|
|||
// Required: true
|
||||
ScenarioHash *string `json:"scenario_hash"`
|
||||
|
||||
// scenario trust
|
||||
// Required: true
|
||||
ScenarioTrust *string `json:"scenario_trust"`
|
||||
|
||||
// scenario version
|
||||
// Required: true
|
||||
ScenarioVersion *string `json:"scenario_version"`
|
||||
|
@ -56,6 +65,10 @@ type AddSignalsRequestItem struct {
|
|||
func (m *AddSignalsRequestItem) Validate(formats strfmt.Registry) error {
|
||||
var res []error
|
||||
|
||||
if err := m.validateDecisions(formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if err := m.validateMessage(formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
@ -68,6 +81,10 @@ func (m *AddSignalsRequestItem) Validate(formats strfmt.Registry) error {
|
|||
res = append(res, err)
|
||||
}
|
||||
|
||||
if err := m.validateScenarioTrust(formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if err := m.validateScenarioVersion(formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
@ -90,6 +107,30 @@ func (m *AddSignalsRequestItem) Validate(formats strfmt.Registry) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (m *AddSignalsRequestItem) validateDecisions(formats strfmt.Registry) error {
|
||||
if swag.IsZero(m.Decisions) { // not required
|
||||
return nil
|
||||
}
|
||||
|
||||
for i := 0; i < len(m.Decisions); i++ {
|
||||
if swag.IsZero(m.Decisions[i]) { // not required
|
||||
continue
|
||||
}
|
||||
|
||||
if m.Decisions[i] != nil {
|
||||
if err := m.Decisions[i].Validate(formats); err != nil {
|
||||
if ve, ok := err.(*errors.Validation); ok {
|
||||
return ve.ValidateName("decisions" + "." + strconv.Itoa(i))
|
||||
}
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *AddSignalsRequestItem) validateMessage(formats strfmt.Registry) error {
|
||||
|
||||
if err := validate.Required("message", "body", m.Message); err != nil {
|
||||
|
@ -117,6 +158,15 @@ func (m *AddSignalsRequestItem) validateScenarioHash(formats strfmt.Registry) er
|
|||
return nil
|
||||
}
|
||||
|
||||
func (m *AddSignalsRequestItem) validateScenarioTrust(formats strfmt.Registry) error {
|
||||
|
||||
if err := validate.Required("scenario_trust", "body", m.ScenarioTrust); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *AddSignalsRequestItem) validateScenarioVersion(formats strfmt.Registry) error {
|
||||
|
||||
if err := validate.Required("scenario_version", "body", m.ScenarioVersion); err != nil {
|
||||
|
|
|
@ -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
|
||||
|
@ -917,6 +916,7 @@ definitions:
|
|||
- "source"
|
||||
- "start_at"
|
||||
- "stop_at"
|
||||
- "scenario_trust"
|
||||
properties:
|
||||
scenario_hash:
|
||||
type: "string"
|
||||
|
@ -930,6 +930,8 @@ definitions:
|
|||
$ref: "#/definitions/Source"
|
||||
scenario_version:
|
||||
type: "string"
|
||||
scenario_trust:
|
||||
type: "string"
|
||||
message:
|
||||
type: "string"
|
||||
description: "a human readable message"
|
||||
|
@ -937,6 +939,10 @@ definitions:
|
|||
type: "string"
|
||||
stop_at:
|
||||
type: "string"
|
||||
decisions:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/definitions/Decision'
|
||||
title: "Signal"
|
||||
tags:
|
||||
- name: bouncers
|
||||
|
|
Loading…
Add table
Reference in a new issue