github.com/cilium/cilium@v1.16.2/api/v1/models/selector_identity_mapping.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  
    14  	"github.com/go-openapi/errors"
    15  	"github.com/go-openapi/strfmt"
    16  	"github.com/go-openapi/swag"
    17  )
    18  
    19  // SelectorIdentityMapping mapping of selector to identities which match it
    20  //
    21  // swagger:model SelectorIdentityMapping
    22  type SelectorIdentityMapping struct {
    23  
    24  	// identities mapping to this selector
    25  	Identities []int64 `json:"identities"`
    26  
    27  	// Labels are the metadata labels associated with the selector
    28  	Labels LabelArray `json:"labels,omitempty"`
    29  
    30  	// string form of selector
    31  	Selector string `json:"selector,omitempty"`
    32  
    33  	// number of users of this selector in the cache
    34  	Users int64 `json:"users,omitempty"`
    35  }
    36  
    37  // Validate validates this selector identity mapping
    38  func (m *SelectorIdentityMapping) Validate(formats strfmt.Registry) error {
    39  	var res []error
    40  
    41  	if err := m.validateLabels(formats); err != nil {
    42  		res = append(res, err)
    43  	}
    44  
    45  	if len(res) > 0 {
    46  		return errors.CompositeValidationError(res...)
    47  	}
    48  	return nil
    49  }
    50  
    51  func (m *SelectorIdentityMapping) validateLabels(formats strfmt.Registry) error {
    52  	if swag.IsZero(m.Labels) { // not required
    53  		return nil
    54  	}
    55  
    56  	if err := m.Labels.Validate(formats); err != nil {
    57  		if ve, ok := err.(*errors.Validation); ok {
    58  			return ve.ValidateName("labels")
    59  		} else if ce, ok := err.(*errors.CompositeError); ok {
    60  			return ce.ValidateName("labels")
    61  		}
    62  		return err
    63  	}
    64  
    65  	return nil
    66  }
    67  
    68  // ContextValidate validate this selector identity mapping based on the context it is used
    69  func (m *SelectorIdentityMapping) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
    70  	var res []error
    71  
    72  	if err := m.contextValidateLabels(ctx, formats); err != nil {
    73  		res = append(res, err)
    74  	}
    75  
    76  	if len(res) > 0 {
    77  		return errors.CompositeValidationError(res...)
    78  	}
    79  	return nil
    80  }
    81  
    82  func (m *SelectorIdentityMapping) contextValidateLabels(ctx context.Context, formats strfmt.Registry) error {
    83  
    84  	if err := m.Labels.ContextValidate(ctx, formats); err != nil {
    85  		if ve, ok := err.(*errors.Validation); ok {
    86  			return ve.ValidateName("labels")
    87  		} else if ce, ok := err.(*errors.CompositeError); ok {
    88  			return ce.ValidateName("labels")
    89  		}
    90  		return err
    91  	}
    92  
    93  	return nil
    94  }
    95  
    96  // MarshalBinary interface implementation
    97  func (m *SelectorIdentityMapping) 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 *SelectorIdentityMapping) UnmarshalBinary(b []byte) error {
   106  	var res SelectorIdentityMapping
   107  	if err := swag.ReadJSON(b, &res); err != nil {
   108  		return err
   109  	}
   110  	*m = res
   111  	return nil
   112  }