mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2025-05-10 20:05:55 +02:00
usage metrics: validate maxLength for some elements (#3131)
Co-authored-by: Sebastien Blot <sebastien@crowdsec.net>
This commit is contained in:
parent
5390b8ea4b
commit
c4da2775cd
5 changed files with 47 additions and 0 deletions
|
@ -35,6 +35,7 @@ type BaseMetrics struct {
|
|||
|
||||
// version of the remediation component
|
||||
// Required: true
|
||||
// Max Length: 255
|
||||
Version *string `json:"version"`
|
||||
}
|
||||
|
||||
|
@ -124,6 +125,10 @@ func (m *BaseMetrics) validateVersion(formats strfmt.Registry) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if err := validate.MaxLength("version", "body", *m.Version, 255); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -1095,6 +1095,7 @@ definitions:
|
|||
version:
|
||||
type: string
|
||||
description: version of the remediation component
|
||||
maxLength: 255
|
||||
os:
|
||||
$ref: '#/definitions/OSversion'
|
||||
metrics:
|
||||
|
@ -1107,6 +1108,7 @@ definitions:
|
|||
items:
|
||||
type: string
|
||||
description: feature flags (expected to be empty for remediation components)
|
||||
maxLength: 255
|
||||
utc_startup_timestamp:
|
||||
type: integer
|
||||
description: UTC timestamp of the startup of the software
|
||||
|
@ -1120,9 +1122,11 @@ definitions:
|
|||
name:
|
||||
type: string
|
||||
description: name of the OS
|
||||
maxLength: 255
|
||||
version:
|
||||
type: string
|
||||
description: version of the OS
|
||||
maxLength: 255
|
||||
required:
|
||||
- name
|
||||
- version
|
||||
|
@ -1146,12 +1150,14 @@ definitions:
|
|||
name:
|
||||
type: string
|
||||
description: name of the metric
|
||||
maxLength: 255
|
||||
value:
|
||||
type: number
|
||||
description: value of the metric
|
||||
unit:
|
||||
type: string
|
||||
description: unit of the metric
|
||||
maxLength: 255
|
||||
labels:
|
||||
$ref: '#/definitions/MetricsLabels'
|
||||
description: labels of the metric
|
||||
|
@ -1178,6 +1184,7 @@ definitions:
|
|||
additionalProperties:
|
||||
type: string
|
||||
description: label of the metric
|
||||
maxLength: 255
|
||||
ConsoleOptions:
|
||||
title: ConsoleOptions
|
||||
type: array
|
||||
|
|
|
@ -24,10 +24,12 @@ type MetricsDetailItem struct {
|
|||
|
||||
// name of the metric
|
||||
// Required: true
|
||||
// Max Length: 255
|
||||
Name *string `json:"name"`
|
||||
|
||||
// unit of the metric
|
||||
// Required: true
|
||||
// Max Length: 255
|
||||
Unit *string `json:"unit"`
|
||||
|
||||
// value of the metric
|
||||
|
@ -86,6 +88,10 @@ func (m *MetricsDetailItem) validateName(formats strfmt.Registry) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if err := validate.MaxLength("name", "body", *m.Name, 255); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -95,6 +101,10 @@ func (m *MetricsDetailItem) validateUnit(formats strfmt.Registry) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if err := validate.MaxLength("unit", "body", *m.Unit, 255); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,9 @@ package models
|
|||
import (
|
||||
"context"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/strfmt"
|
||||
"github.com/go-openapi/validate"
|
||||
)
|
||||
|
||||
// MetricsLabels MetricsLabels
|
||||
|
@ -18,6 +20,19 @@ type MetricsLabels map[string]string
|
|||
|
||||
// Validate validates this metrics labels
|
||||
func (m MetricsLabels) Validate(formats strfmt.Registry) error {
|
||||
var res []error
|
||||
|
||||
for k := range m {
|
||||
|
||||
if err := validate.MaxLength(k, "body", m[k], 255); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -21,10 +21,12 @@ type OSversion struct {
|
|||
|
||||
// name of the OS
|
||||
// Required: true
|
||||
// Max Length: 255
|
||||
Name *string `json:"name"`
|
||||
|
||||
// version of the OS
|
||||
// Required: true
|
||||
// Max Length: 255
|
||||
Version *string `json:"version"`
|
||||
}
|
||||
|
||||
|
@ -52,6 +54,10 @@ func (m *OSversion) validateName(formats strfmt.Registry) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if err := validate.MaxLength("name", "body", *m.Name, 255); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -61,6 +67,10 @@ func (m *OSversion) validateVersion(formats strfmt.Registry) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if err := validate.MaxLength("version", "body", *m.Version, 255); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue