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

     1  // Code generated by protoc-gen-validate. DO NOT EDIT.
     2  // source: go.chromium.org/luci/server/quota/quotapb/policy.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 Policy with the rules defined in the
    39  // 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 *Policy) Validate() error {
    42  	return m.validate(false)
    43  }
    44  
    45  // ValidateAll checks the field values on Policy with the rules defined in the
    46  // proto definition for this message. If any rules are violated, the result is
    47  // a list of violation errors wrapped in PolicyMultiError, or nil if none found.
    48  func (m *Policy) ValidateAll() error {
    49  	return m.validate(true)
    50  }
    51  
    52  func (m *Policy) validate(all bool) error {
    53  	if m == nil {
    54  		return nil
    55  	}
    56  
    57  	var errors []error
    58  
    59  	if m.GetDefault() > 9007199254740991 {
    60  		err := PolicyValidationError{
    61  			field:  "Default",
    62  			reason: "value must be less than or equal to 9007199254740991",
    63  		}
    64  		if !all {
    65  			return err
    66  		}
    67  		errors = append(errors, err)
    68  	}
    69  
    70  	if m.GetLimit() > 9007199254740991 {
    71  		err := PolicyValidationError{
    72  			field:  "Limit",
    73  			reason: "value must be less than or equal to 9007199254740991",
    74  		}
    75  		if !all {
    76  			return err
    77  		}
    78  		errors = append(errors, err)
    79  	}
    80  
    81  	if all {
    82  		switch v := interface{}(m.GetRefill()).(type) {
    83  		case interface{ ValidateAll() error }:
    84  			if err := v.ValidateAll(); err != nil {
    85  				errors = append(errors, PolicyValidationError{
    86  					field:  "Refill",
    87  					reason: "embedded message failed validation",
    88  					cause:  err,
    89  				})
    90  			}
    91  		case interface{ Validate() error }:
    92  			if err := v.Validate(); err != nil {
    93  				errors = append(errors, PolicyValidationError{
    94  					field:  "Refill",
    95  					reason: "embedded message failed validation",
    96  					cause:  err,
    97  				})
    98  			}
    99  		}
   100  	} else if v, ok := interface{}(m.GetRefill()).(interface{ Validate() error }); ok {
   101  		if err := v.Validate(); err != nil {
   102  			return PolicyValidationError{
   103  				field:  "Refill",
   104  				reason: "embedded message failed validation",
   105  				cause:  err,
   106  			}
   107  		}
   108  	}
   109  
   110  	// no validation rules for Options
   111  
   112  	if all {
   113  		switch v := interface{}(m.GetLifetime()).(type) {
   114  		case interface{ ValidateAll() error }:
   115  			if err := v.ValidateAll(); err != nil {
   116  				errors = append(errors, PolicyValidationError{
   117  					field:  "Lifetime",
   118  					reason: "embedded message failed validation",
   119  					cause:  err,
   120  				})
   121  			}
   122  		case interface{ Validate() error }:
   123  			if err := v.Validate(); err != nil {
   124  				errors = append(errors, PolicyValidationError{
   125  					field:  "Lifetime",
   126  					reason: "embedded message failed validation",
   127  					cause:  err,
   128  				})
   129  			}
   130  		}
   131  	} else if v, ok := interface{}(m.GetLifetime()).(interface{ Validate() error }); ok {
   132  		if err := v.Validate(); err != nil {
   133  			return PolicyValidationError{
   134  				field:  "Lifetime",
   135  				reason: "embedded message failed validation",
   136  				cause:  err,
   137  			}
   138  		}
   139  	}
   140  
   141  	if len(errors) > 0 {
   142  		return PolicyMultiError(errors)
   143  	}
   144  
   145  	return nil
   146  }
   147  
   148  // PolicyMultiError is an error wrapping multiple validation errors returned by
   149  // Policy.ValidateAll() if the designated constraints aren't met.
   150  type PolicyMultiError []error
   151  
   152  // Error returns a concatenation of all the error messages it wraps.
   153  func (m PolicyMultiError) Error() string {
   154  	var msgs []string
   155  	for _, err := range m {
   156  		msgs = append(msgs, err.Error())
   157  	}
   158  	return strings.Join(msgs, "; ")
   159  }
   160  
   161  // AllErrors returns a list of validation violation errors.
   162  func (m PolicyMultiError) AllErrors() []error { return m }
   163  
   164  // PolicyValidationError is the validation error returned by Policy.Validate if
   165  // the designated constraints aren't met.
   166  type PolicyValidationError struct {
   167  	field  string
   168  	reason string
   169  	cause  error
   170  	key    bool
   171  }
   172  
   173  // Field function returns field value.
   174  func (e PolicyValidationError) Field() string { return e.field }
   175  
   176  // Reason function returns reason value.
   177  func (e PolicyValidationError) Reason() string { return e.reason }
   178  
   179  // Cause function returns cause value.
   180  func (e PolicyValidationError) Cause() error { return e.cause }
   181  
   182  // Key function returns key value.
   183  func (e PolicyValidationError) Key() bool { return e.key }
   184  
   185  // ErrorName returns error name.
   186  func (e PolicyValidationError) ErrorName() string { return "PolicyValidationError" }
   187  
   188  // Error satisfies the builtin error interface
   189  func (e PolicyValidationError) Error() string {
   190  	cause := ""
   191  	if e.cause != nil {
   192  		cause = fmt.Sprintf(" | caused by: %v", e.cause)
   193  	}
   194  
   195  	key := ""
   196  	if e.key {
   197  		key = "key for "
   198  	}
   199  
   200  	return fmt.Sprintf(
   201  		"invalid %sPolicy.%s: %s%s",
   202  		key,
   203  		e.field,
   204  		e.reason,
   205  		cause)
   206  }
   207  
   208  var _ error = PolicyValidationError{}
   209  
   210  var _ interface {
   211  	Field() string
   212  	Reason() string
   213  	Key() bool
   214  	Cause() error
   215  	ErrorName() string
   216  } = PolicyValidationError{}
   217  
   218  // Validate checks the field values on Policy_Refill with the rules defined in
   219  // the proto definition for this message. If any rules are violated, the first
   220  // error encountered is returned, or nil if there are no violations.
   221  func (m *Policy_Refill) Validate() error {
   222  	return m.validate(false)
   223  }
   224  
   225  // ValidateAll checks the field values on Policy_Refill with the rules defined
   226  // in the proto definition for this message. If any rules are violated, the
   227  // result is a list of violation errors wrapped in Policy_RefillMultiError, or
   228  // nil if none found.
   229  func (m *Policy_Refill) ValidateAll() error {
   230  	return m.validate(true)
   231  }
   232  
   233  func (m *Policy_Refill) validate(all bool) error {
   234  	if m == nil {
   235  		return nil
   236  	}
   237  
   238  	var errors []error
   239  
   240  	if val := m.GetUnits(); val < -9007199254740991 || val > 9007199254740991 {
   241  		err := Policy_RefillValidationError{
   242  			field:  "Units",
   243  			reason: "value must be inside range [-9007199254740991, 9007199254740991]",
   244  		}
   245  		if !all {
   246  			return err
   247  		}
   248  		errors = append(errors, err)
   249  	}
   250  
   251  	if _, ok := _Policy_Refill_Units_NotInLookup[m.GetUnits()]; ok {
   252  		err := Policy_RefillValidationError{
   253  			field:  "Units",
   254  			reason: "value must not be in list [0]",
   255  		}
   256  		if !all {
   257  			return err
   258  		}
   259  		errors = append(errors, err)
   260  	}
   261  
   262  	if m.GetInterval() > 86400 {
   263  		err := Policy_RefillValidationError{
   264  			field:  "Interval",
   265  			reason: "value must be less than or equal to 86400",
   266  		}
   267  		if !all {
   268  			return err
   269  		}
   270  		errors = append(errors, err)
   271  	}
   272  
   273  	if m.GetOffset() > 86400 {
   274  		err := Policy_RefillValidationError{
   275  			field:  "Offset",
   276  			reason: "value must be less than or equal to 86400",
   277  		}
   278  		if !all {
   279  			return err
   280  		}
   281  		errors = append(errors, err)
   282  	}
   283  
   284  	if len(errors) > 0 {
   285  		return Policy_RefillMultiError(errors)
   286  	}
   287  
   288  	return nil
   289  }
   290  
   291  // Policy_RefillMultiError is an error wrapping multiple validation errors
   292  // returned by Policy_Refill.ValidateAll() if the designated constraints
   293  // aren't met.
   294  type Policy_RefillMultiError []error
   295  
   296  // Error returns a concatenation of all the error messages it wraps.
   297  func (m Policy_RefillMultiError) Error() string {
   298  	var msgs []string
   299  	for _, err := range m {
   300  		msgs = append(msgs, err.Error())
   301  	}
   302  	return strings.Join(msgs, "; ")
   303  }
   304  
   305  // AllErrors returns a list of validation violation errors.
   306  func (m Policy_RefillMultiError) AllErrors() []error { return m }
   307  
   308  // Policy_RefillValidationError is the validation error returned by
   309  // Policy_Refill.Validate if the designated constraints aren't met.
   310  type Policy_RefillValidationError struct {
   311  	field  string
   312  	reason string
   313  	cause  error
   314  	key    bool
   315  }
   316  
   317  // Field function returns field value.
   318  func (e Policy_RefillValidationError) Field() string { return e.field }
   319  
   320  // Reason function returns reason value.
   321  func (e Policy_RefillValidationError) Reason() string { return e.reason }
   322  
   323  // Cause function returns cause value.
   324  func (e Policy_RefillValidationError) Cause() error { return e.cause }
   325  
   326  // Key function returns key value.
   327  func (e Policy_RefillValidationError) Key() bool { return e.key }
   328  
   329  // ErrorName returns error name.
   330  func (e Policy_RefillValidationError) ErrorName() string { return "Policy_RefillValidationError" }
   331  
   332  // Error satisfies the builtin error interface
   333  func (e Policy_RefillValidationError) Error() string {
   334  	cause := ""
   335  	if e.cause != nil {
   336  		cause = fmt.Sprintf(" | caused by: %v", e.cause)
   337  	}
   338  
   339  	key := ""
   340  	if e.key {
   341  		key = "key for "
   342  	}
   343  
   344  	return fmt.Sprintf(
   345  		"invalid %sPolicy_Refill.%s: %s%s",
   346  		key,
   347  		e.field,
   348  		e.reason,
   349  		cause)
   350  }
   351  
   352  var _ error = Policy_RefillValidationError{}
   353  
   354  var _ interface {
   355  	Field() string
   356  	Reason() string
   357  	Key() bool
   358  	Cause() error
   359  	ErrorName() string
   360  } = Policy_RefillValidationError{}
   361  
   362  var _Policy_Refill_Units_NotInLookup = map[int64]struct{}{
   363  	0: {},
   364  }