github.com/crowdsecurity/crowdsec@v1.6.1/pkg/models/decision.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  
    11  	"github.com/go-openapi/errors"
    12  	"github.com/go-openapi/strfmt"
    13  	"github.com/go-openapi/swag"
    14  	"github.com/go-openapi/validate"
    15  )
    16  
    17  // Decision Decision
    18  //
    19  // swagger:model Decision
    20  type Decision struct {
    21  
    22  	// the duration of the decisions
    23  	// Required: true
    24  	Duration *string `json:"duration"`
    25  
    26  	// (only relevant for GET ops) the unique id
    27  	// Read Only: true
    28  	ID int64 `json:"id,omitempty"`
    29  
    30  	// the origin of the decision : cscli, crowdsec
    31  	// Required: true
    32  	Origin *string `json:"origin"`
    33  
    34  	// scenario
    35  	// Required: true
    36  	Scenario *string `json:"scenario"`
    37  
    38  	// the scope of decision : does it apply to an IP, a range, a username, etc
    39  	// Required: true
    40  	Scope *string `json:"scope"`
    41  
    42  	// true if the decision result from a scenario in simulation mode
    43  	// Read Only: true
    44  	Simulated *bool `json:"simulated,omitempty"`
    45  
    46  	// the type of decision, might be 'ban', 'captcha' or something custom. Ignored when watcher (cscli/crowdsec) is pushing to APIL.
    47  	// Required: true
    48  	Type *string `json:"type"`
    49  
    50  	// the date until the decisions must be active
    51  	Until string `json:"until,omitempty"`
    52  
    53  	// only relevant for LAPI->CAPI, ignored for cscli->LAPI and crowdsec->LAPI
    54  	// Read Only: true
    55  	UUID string `json:"uuid,omitempty"`
    56  
    57  	// the value of the decision scope : an IP, a range, a username, etc
    58  	// Required: true
    59  	Value *string `json:"value"`
    60  }
    61  
    62  // Validate validates this decision
    63  func (m *Decision) Validate(formats strfmt.Registry) error {
    64  	var res []error
    65  
    66  	if err := m.validateDuration(formats); err != nil {
    67  		res = append(res, err)
    68  	}
    69  
    70  	if err := m.validateOrigin(formats); err != nil {
    71  		res = append(res, err)
    72  	}
    73  
    74  	if err := m.validateScenario(formats); err != nil {
    75  		res = append(res, err)
    76  	}
    77  
    78  	if err := m.validateScope(formats); err != nil {
    79  		res = append(res, err)
    80  	}
    81  
    82  	if err := m.validateType(formats); err != nil {
    83  		res = append(res, err)
    84  	}
    85  
    86  	if err := m.validateValue(formats); err != nil {
    87  		res = append(res, err)
    88  	}
    89  
    90  	if len(res) > 0 {
    91  		return errors.CompositeValidationError(res...)
    92  	}
    93  	return nil
    94  }
    95  
    96  func (m *Decision) validateDuration(formats strfmt.Registry) error {
    97  
    98  	if err := validate.Required("duration", "body", m.Duration); err != nil {
    99  		return err
   100  	}
   101  
   102  	return nil
   103  }
   104  
   105  func (m *Decision) validateOrigin(formats strfmt.Registry) error {
   106  
   107  	if err := validate.Required("origin", "body", m.Origin); err != nil {
   108  		return err
   109  	}
   110  
   111  	return nil
   112  }
   113  
   114  func (m *Decision) validateScenario(formats strfmt.Registry) error {
   115  
   116  	if err := validate.Required("scenario", "body", m.Scenario); err != nil {
   117  		return err
   118  	}
   119  
   120  	return nil
   121  }
   122  
   123  func (m *Decision) validateScope(formats strfmt.Registry) error {
   124  
   125  	if err := validate.Required("scope", "body", m.Scope); err != nil {
   126  		return err
   127  	}
   128  
   129  	return nil
   130  }
   131  
   132  func (m *Decision) validateType(formats strfmt.Registry) error {
   133  
   134  	if err := validate.Required("type", "body", m.Type); err != nil {
   135  		return err
   136  	}
   137  
   138  	return nil
   139  }
   140  
   141  func (m *Decision) validateValue(formats strfmt.Registry) error {
   142  
   143  	if err := validate.Required("value", "body", m.Value); err != nil {
   144  		return err
   145  	}
   146  
   147  	return nil
   148  }
   149  
   150  // ContextValidate validate this decision based on the context it is used
   151  func (m *Decision) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   152  	var res []error
   153  
   154  	if err := m.contextValidateID(ctx, formats); err != nil {
   155  		res = append(res, err)
   156  	}
   157  
   158  	if err := m.contextValidateSimulated(ctx, formats); err != nil {
   159  		res = append(res, err)
   160  	}
   161  
   162  	if err := m.contextValidateUUID(ctx, formats); err != nil {
   163  		res = append(res, err)
   164  	}
   165  
   166  	if len(res) > 0 {
   167  		return errors.CompositeValidationError(res...)
   168  	}
   169  	return nil
   170  }
   171  
   172  func (m *Decision) contextValidateID(ctx context.Context, formats strfmt.Registry) error {
   173  
   174  	if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil {
   175  		return err
   176  	}
   177  
   178  	return nil
   179  }
   180  
   181  func (m *Decision) contextValidateSimulated(ctx context.Context, formats strfmt.Registry) error {
   182  
   183  	if err := validate.ReadOnly(ctx, "simulated", "body", m.Simulated); err != nil {
   184  		return err
   185  	}
   186  
   187  	return nil
   188  }
   189  
   190  func (m *Decision) contextValidateUUID(ctx context.Context, formats strfmt.Registry) error {
   191  
   192  	if err := validate.ReadOnly(ctx, "uuid", "body", string(m.UUID)); err != nil {
   193  		return err
   194  	}
   195  
   196  	return nil
   197  }
   198  
   199  // MarshalBinary interface implementation
   200  func (m *Decision) MarshalBinary() ([]byte, error) {
   201  	if m == nil {
   202  		return nil, nil
   203  	}
   204  	return swag.WriteJSON(m)
   205  }
   206  
   207  // UnmarshalBinary interface implementation
   208  func (m *Decision) UnmarshalBinary(b []byte) error {
   209  	var res Decision
   210  	if err := swag.ReadJSON(b, &res); err != nil {
   211  		return err
   212  	}
   213  	*m = res
   214  	return nil
   215  }