github.com/cilium/cilium@v1.16.2/api/v1/models/bgp_route_policy_statement.go (about)

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  // Copyright Authors of Cilium
     4  // SPDX-License-Identifier: Apache-2.0
     5  
     6  package models
     7  
     8  // This file was generated by the swagger tool.
     9  // Editing this file might prove futile when you re-run the swagger generate command
    10  
    11  import (
    12  	"context"
    13  	"encoding/json"
    14  	"strconv"
    15  
    16  	"github.com/go-openapi/errors"
    17  	"github.com/go-openapi/strfmt"
    18  	"github.com/go-openapi/swag"
    19  	"github.com/go-openapi/validate"
    20  )
    21  
    22  // BgpRoutePolicyStatement Single BGP route policy statement
    23  //
    24  // swagger:model BgpRoutePolicyStatement
    25  type BgpRoutePolicyStatement struct {
    26  
    27  	// List of BGP standard community values to be added to the matched route
    28  	AddCommunities []string `json:"add-communities"`
    29  
    30  	// List of BGP large community values to be added to the matched route
    31  	AddLargeCommunities []string `json:"add-large-communities"`
    32  
    33  	// Matches any of the provided BGP neighbor IP addresses. If empty matches all neighbors.
    34  	MatchNeighbors []string `json:"match-neighbors"`
    35  
    36  	// Matches any of the provided prefixes. If empty matches all prefixes.
    37  	MatchPrefixes []*BgpRoutePolicyPrefixMatch `json:"match-prefixes"`
    38  
    39  	// RIB processing action taken on the matched route
    40  	// Enum: [none accept reject]
    41  	RouteAction string `json:"route-action,omitempty"`
    42  
    43  	// BGP local preference value to be set on the matched route
    44  	SetLocalPreference int64 `json:"set-local-preference,omitempty"`
    45  }
    46  
    47  // Validate validates this bgp route policy statement
    48  func (m *BgpRoutePolicyStatement) Validate(formats strfmt.Registry) error {
    49  	var res []error
    50  
    51  	if err := m.validateMatchPrefixes(formats); err != nil {
    52  		res = append(res, err)
    53  	}
    54  
    55  	if err := m.validateRouteAction(formats); err != nil {
    56  		res = append(res, err)
    57  	}
    58  
    59  	if len(res) > 0 {
    60  		return errors.CompositeValidationError(res...)
    61  	}
    62  	return nil
    63  }
    64  
    65  func (m *BgpRoutePolicyStatement) validateMatchPrefixes(formats strfmt.Registry) error {
    66  	if swag.IsZero(m.MatchPrefixes) { // not required
    67  		return nil
    68  	}
    69  
    70  	for i := 0; i < len(m.MatchPrefixes); i++ {
    71  		if swag.IsZero(m.MatchPrefixes[i]) { // not required
    72  			continue
    73  		}
    74  
    75  		if m.MatchPrefixes[i] != nil {
    76  			if err := m.MatchPrefixes[i].Validate(formats); err != nil {
    77  				if ve, ok := err.(*errors.Validation); ok {
    78  					return ve.ValidateName("match-prefixes" + "." + strconv.Itoa(i))
    79  				} else if ce, ok := err.(*errors.CompositeError); ok {
    80  					return ce.ValidateName("match-prefixes" + "." + strconv.Itoa(i))
    81  				}
    82  				return err
    83  			}
    84  		}
    85  
    86  	}
    87  
    88  	return nil
    89  }
    90  
    91  var bgpRoutePolicyStatementTypeRouteActionPropEnum []interface{}
    92  
    93  func init() {
    94  	var res []string
    95  	if err := json.Unmarshal([]byte(`["none","accept","reject"]`), &res); err != nil {
    96  		panic(err)
    97  	}
    98  	for _, v := range res {
    99  		bgpRoutePolicyStatementTypeRouteActionPropEnum = append(bgpRoutePolicyStatementTypeRouteActionPropEnum, v)
   100  	}
   101  }
   102  
   103  const (
   104  
   105  	// BgpRoutePolicyStatementRouteActionNone captures enum value "none"
   106  	BgpRoutePolicyStatementRouteActionNone string = "none"
   107  
   108  	// BgpRoutePolicyStatementRouteActionAccept captures enum value "accept"
   109  	BgpRoutePolicyStatementRouteActionAccept string = "accept"
   110  
   111  	// BgpRoutePolicyStatementRouteActionReject captures enum value "reject"
   112  	BgpRoutePolicyStatementRouteActionReject string = "reject"
   113  )
   114  
   115  // prop value enum
   116  func (m *BgpRoutePolicyStatement) validateRouteActionEnum(path, location string, value string) error {
   117  	if err := validate.EnumCase(path, location, value, bgpRoutePolicyStatementTypeRouteActionPropEnum, true); err != nil {
   118  		return err
   119  	}
   120  	return nil
   121  }
   122  
   123  func (m *BgpRoutePolicyStatement) validateRouteAction(formats strfmt.Registry) error {
   124  	if swag.IsZero(m.RouteAction) { // not required
   125  		return nil
   126  	}
   127  
   128  	// value enum
   129  	if err := m.validateRouteActionEnum("route-action", "body", m.RouteAction); err != nil {
   130  		return err
   131  	}
   132  
   133  	return nil
   134  }
   135  
   136  // ContextValidate validate this bgp route policy statement based on the context it is used
   137  func (m *BgpRoutePolicyStatement) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   138  	var res []error
   139  
   140  	if err := m.contextValidateMatchPrefixes(ctx, formats); err != nil {
   141  		res = append(res, err)
   142  	}
   143  
   144  	if len(res) > 0 {
   145  		return errors.CompositeValidationError(res...)
   146  	}
   147  	return nil
   148  }
   149  
   150  func (m *BgpRoutePolicyStatement) contextValidateMatchPrefixes(ctx context.Context, formats strfmt.Registry) error {
   151  
   152  	for i := 0; i < len(m.MatchPrefixes); i++ {
   153  
   154  		if m.MatchPrefixes[i] != nil {
   155  
   156  			if swag.IsZero(m.MatchPrefixes[i]) { // not required
   157  				return nil
   158  			}
   159  
   160  			if err := m.MatchPrefixes[i].ContextValidate(ctx, formats); err != nil {
   161  				if ve, ok := err.(*errors.Validation); ok {
   162  					return ve.ValidateName("match-prefixes" + "." + strconv.Itoa(i))
   163  				} else if ce, ok := err.(*errors.CompositeError); ok {
   164  					return ce.ValidateName("match-prefixes" + "." + strconv.Itoa(i))
   165  				}
   166  				return err
   167  			}
   168  		}
   169  
   170  	}
   171  
   172  	return nil
   173  }
   174  
   175  // MarshalBinary interface implementation
   176  func (m *BgpRoutePolicyStatement) MarshalBinary() ([]byte, error) {
   177  	if m == nil {
   178  		return nil, nil
   179  	}
   180  	return swag.WriteJSON(m)
   181  }
   182  
   183  // UnmarshalBinary interface implementation
   184  func (m *BgpRoutePolicyStatement) UnmarshalBinary(b []byte) error {
   185  	var res BgpRoutePolicyStatement
   186  	if err := swag.ReadJSON(b, &res); err != nil {
   187  		return err
   188  	}
   189  	*m = res
   190  	return nil
   191  }