github.com/kubearmor/cilium@v1.6.12/api/v1/models/l4_policy.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  	"strconv"
    10  
    11  	strfmt "github.com/go-openapi/strfmt"
    12  
    13  	"github.com/go-openapi/errors"
    14  	"github.com/go-openapi/swag"
    15  )
    16  
    17  // L4Policy L4 endpoint policy
    18  // swagger:model L4Policy
    19  type L4Policy struct {
    20  
    21  	// List of L4 egress rules
    22  	Egress []*PolicyRule `json:"egress"`
    23  
    24  	// List of L4 ingress rules
    25  	Ingress []*PolicyRule `json:"ingress"`
    26  }
    27  
    28  // Validate validates this l4 policy
    29  func (m *L4Policy) Validate(formats strfmt.Registry) error {
    30  	var res []error
    31  
    32  	if err := m.validateEgress(formats); err != nil {
    33  		res = append(res, err)
    34  	}
    35  
    36  	if err := m.validateIngress(formats); err != nil {
    37  		res = append(res, err)
    38  	}
    39  
    40  	if len(res) > 0 {
    41  		return errors.CompositeValidationError(res...)
    42  	}
    43  	return nil
    44  }
    45  
    46  func (m *L4Policy) validateEgress(formats strfmt.Registry) error {
    47  
    48  	if swag.IsZero(m.Egress) { // not required
    49  		return nil
    50  	}
    51  
    52  	for i := 0; i < len(m.Egress); i++ {
    53  		if swag.IsZero(m.Egress[i]) { // not required
    54  			continue
    55  		}
    56  
    57  		if m.Egress[i] != nil {
    58  			if err := m.Egress[i].Validate(formats); err != nil {
    59  				if ve, ok := err.(*errors.Validation); ok {
    60  					return ve.ValidateName("egress" + "." + strconv.Itoa(i))
    61  				}
    62  				return err
    63  			}
    64  		}
    65  
    66  	}
    67  
    68  	return nil
    69  }
    70  
    71  func (m *L4Policy) validateIngress(formats strfmt.Registry) error {
    72  
    73  	if swag.IsZero(m.Ingress) { // not required
    74  		return nil
    75  	}
    76  
    77  	for i := 0; i < len(m.Ingress); i++ {
    78  		if swag.IsZero(m.Ingress[i]) { // not required
    79  			continue
    80  		}
    81  
    82  		if m.Ingress[i] != nil {
    83  			if err := m.Ingress[i].Validate(formats); err != nil {
    84  				if ve, ok := err.(*errors.Validation); ok {
    85  					return ve.ValidateName("ingress" + "." + strconv.Itoa(i))
    86  				}
    87  				return err
    88  			}
    89  		}
    90  
    91  	}
    92  
    93  	return nil
    94  }
    95  
    96  // MarshalBinary interface implementation
    97  func (m *L4Policy) MarshalBinary() ([]byte, error) {
    98  	if m == nil {
    99  		return nil, nil
   100  	}
   101  	return swag.WriteJSON(m)
   102  }
   103  
   104  // UnmarshalBinary interface implementation
   105  func (m *L4Policy) UnmarshalBinary(b []byte) error {
   106  	var res L4Policy
   107  	if err := swag.ReadJSON(b, &res); err != nil {
   108  		return err
   109  	}
   110  	*m = res
   111  	return nil
   112  }