fix the swagger model
This commit is contained in:
parent
03dbce1e50
commit
1372c49505
|
@ -78,7 +78,7 @@ func (a *apic) FetchScenariosListFromDB() ([]string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func AlertToSignal(alert *models.Alert, scenarioTrust string, keepDecisions bool) *models.AddSignalsRequestItem {
|
func AlertToSignal(alert *models.Alert, scenarioTrust string, keepDecisions bool) *models.AddSignalsRequestItem {
|
||||||
return &models.AddSignalsRequestItem{
|
signal := &models.AddSignalsRequestItem{
|
||||||
Message: alert.Message,
|
Message: alert.Message,
|
||||||
Scenario: alert.Scenario,
|
Scenario: alert.Scenario,
|
||||||
ScenarioHash: alert.ScenarioHash,
|
ScenarioHash: alert.ScenarioHash,
|
||||||
|
@ -88,7 +88,13 @@ func AlertToSignal(alert *models.Alert, scenarioTrust string, keepDecisions bool
|
||||||
StopAt: alert.StopAt,
|
StopAt: alert.StopAt,
|
||||||
CreatedAt: alert.CreatedAt,
|
CreatedAt: alert.CreatedAt,
|
||||||
MachineID: alert.MachineID,
|
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) {
|
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
|
// Editing this file might prove futile when you re-run the swagger generate command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/go-openapi/errors"
|
"github.com/go-openapi/errors"
|
||||||
"github.com/go-openapi/strfmt"
|
"github.com/go-openapi/strfmt"
|
||||||
"github.com/go-openapi/swag"
|
"github.com/go-openapi/swag"
|
||||||
|
@ -20,6 +22,9 @@ type AddSignalsRequestItem struct {
|
||||||
// created at
|
// created at
|
||||||
CreatedAt string `json:"created_at,omitempty"`
|
CreatedAt string `json:"created_at,omitempty"`
|
||||||
|
|
||||||
|
// decisions
|
||||||
|
Decisions []*Decision `json:"decisions"`
|
||||||
|
|
||||||
// machine id
|
// machine id
|
||||||
MachineID string `json:"machine_id,omitempty"`
|
MachineID string `json:"machine_id,omitempty"`
|
||||||
|
|
||||||
|
@ -35,6 +40,10 @@ type AddSignalsRequestItem struct {
|
||||||
// Required: true
|
// Required: true
|
||||||
ScenarioHash *string `json:"scenario_hash"`
|
ScenarioHash *string `json:"scenario_hash"`
|
||||||
|
|
||||||
|
// scenario trust
|
||||||
|
// Required: true
|
||||||
|
ScenarioTrust *string `json:"scenario_trust"`
|
||||||
|
|
||||||
// scenario version
|
// scenario version
|
||||||
// Required: true
|
// Required: true
|
||||||
ScenarioVersion *string `json:"scenario_version"`
|
ScenarioVersion *string `json:"scenario_version"`
|
||||||
|
@ -56,6 +65,10 @@ type AddSignalsRequestItem struct {
|
||||||
func (m *AddSignalsRequestItem) Validate(formats strfmt.Registry) error {
|
func (m *AddSignalsRequestItem) Validate(formats strfmt.Registry) error {
|
||||||
var res []error
|
var res []error
|
||||||
|
|
||||||
|
if err := m.validateDecisions(formats); err != nil {
|
||||||
|
res = append(res, err)
|
||||||
|
}
|
||||||
|
|
||||||
if err := m.validateMessage(formats); err != nil {
|
if err := m.validateMessage(formats); err != nil {
|
||||||
res = append(res, err)
|
res = append(res, err)
|
||||||
}
|
}
|
||||||
|
@ -68,6 +81,10 @@ func (m *AddSignalsRequestItem) Validate(formats strfmt.Registry) error {
|
||||||
res = append(res, err)
|
res = append(res, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := m.validateScenarioTrust(formats); err != nil {
|
||||||
|
res = append(res, err)
|
||||||
|
}
|
||||||
|
|
||||||
if err := m.validateScenarioVersion(formats); err != nil {
|
if err := m.validateScenarioVersion(formats); err != nil {
|
||||||
res = append(res, err)
|
res = append(res, err)
|
||||||
}
|
}
|
||||||
|
@ -90,6 +107,30 @@ func (m *AddSignalsRequestItem) Validate(formats strfmt.Registry) error {
|
||||||
return nil
|
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 {
|
func (m *AddSignalsRequestItem) validateMessage(formats strfmt.Registry) error {
|
||||||
|
|
||||||
if err := validate.Required("message", "body", m.Message); err != nil {
|
if err := validate.Required("message", "body", m.Message); err != nil {
|
||||||
|
@ -117,6 +158,15 @@ func (m *AddSignalsRequestItem) validateScenarioHash(formats strfmt.Registry) er
|
||||||
return nil
|
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 {
|
func (m *AddSignalsRequestItem) validateScenarioVersion(formats strfmt.Registry) error {
|
||||||
|
|
||||||
if err := validate.Required("scenario_version", "body", m.ScenarioVersion); err != nil {
|
if err := validate.Required("scenario_version", "body", m.ScenarioVersion); err != nil {
|
||||||
|
|
|
@ -45,7 +45,6 @@ paths:
|
||||||
required: false
|
required: false
|
||||||
type: string
|
type: string
|
||||||
description: 'Comma separated scopes of decisions to fetch'
|
description: 'Comma separated scopes of decisions to fetch'
|
||||||
example: ip,range,country
|
|
||||||
responses:
|
responses:
|
||||||
'200':
|
'200':
|
||||||
description: successful operation
|
description: successful operation
|
||||||
|
@ -917,6 +916,7 @@ definitions:
|
||||||
- "source"
|
- "source"
|
||||||
- "start_at"
|
- "start_at"
|
||||||
- "stop_at"
|
- "stop_at"
|
||||||
|
- "scenario_trust"
|
||||||
properties:
|
properties:
|
||||||
scenario_hash:
|
scenario_hash:
|
||||||
type: "string"
|
type: "string"
|
||||||
|
@ -930,6 +930,8 @@ definitions:
|
||||||
$ref: "#/definitions/Source"
|
$ref: "#/definitions/Source"
|
||||||
scenario_version:
|
scenario_version:
|
||||||
type: "string"
|
type: "string"
|
||||||
|
scenario_trust:
|
||||||
|
type: "string"
|
||||||
message:
|
message:
|
||||||
type: "string"
|
type: "string"
|
||||||
description: "a human readable message"
|
description: "a human readable message"
|
||||||
|
@ -937,6 +939,10 @@ definitions:
|
||||||
type: "string"
|
type: "string"
|
||||||
stop_at:
|
stop_at:
|
||||||
type: "string"
|
type: "string"
|
||||||
|
decisions:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/Decision'
|
||||||
title: "Signal"
|
title: "Signal"
|
||||||
tags:
|
tags:
|
||||||
- name: bouncers
|
- name: bouncers
|
||||||
|
|
Loading…
Reference in a new issue