github.com/crowdsecurity/crowdsec@v1.6.1/pkg/models/alert.go (about) 1 // Code generated by go-swagger; DO NOT EDIT. 2 3 package models 4 5 // This file was generated by the swagger tool. 6 // Editing this file might prove futile when you re-run the swagger generate command 7 8 import ( 9 "context" 10 "strconv" 11 12 "github.com/go-openapi/errors" 13 "github.com/go-openapi/strfmt" 14 "github.com/go-openapi/swag" 15 "github.com/go-openapi/validate" 16 ) 17 18 // Alert Alert 19 // 20 // swagger:model Alert 21 type Alert struct { 22 23 // capacity 24 // Required: true 25 Capacity *int32 `json:"capacity"` 26 27 // only relevant for GET, ignored in POST requests 28 // Read Only: true 29 CreatedAt string `json:"created_at,omitempty"` 30 31 // decisions 32 Decisions []*Decision `json:"decisions"` 33 34 // the Meta of the events leading to overflow 35 // Required: true 36 Events []*Event `json:"events"` 37 38 // events count 39 // Required: true 40 EventsCount *int32 `json:"events_count"` 41 42 // only relevant for GET, ignored in POST requests 43 // Read Only: true 44 ID int64 `json:"id,omitempty"` 45 46 // labels 47 Labels []string `json:"labels"` 48 49 // leakspeed 50 // Required: true 51 Leakspeed *string `json:"leakspeed"` 52 53 // only relevant for LAPI->CAPI, ignored for cscli->LAPI and crowdsec->LAPI 54 // Read Only: true 55 MachineID string `json:"machine_id,omitempty"` 56 57 // a human readable message 58 // Required: true 59 Message *string `json:"message"` 60 61 // meta 62 Meta Meta `json:"meta,omitempty"` 63 64 // remediation 65 Remediation bool `json:"remediation,omitempty"` 66 67 // scenario 68 // Required: true 69 Scenario *string `json:"scenario"` 70 71 // scenario hash 72 // Required: true 73 ScenarioHash *string `json:"scenario_hash"` 74 75 // scenario version 76 // Required: true 77 ScenarioVersion *string `json:"scenario_version"` 78 79 // simulated 80 // Required: true 81 Simulated *bool `json:"simulated"` 82 83 // source 84 // Required: true 85 Source *Source `json:"source"` 86 87 // start at 88 // Required: true 89 StartAt *string `json:"start_at"` 90 91 // stop at 92 // Required: true 93 StopAt *string `json:"stop_at"` 94 95 // only relevant for LAPI->CAPI, ignored for cscli->LAPI and crowdsec->LAPI 96 // Read Only: true 97 UUID string `json:"uuid,omitempty"` 98 } 99 100 // Validate validates this alert 101 func (m *Alert) Validate(formats strfmt.Registry) error { 102 var res []error 103 104 if err := m.validateCapacity(formats); err != nil { 105 res = append(res, err) 106 } 107 108 if err := m.validateDecisions(formats); err != nil { 109 res = append(res, err) 110 } 111 112 if err := m.validateEvents(formats); err != nil { 113 res = append(res, err) 114 } 115 116 if err := m.validateEventsCount(formats); err != nil { 117 res = append(res, err) 118 } 119 120 if err := m.validateLeakspeed(formats); err != nil { 121 res = append(res, err) 122 } 123 124 if err := m.validateMessage(formats); err != nil { 125 res = append(res, err) 126 } 127 128 if err := m.validateMeta(formats); err != nil { 129 res = append(res, err) 130 } 131 132 if err := m.validateScenario(formats); err != nil { 133 res = append(res, err) 134 } 135 136 if err := m.validateScenarioHash(formats); err != nil { 137 res = append(res, err) 138 } 139 140 if err := m.validateScenarioVersion(formats); err != nil { 141 res = append(res, err) 142 } 143 144 if err := m.validateSimulated(formats); err != nil { 145 res = append(res, err) 146 } 147 148 if err := m.validateSource(formats); err != nil { 149 res = append(res, err) 150 } 151 152 if err := m.validateStartAt(formats); err != nil { 153 res = append(res, err) 154 } 155 156 if err := m.validateStopAt(formats); err != nil { 157 res = append(res, err) 158 } 159 160 if len(res) > 0 { 161 return errors.CompositeValidationError(res...) 162 } 163 return nil 164 } 165 166 func (m *Alert) validateCapacity(formats strfmt.Registry) error { 167 168 if err := validate.Required("capacity", "body", m.Capacity); err != nil { 169 return err 170 } 171 172 return nil 173 } 174 175 func (m *Alert) validateDecisions(formats strfmt.Registry) error { 176 if swag.IsZero(m.Decisions) { // not required 177 return nil 178 } 179 180 for i := 0; i < len(m.Decisions); i++ { 181 if swag.IsZero(m.Decisions[i]) { // not required 182 continue 183 } 184 185 if m.Decisions[i] != nil { 186 if err := m.Decisions[i].Validate(formats); err != nil { 187 if ve, ok := err.(*errors.Validation); ok { 188 return ve.ValidateName("decisions" + "." + strconv.Itoa(i)) 189 } else if ce, ok := err.(*errors.CompositeError); ok { 190 return ce.ValidateName("decisions" + "." + strconv.Itoa(i)) 191 } 192 return err 193 } 194 } 195 196 } 197 198 return nil 199 } 200 201 func (m *Alert) validateEvents(formats strfmt.Registry) error { 202 203 if err := validate.Required("events", "body", m.Events); err != nil { 204 return err 205 } 206 207 for i := 0; i < len(m.Events); i++ { 208 if swag.IsZero(m.Events[i]) { // not required 209 continue 210 } 211 212 if m.Events[i] != nil { 213 if err := m.Events[i].Validate(formats); err != nil { 214 if ve, ok := err.(*errors.Validation); ok { 215 return ve.ValidateName("events" + "." + strconv.Itoa(i)) 216 } else if ce, ok := err.(*errors.CompositeError); ok { 217 return ce.ValidateName("events" + "." + strconv.Itoa(i)) 218 } 219 return err 220 } 221 } 222 223 } 224 225 return nil 226 } 227 228 func (m *Alert) validateEventsCount(formats strfmt.Registry) error { 229 230 if err := validate.Required("events_count", "body", m.EventsCount); err != nil { 231 return err 232 } 233 234 return nil 235 } 236 237 func (m *Alert) validateLeakspeed(formats strfmt.Registry) error { 238 239 if err := validate.Required("leakspeed", "body", m.Leakspeed); err != nil { 240 return err 241 } 242 243 return nil 244 } 245 246 func (m *Alert) validateMessage(formats strfmt.Registry) error { 247 248 if err := validate.Required("message", "body", m.Message); err != nil { 249 return err 250 } 251 252 return nil 253 } 254 255 func (m *Alert) validateMeta(formats strfmt.Registry) error { 256 if swag.IsZero(m.Meta) { // not required 257 return nil 258 } 259 260 if err := m.Meta.Validate(formats); err != nil { 261 if ve, ok := err.(*errors.Validation); ok { 262 return ve.ValidateName("meta") 263 } else if ce, ok := err.(*errors.CompositeError); ok { 264 return ce.ValidateName("meta") 265 } 266 return err 267 } 268 269 return nil 270 } 271 272 func (m *Alert) validateScenario(formats strfmt.Registry) error { 273 274 if err := validate.Required("scenario", "body", m.Scenario); err != nil { 275 return err 276 } 277 278 return nil 279 } 280 281 func (m *Alert) validateScenarioHash(formats strfmt.Registry) error { 282 283 if err := validate.Required("scenario_hash", "body", m.ScenarioHash); err != nil { 284 return err 285 } 286 287 return nil 288 } 289 290 func (m *Alert) validateScenarioVersion(formats strfmt.Registry) error { 291 292 if err := validate.Required("scenario_version", "body", m.ScenarioVersion); err != nil { 293 return err 294 } 295 296 return nil 297 } 298 299 func (m *Alert) validateSimulated(formats strfmt.Registry) error { 300 301 if err := validate.Required("simulated", "body", m.Simulated); err != nil { 302 return err 303 } 304 305 return nil 306 } 307 308 func (m *Alert) validateSource(formats strfmt.Registry) error { 309 310 if err := validate.Required("source", "body", m.Source); err != nil { 311 return err 312 } 313 314 if m.Source != nil { 315 if err := m.Source.Validate(formats); err != nil { 316 if ve, ok := err.(*errors.Validation); ok { 317 return ve.ValidateName("source") 318 } else if ce, ok := err.(*errors.CompositeError); ok { 319 return ce.ValidateName("source") 320 } 321 return err 322 } 323 } 324 325 return nil 326 } 327 328 func (m *Alert) validateStartAt(formats strfmt.Registry) error { 329 330 if err := validate.Required("start_at", "body", m.StartAt); err != nil { 331 return err 332 } 333 334 return nil 335 } 336 337 func (m *Alert) validateStopAt(formats strfmt.Registry) error { 338 339 if err := validate.Required("stop_at", "body", m.StopAt); err != nil { 340 return err 341 } 342 343 return nil 344 } 345 346 // ContextValidate validate this alert based on the context it is used 347 func (m *Alert) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 348 var res []error 349 350 if err := m.contextValidateCreatedAt(ctx, formats); err != nil { 351 res = append(res, err) 352 } 353 354 if err := m.contextValidateDecisions(ctx, formats); err != nil { 355 res = append(res, err) 356 } 357 358 if err := m.contextValidateEvents(ctx, formats); err != nil { 359 res = append(res, err) 360 } 361 362 if err := m.contextValidateID(ctx, formats); err != nil { 363 res = append(res, err) 364 } 365 366 if err := m.contextValidateMachineID(ctx, formats); err != nil { 367 res = append(res, err) 368 } 369 370 if err := m.contextValidateMeta(ctx, formats); err != nil { 371 res = append(res, err) 372 } 373 374 if err := m.contextValidateSource(ctx, formats); err != nil { 375 res = append(res, err) 376 } 377 378 if err := m.contextValidateUUID(ctx, formats); err != nil { 379 res = append(res, err) 380 } 381 382 if len(res) > 0 { 383 return errors.CompositeValidationError(res...) 384 } 385 return nil 386 } 387 388 func (m *Alert) contextValidateCreatedAt(ctx context.Context, formats strfmt.Registry) error { 389 390 if err := validate.ReadOnly(ctx, "created_at", "body", string(m.CreatedAt)); err != nil { 391 return err 392 } 393 394 return nil 395 } 396 397 func (m *Alert) contextValidateDecisions(ctx context.Context, formats strfmt.Registry) error { 398 399 for i := 0; i < len(m.Decisions); i++ { 400 401 if m.Decisions[i] != nil { 402 403 if swag.IsZero(m.Decisions[i]) { // not required 404 return nil 405 } 406 407 if err := m.Decisions[i].ContextValidate(ctx, formats); err != nil { 408 if ve, ok := err.(*errors.Validation); ok { 409 return ve.ValidateName("decisions" + "." + strconv.Itoa(i)) 410 } else if ce, ok := err.(*errors.CompositeError); ok { 411 return ce.ValidateName("decisions" + "." + strconv.Itoa(i)) 412 } 413 return err 414 } 415 } 416 417 } 418 419 return nil 420 } 421 422 func (m *Alert) contextValidateEvents(ctx context.Context, formats strfmt.Registry) error { 423 424 for i := 0; i < len(m.Events); i++ { 425 426 if m.Events[i] != nil { 427 428 if swag.IsZero(m.Events[i]) { // not required 429 return nil 430 } 431 432 if err := m.Events[i].ContextValidate(ctx, formats); err != nil { 433 if ve, ok := err.(*errors.Validation); ok { 434 return ve.ValidateName("events" + "." + strconv.Itoa(i)) 435 } else if ce, ok := err.(*errors.CompositeError); ok { 436 return ce.ValidateName("events" + "." + strconv.Itoa(i)) 437 } 438 return err 439 } 440 } 441 442 } 443 444 return nil 445 } 446 447 func (m *Alert) contextValidateID(ctx context.Context, formats strfmt.Registry) error { 448 449 if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil { 450 return err 451 } 452 453 return nil 454 } 455 456 func (m *Alert) contextValidateMachineID(ctx context.Context, formats strfmt.Registry) error { 457 458 if err := validate.ReadOnly(ctx, "machine_id", "body", string(m.MachineID)); err != nil { 459 return err 460 } 461 462 return nil 463 } 464 465 func (m *Alert) contextValidateMeta(ctx context.Context, formats strfmt.Registry) error { 466 467 if err := m.Meta.ContextValidate(ctx, formats); err != nil { 468 if ve, ok := err.(*errors.Validation); ok { 469 return ve.ValidateName("meta") 470 } else if ce, ok := err.(*errors.CompositeError); ok { 471 return ce.ValidateName("meta") 472 } 473 return err 474 } 475 476 return nil 477 } 478 479 func (m *Alert) contextValidateSource(ctx context.Context, formats strfmt.Registry) error { 480 481 if m.Source != nil { 482 483 if err := m.Source.ContextValidate(ctx, formats); err != nil { 484 if ve, ok := err.(*errors.Validation); ok { 485 return ve.ValidateName("source") 486 } else if ce, ok := err.(*errors.CompositeError); ok { 487 return ce.ValidateName("source") 488 } 489 return err 490 } 491 } 492 493 return nil 494 } 495 496 func (m *Alert) contextValidateUUID(ctx context.Context, formats strfmt.Registry) error { 497 498 if err := validate.ReadOnly(ctx, "uuid", "body", string(m.UUID)); err != nil { 499 return err 500 } 501 502 return nil 503 } 504 505 // MarshalBinary interface implementation 506 func (m *Alert) MarshalBinary() ([]byte, error) { 507 if m == nil { 508 return nil, nil 509 } 510 return swag.WriteJSON(m) 511 } 512 513 // UnmarshalBinary interface implementation 514 func (m *Alert) UnmarshalBinary(b []byte) error { 515 var res Alert 516 if err := swag.ReadJSON(b, &res); err != nil { 517 return err 518 } 519 *m = res 520 return nil 521 }