github.com/crowdsecurity/crowdsec@v1.6.1/pkg/modelscapi/metrics_request.go (about)

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  package modelscapi
     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  // MetricsRequest metrics
    19  //
    20  // push metrics model
    21  //
    22  // swagger:model MetricsRequest
    23  type MetricsRequest struct {
    24  
    25  	// bouncers
    26  	// Required: true
    27  	Bouncers []*MetricsRequestBouncersItem `json:"bouncers"`
    28  
    29  	// machines
    30  	// Required: true
    31  	Machines []*MetricsRequestMachinesItem `json:"machines"`
    32  }
    33  
    34  // Validate validates this metrics request
    35  func (m *MetricsRequest) Validate(formats strfmt.Registry) error {
    36  	var res []error
    37  
    38  	if err := m.validateBouncers(formats); err != nil {
    39  		res = append(res, err)
    40  	}
    41  
    42  	if err := m.validateMachines(formats); err != nil {
    43  		res = append(res, err)
    44  	}
    45  
    46  	if len(res) > 0 {
    47  		return errors.CompositeValidationError(res...)
    48  	}
    49  	return nil
    50  }
    51  
    52  func (m *MetricsRequest) validateBouncers(formats strfmt.Registry) error {
    53  
    54  	if err := validate.Required("bouncers", "body", m.Bouncers); err != nil {
    55  		return err
    56  	}
    57  
    58  	for i := 0; i < len(m.Bouncers); i++ {
    59  		if swag.IsZero(m.Bouncers[i]) { // not required
    60  			continue
    61  		}
    62  
    63  		if m.Bouncers[i] != nil {
    64  			if err := m.Bouncers[i].Validate(formats); err != nil {
    65  				if ve, ok := err.(*errors.Validation); ok {
    66  					return ve.ValidateName("bouncers" + "." + strconv.Itoa(i))
    67  				} else if ce, ok := err.(*errors.CompositeError); ok {
    68  					return ce.ValidateName("bouncers" + "." + strconv.Itoa(i))
    69  				}
    70  				return err
    71  			}
    72  		}
    73  
    74  	}
    75  
    76  	return nil
    77  }
    78  
    79  func (m *MetricsRequest) validateMachines(formats strfmt.Registry) error {
    80  
    81  	if err := validate.Required("machines", "body", m.Machines); err != nil {
    82  		return err
    83  	}
    84  
    85  	for i := 0; i < len(m.Machines); i++ {
    86  		if swag.IsZero(m.Machines[i]) { // not required
    87  			continue
    88  		}
    89  
    90  		if m.Machines[i] != nil {
    91  			if err := m.Machines[i].Validate(formats); err != nil {
    92  				if ve, ok := err.(*errors.Validation); ok {
    93  					return ve.ValidateName("machines" + "." + strconv.Itoa(i))
    94  				} else if ce, ok := err.(*errors.CompositeError); ok {
    95  					return ce.ValidateName("machines" + "." + strconv.Itoa(i))
    96  				}
    97  				return err
    98  			}
    99  		}
   100  
   101  	}
   102  
   103  	return nil
   104  }
   105  
   106  // ContextValidate validate this metrics request based on the context it is used
   107  func (m *MetricsRequest) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   108  	var res []error
   109  
   110  	if err := m.contextValidateBouncers(ctx, formats); err != nil {
   111  		res = append(res, err)
   112  	}
   113  
   114  	if err := m.contextValidateMachines(ctx, formats); err != nil {
   115  		res = append(res, err)
   116  	}
   117  
   118  	if len(res) > 0 {
   119  		return errors.CompositeValidationError(res...)
   120  	}
   121  	return nil
   122  }
   123  
   124  func (m *MetricsRequest) contextValidateBouncers(ctx context.Context, formats strfmt.Registry) error {
   125  
   126  	for i := 0; i < len(m.Bouncers); i++ {
   127  
   128  		if m.Bouncers[i] != nil {
   129  			if err := m.Bouncers[i].ContextValidate(ctx, formats); err != nil {
   130  				if ve, ok := err.(*errors.Validation); ok {
   131  					return ve.ValidateName("bouncers" + "." + strconv.Itoa(i))
   132  				} else if ce, ok := err.(*errors.CompositeError); ok {
   133  					return ce.ValidateName("bouncers" + "." + strconv.Itoa(i))
   134  				}
   135  				return err
   136  			}
   137  		}
   138  
   139  	}
   140  
   141  	return nil
   142  }
   143  
   144  func (m *MetricsRequest) contextValidateMachines(ctx context.Context, formats strfmt.Registry) error {
   145  
   146  	for i := 0; i < len(m.Machines); i++ {
   147  
   148  		if m.Machines[i] != nil {
   149  			if err := m.Machines[i].ContextValidate(ctx, formats); err != nil {
   150  				if ve, ok := err.(*errors.Validation); ok {
   151  					return ve.ValidateName("machines" + "." + strconv.Itoa(i))
   152  				} else if ce, ok := err.(*errors.CompositeError); ok {
   153  					return ce.ValidateName("machines" + "." + strconv.Itoa(i))
   154  				}
   155  				return err
   156  			}
   157  		}
   158  
   159  	}
   160  
   161  	return nil
   162  }
   163  
   164  // MarshalBinary interface implementation
   165  func (m *MetricsRequest) MarshalBinary() ([]byte, error) {
   166  	if m == nil {
   167  		return nil, nil
   168  	}
   169  	return swag.WriteJSON(m)
   170  }
   171  
   172  // UnmarshalBinary interface implementation
   173  func (m *MetricsRequest) UnmarshalBinary(b []byte) error {
   174  	var res MetricsRequest
   175  	if err := swag.ReadJSON(b, &res); err != nil {
   176  		return err
   177  	}
   178  	*m = res
   179  	return nil
   180  }