Allow auto registration of machines in LAPI (#3202)

Co-authored-by: marco <marco@crowdsec.net>
This commit is contained in:
blotus 2024-09-02 13:13:40 +02:00 committed by GitHub
parent 8c0c10cd7a
commit d2616766de
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 548 additions and 173 deletions

View file

@ -27,6 +27,11 @@ type WatcherRegistrationRequest struct {
// Required: true
// Format: password
Password *strfmt.Password `json:"password"`
// registration token
// Max Length: 255
// Min Length: 32
RegistrationToken string `json:"registration_token,omitempty"`
}
// Validate validates this watcher registration request
@ -41,6 +46,10 @@ func (m *WatcherRegistrationRequest) Validate(formats strfmt.Registry) error {
res = append(res, err)
}
if err := m.validateRegistrationToken(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
@ -69,6 +78,22 @@ func (m *WatcherRegistrationRequest) validatePassword(formats strfmt.Registry) e
return nil
}
func (m *WatcherRegistrationRequest) validateRegistrationToken(formats strfmt.Registry) error {
if swag.IsZero(m.RegistrationToken) { // not required
return nil
}
if err := validate.MinLength("registration_token", "body", m.RegistrationToken, 32); err != nil {
return err
}
if err := validate.MaxLength("registration_token", "body", m.RegistrationToken, 255); err != nil {
return err
}
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