github.com/goharbor/go-client@v0.210.0/pkg/sdk/v2.0/models/immutable_rule.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  	"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  // ImmutableRule immutable rule
    19  //
    20  // swagger:model ImmutableRule
    21  type ImmutableRule struct {
    22  
    23  	// action
    24  	Action string `json:"action,omitempty"`
    25  
    26  	// disabled
    27  	Disabled bool `json:"disabled,omitempty"`
    28  
    29  	// id
    30  	ID int64 `json:"id,omitempty"`
    31  
    32  	// params
    33  	Params map[string]interface{} `json:"params,omitempty"`
    34  
    35  	// priority
    36  	Priority int64 `json:"priority,omitempty"`
    37  
    38  	// scope selectors
    39  	ScopeSelectors map[string][]ImmutableSelector `json:"scope_selectors,omitempty"`
    40  
    41  	// tag selectors
    42  	TagSelectors []*ImmutableSelector `json:"tag_selectors"`
    43  
    44  	// template
    45  	Template string `json:"template,omitempty"`
    46  }
    47  
    48  // Validate validates this immutable rule
    49  func (m *ImmutableRule) Validate(formats strfmt.Registry) error {
    50  	var res []error
    51  
    52  	if err := m.validateScopeSelectors(formats); err != nil {
    53  		res = append(res, err)
    54  	}
    55  
    56  	if err := m.validateTagSelectors(formats); err != nil {
    57  		res = append(res, err)
    58  	}
    59  
    60  	if len(res) > 0 {
    61  		return errors.CompositeValidationError(res...)
    62  	}
    63  	return nil
    64  }
    65  
    66  func (m *ImmutableRule) validateScopeSelectors(formats strfmt.Registry) error {
    67  	if swag.IsZero(m.ScopeSelectors) { // not required
    68  		return nil
    69  	}
    70  
    71  	for k := range m.ScopeSelectors {
    72  
    73  		if err := validate.Required("scope_selectors"+"."+k, "body", m.ScopeSelectors[k]); err != nil {
    74  			return err
    75  		}
    76  
    77  		for i := 0; i < len(m.ScopeSelectors[k]); i++ {
    78  
    79  			if err := m.ScopeSelectors[k][i].Validate(formats); err != nil {
    80  				if ve, ok := err.(*errors.Validation); ok {
    81  					return ve.ValidateName("scope_selectors" + "." + k + "." + strconv.Itoa(i))
    82  				} else if ce, ok := err.(*errors.CompositeError); ok {
    83  					return ce.ValidateName("scope_selectors" + "." + k + "." + strconv.Itoa(i))
    84  				}
    85  				return err
    86  			}
    87  
    88  		}
    89  
    90  	}
    91  
    92  	return nil
    93  }
    94  
    95  func (m *ImmutableRule) validateTagSelectors(formats strfmt.Registry) error {
    96  	if swag.IsZero(m.TagSelectors) { // not required
    97  		return nil
    98  	}
    99  
   100  	for i := 0; i < len(m.TagSelectors); i++ {
   101  		if swag.IsZero(m.TagSelectors[i]) { // not required
   102  			continue
   103  		}
   104  
   105  		if m.TagSelectors[i] != nil {
   106  			if err := m.TagSelectors[i].Validate(formats); err != nil {
   107  				if ve, ok := err.(*errors.Validation); ok {
   108  					return ve.ValidateName("tag_selectors" + "." + strconv.Itoa(i))
   109  				} else if ce, ok := err.(*errors.CompositeError); ok {
   110  					return ce.ValidateName("tag_selectors" + "." + strconv.Itoa(i))
   111  				}
   112  				return err
   113  			}
   114  		}
   115  
   116  	}
   117  
   118  	return nil
   119  }
   120  
   121  // ContextValidate validate this immutable rule based on the context it is used
   122  func (m *ImmutableRule) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   123  	var res []error
   124  
   125  	if err := m.contextValidateScopeSelectors(ctx, formats); err != nil {
   126  		res = append(res, err)
   127  	}
   128  
   129  	if err := m.contextValidateTagSelectors(ctx, formats); err != nil {
   130  		res = append(res, err)
   131  	}
   132  
   133  	if len(res) > 0 {
   134  		return errors.CompositeValidationError(res...)
   135  	}
   136  	return nil
   137  }
   138  
   139  func (m *ImmutableRule) contextValidateScopeSelectors(ctx context.Context, formats strfmt.Registry) error {
   140  
   141  	for k := range m.ScopeSelectors {
   142  
   143  		for i := 0; i < len(m.ScopeSelectors[k]); i++ {
   144  
   145  			if err := m.ScopeSelectors[k][i].ContextValidate(ctx, formats); err != nil {
   146  				if ve, ok := err.(*errors.Validation); ok {
   147  					return ve.ValidateName("scope_selectors" + "." + k + "." + strconv.Itoa(i))
   148  				} else if ce, ok := err.(*errors.CompositeError); ok {
   149  					return ce.ValidateName("scope_selectors" + "." + k + "." + strconv.Itoa(i))
   150  				}
   151  				return err
   152  			}
   153  
   154  		}
   155  
   156  	}
   157  
   158  	return nil
   159  }
   160  
   161  func (m *ImmutableRule) contextValidateTagSelectors(ctx context.Context, formats strfmt.Registry) error {
   162  
   163  	for i := 0; i < len(m.TagSelectors); i++ {
   164  
   165  		if m.TagSelectors[i] != nil {
   166  			if err := m.TagSelectors[i].ContextValidate(ctx, formats); err != nil {
   167  				if ve, ok := err.(*errors.Validation); ok {
   168  					return ve.ValidateName("tag_selectors" + "." + strconv.Itoa(i))
   169  				} else if ce, ok := err.(*errors.CompositeError); ok {
   170  					return ce.ValidateName("tag_selectors" + "." + strconv.Itoa(i))
   171  				}
   172  				return err
   173  			}
   174  		}
   175  
   176  	}
   177  
   178  	return nil
   179  }
   180  
   181  // MarshalBinary interface implementation
   182  func (m *ImmutableRule) MarshalBinary() ([]byte, error) {
   183  	if m == nil {
   184  		return nil, nil
   185  	}
   186  	return swag.WriteJSON(m)
   187  }
   188  
   189  // UnmarshalBinary interface implementation
   190  func (m *ImmutableRule) UnmarshalBinary(b []byte) error {
   191  	var res ImmutableRule
   192  	if err := swag.ReadJSON(b, &res); err != nil {
   193  		return err
   194  	}
   195  	*m = res
   196  	return nil
   197  }