go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/server/quota/quotapb/policy_config.pb.validate.go (about)

     1  // Code generated by protoc-gen-validate. DO NOT EDIT.
     2  // source: go.chromium.org/luci/server/quota/quotapb/policy_config.proto
     3  
     4  package quotapb
     5  
     6  import (
     7  	"bytes"
     8  	"errors"
     9  	"fmt"
    10  	"net"
    11  	"net/mail"
    12  	"net/url"
    13  	"regexp"
    14  	"sort"
    15  	"strings"
    16  	"time"
    17  	"unicode/utf8"
    18  
    19  	"google.golang.org/protobuf/types/known/anypb"
    20  )
    21  
    22  // ensure the imports are used
    23  var (
    24  	_ = bytes.MinRead
    25  	_ = errors.New("")
    26  	_ = fmt.Print
    27  	_ = utf8.UTFMax
    28  	_ = (*regexp.Regexp)(nil)
    29  	_ = (*strings.Reader)(nil)
    30  	_ = net.IPv4len
    31  	_ = time.Duration(0)
    32  	_ = (*url.URL)(nil)
    33  	_ = (*mail.Address)(nil)
    34  	_ = anypb.Any{}
    35  	_ = sort.Sort
    36  )
    37  
    38  // Validate checks the field values on PolicyConfig with the rules defined in
    39  // the proto definition for this message. If any rules are violated, the first
    40  // error encountered is returned, or nil if there are no violations.
    41  func (m *PolicyConfig) Validate() error {
    42  	return m.validate(false)
    43  }
    44  
    45  // ValidateAll checks the field values on PolicyConfig with the rules defined
    46  // in the proto definition for this message. If any rules are violated, the
    47  // result is a list of violation errors wrapped in PolicyConfigMultiError, or
    48  // nil if none found.
    49  func (m *PolicyConfig) ValidateAll() error {
    50  	return m.validate(true)
    51  }
    52  
    53  func (m *PolicyConfig) validate(all bool) error {
    54  	if m == nil {
    55  		return nil
    56  	}
    57  
    58  	var errors []error
    59  
    60  	for idx, item := range m.GetPolicies() {
    61  		_, _ = idx, item
    62  
    63  		if all {
    64  			switch v := interface{}(item).(type) {
    65  			case interface{ ValidateAll() error }:
    66  				if err := v.ValidateAll(); err != nil {
    67  					errors = append(errors, PolicyConfigValidationError{
    68  						field:  fmt.Sprintf("Policies[%v]", idx),
    69  						reason: "embedded message failed validation",
    70  						cause:  err,
    71  					})
    72  				}
    73  			case interface{ Validate() error }:
    74  				if err := v.Validate(); err != nil {
    75  					errors = append(errors, PolicyConfigValidationError{
    76  						field:  fmt.Sprintf("Policies[%v]", idx),
    77  						reason: "embedded message failed validation",
    78  						cause:  err,
    79  					})
    80  				}
    81  			}
    82  		} else if v, ok := interface{}(item).(interface{ Validate() error }); ok {
    83  			if err := v.Validate(); err != nil {
    84  				return PolicyConfigValidationError{
    85  					field:  fmt.Sprintf("Policies[%v]", idx),
    86  					reason: "embedded message failed validation",
    87  					cause:  err,
    88  				}
    89  			}
    90  		}
    91  
    92  	}
    93  
    94  	if len(errors) > 0 {
    95  		return PolicyConfigMultiError(errors)
    96  	}
    97  
    98  	return nil
    99  }
   100  
   101  // PolicyConfigMultiError is an error wrapping multiple validation errors
   102  // returned by PolicyConfig.ValidateAll() if the designated constraints aren't met.
   103  type PolicyConfigMultiError []error
   104  
   105  // Error returns a concatenation of all the error messages it wraps.
   106  func (m PolicyConfigMultiError) Error() string {
   107  	var msgs []string
   108  	for _, err := range m {
   109  		msgs = append(msgs, err.Error())
   110  	}
   111  	return strings.Join(msgs, "; ")
   112  }
   113  
   114  // AllErrors returns a list of validation violation errors.
   115  func (m PolicyConfigMultiError) AllErrors() []error { return m }
   116  
   117  // PolicyConfigValidationError is the validation error returned by
   118  // PolicyConfig.Validate if the designated constraints aren't met.
   119  type PolicyConfigValidationError struct {
   120  	field  string
   121  	reason string
   122  	cause  error
   123  	key    bool
   124  }
   125  
   126  // Field function returns field value.
   127  func (e PolicyConfigValidationError) Field() string { return e.field }
   128  
   129  // Reason function returns reason value.
   130  func (e PolicyConfigValidationError) Reason() string { return e.reason }
   131  
   132  // Cause function returns cause value.
   133  func (e PolicyConfigValidationError) Cause() error { return e.cause }
   134  
   135  // Key function returns key value.
   136  func (e PolicyConfigValidationError) Key() bool { return e.key }
   137  
   138  // ErrorName returns error name.
   139  func (e PolicyConfigValidationError) ErrorName() string { return "PolicyConfigValidationError" }
   140  
   141  // Error satisfies the builtin error interface
   142  func (e PolicyConfigValidationError) Error() string {
   143  	cause := ""
   144  	if e.cause != nil {
   145  		cause = fmt.Sprintf(" | caused by: %v", e.cause)
   146  	}
   147  
   148  	key := ""
   149  	if e.key {
   150  		key = "key for "
   151  	}
   152  
   153  	return fmt.Sprintf(
   154  		"invalid %sPolicyConfig.%s: %s%s",
   155  		key,
   156  		e.field,
   157  		e.reason,
   158  		cause)
   159  }
   160  
   161  var _ error = PolicyConfigValidationError{}
   162  
   163  var _ interface {
   164  	Field() string
   165  	Reason() string
   166  	Key() bool
   167  	Cause() error
   168  	ErrorName() string
   169  } = PolicyConfigValidationError{}
   170  
   171  // Validate checks the field values on PolicyConfig_Entry with the rules
   172  // defined in the proto definition for this message. If any rules are
   173  // violated, the first error encountered is returned, or nil if there are no violations.
   174  func (m *PolicyConfig_Entry) Validate() error {
   175  	return m.validate(false)
   176  }
   177  
   178  // ValidateAll checks the field values on PolicyConfig_Entry with the rules
   179  // defined in the proto definition for this message. If any rules are
   180  // violated, the result is a list of violation errors wrapped in
   181  // PolicyConfig_EntryMultiError, or nil if none found.
   182  func (m *PolicyConfig_Entry) ValidateAll() error {
   183  	return m.validate(true)
   184  }
   185  
   186  func (m *PolicyConfig_Entry) validate(all bool) error {
   187  	if m == nil {
   188  		return nil
   189  	}
   190  
   191  	var errors []error
   192  
   193  	if all {
   194  		switch v := interface{}(m.GetKey()).(type) {
   195  		case interface{ ValidateAll() error }:
   196  			if err := v.ValidateAll(); err != nil {
   197  				errors = append(errors, PolicyConfig_EntryValidationError{
   198  					field:  "Key",
   199  					reason: "embedded message failed validation",
   200  					cause:  err,
   201  				})
   202  			}
   203  		case interface{ Validate() error }:
   204  			if err := v.Validate(); err != nil {
   205  				errors = append(errors, PolicyConfig_EntryValidationError{
   206  					field:  "Key",
   207  					reason: "embedded message failed validation",
   208  					cause:  err,
   209  				})
   210  			}
   211  		}
   212  	} else if v, ok := interface{}(m.GetKey()).(interface{ Validate() error }); ok {
   213  		if err := v.Validate(); err != nil {
   214  			return PolicyConfig_EntryValidationError{
   215  				field:  "Key",
   216  				reason: "embedded message failed validation",
   217  				cause:  err,
   218  			}
   219  		}
   220  	}
   221  
   222  	if all {
   223  		switch v := interface{}(m.GetPolicy()).(type) {
   224  		case interface{ ValidateAll() error }:
   225  			if err := v.ValidateAll(); err != nil {
   226  				errors = append(errors, PolicyConfig_EntryValidationError{
   227  					field:  "Policy",
   228  					reason: "embedded message failed validation",
   229  					cause:  err,
   230  				})
   231  			}
   232  		case interface{ Validate() error }:
   233  			if err := v.Validate(); err != nil {
   234  				errors = append(errors, PolicyConfig_EntryValidationError{
   235  					field:  "Policy",
   236  					reason: "embedded message failed validation",
   237  					cause:  err,
   238  				})
   239  			}
   240  		}
   241  	} else if v, ok := interface{}(m.GetPolicy()).(interface{ Validate() error }); ok {
   242  		if err := v.Validate(); err != nil {
   243  			return PolicyConfig_EntryValidationError{
   244  				field:  "Policy",
   245  				reason: "embedded message failed validation",
   246  				cause:  err,
   247  			}
   248  		}
   249  	}
   250  
   251  	if len(errors) > 0 {
   252  		return PolicyConfig_EntryMultiError(errors)
   253  	}
   254  
   255  	return nil
   256  }
   257  
   258  // PolicyConfig_EntryMultiError is an error wrapping multiple validation errors
   259  // returned by PolicyConfig_Entry.ValidateAll() if the designated constraints
   260  // aren't met.
   261  type PolicyConfig_EntryMultiError []error
   262  
   263  // Error returns a concatenation of all the error messages it wraps.
   264  func (m PolicyConfig_EntryMultiError) Error() string {
   265  	var msgs []string
   266  	for _, err := range m {
   267  		msgs = append(msgs, err.Error())
   268  	}
   269  	return strings.Join(msgs, "; ")
   270  }
   271  
   272  // AllErrors returns a list of validation violation errors.
   273  func (m PolicyConfig_EntryMultiError) AllErrors() []error { return m }
   274  
   275  // PolicyConfig_EntryValidationError is the validation error returned by
   276  // PolicyConfig_Entry.Validate if the designated constraints aren't met.
   277  type PolicyConfig_EntryValidationError struct {
   278  	field  string
   279  	reason string
   280  	cause  error
   281  	key    bool
   282  }
   283  
   284  // Field function returns field value.
   285  func (e PolicyConfig_EntryValidationError) Field() string { return e.field }
   286  
   287  // Reason function returns reason value.
   288  func (e PolicyConfig_EntryValidationError) Reason() string { return e.reason }
   289  
   290  // Cause function returns cause value.
   291  func (e PolicyConfig_EntryValidationError) Cause() error { return e.cause }
   292  
   293  // Key function returns key value.
   294  func (e PolicyConfig_EntryValidationError) Key() bool { return e.key }
   295  
   296  // ErrorName returns error name.
   297  func (e PolicyConfig_EntryValidationError) ErrorName() string {
   298  	return "PolicyConfig_EntryValidationError"
   299  }
   300  
   301  // Error satisfies the builtin error interface
   302  func (e PolicyConfig_EntryValidationError) Error() string {
   303  	cause := ""
   304  	if e.cause != nil {
   305  		cause = fmt.Sprintf(" | caused by: %v", e.cause)
   306  	}
   307  
   308  	key := ""
   309  	if e.key {
   310  		key = "key for "
   311  	}
   312  
   313  	return fmt.Sprintf(
   314  		"invalid %sPolicyConfig_Entry.%s: %s%s",
   315  		key,
   316  		e.field,
   317  		e.reason,
   318  		cause)
   319  }
   320  
   321  var _ error = PolicyConfig_EntryValidationError{}
   322  
   323  var _ interface {
   324  	Field() string
   325  	Reason() string
   326  	Key() bool
   327  	Cause() error
   328  	ErrorName() string
   329  } = PolicyConfig_EntryValidationError{}