github.com/cloudwan/edgelq-sdk@v1.15.4/logging/resources/v1alpha2/log/log.pb.filter.go (about)

     1  // Code generated by protoc-gen-goten-resource
     2  // Resource: Log
     3  // DO NOT EDIT!!!
     4  
     5  package log
     6  
     7  import (
     8  	"fmt"
     9  	"math"
    10  	"strings"
    11  
    12  	"google.golang.org/grpc/codes"
    13  	"google.golang.org/grpc/status"
    14  	"google.golang.org/protobuf/proto"
    15  
    16  	gotenobject "github.com/cloudwan/goten-sdk/runtime/object"
    17  	gotenresource "github.com/cloudwan/goten-sdk/runtime/resource"
    18  	filterParser "github.com/cloudwan/goten-sdk/runtime/resource/filter"
    19  	utils "github.com/cloudwan/goten-sdk/runtime/utils"
    20  )
    21  
    22  // proto imports
    23  import (
    24  	iam_organization "github.com/cloudwan/edgelq-sdk/iam/resources/v1alpha2/organization"
    25  	iam_project "github.com/cloudwan/edgelq-sdk/iam/resources/v1alpha2/project"
    26  	log_descriptor "github.com/cloudwan/edgelq-sdk/logging/resources/v1alpha2/log_descriptor"
    27  	meta "github.com/cloudwan/goten-sdk/types/meta"
    28  	structpb "google.golang.org/protobuf/types/known/structpb"
    29  	timestamppb "google.golang.org/protobuf/types/known/timestamppb"
    30  )
    31  
    32  var (
    33  	_ = new(fmt.Stringer)
    34  	_ = strings.Builder{}
    35  	_ = math.IsNaN
    36  
    37  	_ = new(proto.Message)
    38  
    39  	_ = new(gotenobject.FieldPath)
    40  	_ = gotenresource.WildcardId
    41  )
    42  
    43  // make sure we're using proto imports
    44  var (
    45  	_ = &iam_organization.Organization{}
    46  	_ = &iam_project.Project{}
    47  	_ = &log_descriptor.LogDescriptor{}
    48  	_ = &structpb.Struct{}
    49  	_ = &timestamppb.Timestamp{}
    50  	_ = &meta.Meta{}
    51  )
    52  
    53  type FilterCondition interface {
    54  	gotenresource.FilterCondition
    55  	_IsFilterCondition()
    56  	_IsLogFilterBuilderOrCondition()
    57  	And(...FilterCondition) FilterCondition
    58  	Evaluate(res *Log) bool
    59  
    60  	// Whether this condition is at least as specific as other.
    61  	// When true, any Log that passes this condition will also pass other condition.
    62  	Satisfies(other FilterCondition) bool
    63  
    64  	// Checks whether condition specifies given field path
    65  	// Useful for blacklisting protected paths in iam policy conditions
    66  	SpecifiesFieldPath(fp Log_FieldPath) bool
    67  }
    68  
    69  func AndFilterConditions(conds ...FilterCondition) FilterCondition {
    70  	result := &FilterConditionComposite{
    71  		Operator: filterParser.AND,
    72  	}
    73  	for _, condi := range conds {
    74  		switch cond := condi.(type) {
    75  		case *FilterConditionComposite:
    76  			if cond.Operator == filterParser.AND {
    77  				result.Conditions = append(result.Conditions, cond.Conditions...)
    78  				continue
    79  			}
    80  		default:
    81  		}
    82  		result.Conditions = append(result.Conditions, condi)
    83  	}
    84  	return result
    85  }
    86  
    87  type FilterConditionComposite struct {
    88  	Operator   filterParser.CompositeOperator
    89  	Conditions []FilterCondition
    90  }
    91  
    92  func (cond *FilterConditionComposite) String() string {
    93  	substrs := make([]string, 0, len(cond.Conditions))
    94  	for _, subcond := range cond.Conditions {
    95  		substrs = append(substrs, subcond.String())
    96  	}
    97  	sep := fmt.Sprintf(" %s ", cond.Operator)
    98  	return "(" + strings.Join(substrs, sep) + ")"
    99  }
   100  
   101  func (cond *FilterConditionComposite) _IsFilterCondition() {}
   102  
   103  func (cond *FilterConditionComposite) _IsLogFilterBuilderOrCondition() {}
   104  
   105  func (cond *FilterConditionComposite) And(conds ...FilterCondition) FilterCondition {
   106  	return AndFilterConditions(append([]FilterCondition{cond}, conds...)...)
   107  }
   108  
   109  func (cond *FilterConditionComposite) Evaluate(res *Log) bool {
   110  	switch cond.Operator {
   111  	case filterParser.OR:
   112  		for _, subCond := range cond.Conditions {
   113  			if subCond.Evaluate(res) {
   114  				return true
   115  			}
   116  		}
   117  		return false
   118  	case filterParser.AND:
   119  		for _, subCond := range cond.Conditions {
   120  			if !subCond.Evaluate(res) {
   121  				return false
   122  			}
   123  		}
   124  		return true
   125  	default:
   126  		panic(fmt.Sprintf("Unsupported composite condition operator: %s", cond.Operator))
   127  	}
   128  }
   129  
   130  func (cond *FilterConditionComposite) EvaluateRaw(res gotenresource.Resource) bool {
   131  	if typedRes, ok := res.(*Log); !ok {
   132  		return false
   133  	} else {
   134  		return cond.Evaluate(typedRes)
   135  	}
   136  }
   137  
   138  func (cond *FilterConditionComposite) flattenConditions() (results []FilterCondition) {
   139  	for _, subcnd := range cond.Conditions {
   140  		switch tsubcnd := subcnd.(type) {
   141  		case *FilterConditionComposite:
   142  			if tsubcnd.Operator == cond.Operator {
   143  				results = append(results, tsubcnd.flattenConditions()...)
   144  			} else {
   145  				results = append(results, subcnd) // take it as it is
   146  			}
   147  		default:
   148  			results = append(results, subcnd)
   149  		}
   150  	}
   151  	return
   152  }
   153  
   154  func (cond *FilterConditionComposite) Satisfies(other FilterCondition) bool {
   155  	flattened := cond.flattenConditions()
   156  	switch cond.Operator {
   157  	case filterParser.AND:
   158  		switch tother := other.(type) {
   159  		case *FilterConditionComposite:
   160  			switch tother.Operator {
   161  			case filterParser.AND:
   162  				otherFlattened := tother.flattenConditions()
   163  			OtherSubcnds:
   164  				for _, otherSubcnd := range otherFlattened {
   165  					for _, subcnd := range flattened {
   166  						if subcnd.Satisfies(otherSubcnd) {
   167  							continue OtherSubcnds
   168  						}
   169  					}
   170  					return false
   171  				}
   172  				return true
   173  			case filterParser.OR:
   174  				otherFlattened := tother.flattenConditions()
   175  				for _, otherSubcnd := range otherFlattened {
   176  					if cond.Satisfies(otherSubcnd) {
   177  						return true
   178  					}
   179  				}
   180  				return false
   181  			default:
   182  				return false
   183  			}
   184  		default:
   185  			for _, subcnd := range flattened {
   186  				if subcnd.Satisfies(other) {
   187  					return true
   188  				}
   189  			}
   190  			return false
   191  		}
   192  	default:
   193  		panic(fmt.Errorf("unsupported condition type %s", cond.Operator))
   194  	}
   195  	return false
   196  }
   197  
   198  func (cond *FilterConditionComposite) SatisfiesRaw(other gotenresource.FilterCondition) bool {
   199  	if typedCond, ok := other.(FilterCondition); !ok {
   200  		return false
   201  	} else {
   202  		return cond.Satisfies(typedCond)
   203  	}
   204  }
   205  
   206  func (cond *FilterConditionComposite) SpecifiesFieldPath(fp Log_FieldPath) bool {
   207  	for _, subcnd := range cond.Conditions {
   208  		if subcnd.SpecifiesFieldPath(fp) {
   209  			return true
   210  		}
   211  	}
   212  	return false
   213  }
   214  
   215  func (cond *FilterConditionComposite) SpecifiesRawFieldPath(fp gotenobject.FieldPath) bool {
   216  	if typedFp, ok := fp.(Log_FieldPath); !ok {
   217  		return false
   218  	} else {
   219  		return cond.SpecifiesFieldPath(typedFp)
   220  	}
   221  }
   222  
   223  func (cond *FilterConditionComposite) GetOperator() filterParser.CompositeOperator {
   224  	return cond.Operator
   225  }
   226  
   227  func (cond *FilterConditionComposite) GetSubConditions() []gotenresource.FilterCondition {
   228  	subConds := make([]gotenresource.FilterCondition, len(cond.Conditions))
   229  	for idx, subCond := range cond.Conditions {
   230  		subConds[idx] = subCond
   231  	}
   232  	return subConds
   233  }
   234  
   235  func (cond *FilterConditionComposite) ConditionComposite() {}
   236  
   237  type FilterConditionNot struct {
   238  	FilterCondition
   239  }
   240  
   241  func (cond *FilterConditionNot) String() string {
   242  	return "NOT " + cond.FilterCondition.String()
   243  }
   244  
   245  func (cond *FilterConditionNot) _IsFilterCondition() {}
   246  
   247  func (cond *FilterConditionNot) _IsLogFilterBuilderOrCondition() {}
   248  
   249  func (cond *FilterConditionNot) And(conds ...FilterCondition) FilterCondition {
   250  	return AndFilterConditions(append([]FilterCondition{cond}, conds...)...)
   251  }
   252  
   253  func (cond *FilterConditionNot) Evaluate(res *Log) bool {
   254  	return !cond.FilterCondition.Evaluate(res)
   255  }
   256  
   257  func (cond *FilterConditionNot) EvaluateRaw(res gotenresource.Resource) bool {
   258  	if typedRes, ok := res.(*Log); !ok {
   259  		return false
   260  	} else {
   261  		return cond.Evaluate(typedRes)
   262  	}
   263  }
   264  
   265  func (cond *FilterConditionNot) Satisfies(other FilterCondition) bool {
   266  	switch tother := other.(type) {
   267  	case *FilterConditionNot:
   268  		return cond.FilterCondition.Satisfies(tother.FilterCondition)
   269  	default:
   270  		return !cond.FilterCondition.Satisfies(other)
   271  	}
   272  }
   273  
   274  func (cond *FilterConditionNot) SatisfiesRaw(other gotenresource.FilterCondition) bool {
   275  	if typedCond, ok := other.(FilterCondition); !ok {
   276  		return false
   277  	} else {
   278  		return cond.Satisfies(typedCond)
   279  	}
   280  }
   281  
   282  func (cond *FilterConditionNot) SpecifiesFieldPath(fp Log_FieldPath) bool {
   283  	return cond.FilterCondition.SpecifiesFieldPath(fp)
   284  }
   285  
   286  func (cond *FilterConditionNot) SpecifiesRawFieldPath(fp gotenobject.FieldPath) bool {
   287  	if typedFp, ok := fp.(Log_FieldPath); !ok {
   288  		return false
   289  	} else {
   290  		return cond.SpecifiesFieldPath(typedFp)
   291  	}
   292  }
   293  
   294  func (cond *FilterConditionNot) GetSubCondition() gotenresource.FilterCondition {
   295  	return cond.FilterCondition
   296  }
   297  
   298  func (cond *FilterConditionNot) ConditionNot() {}
   299  
   300  type FilterConditionIsNull struct {
   301  	Not       bool
   302  	FieldPath Log_FieldPath
   303  }
   304  
   305  func (cond *FilterConditionIsNull) String() string {
   306  	if cond.Not {
   307  		return cond.FieldPath.String() + " IS NOT NULL"
   308  	} else {
   309  		return cond.FieldPath.String() + " IS NULL"
   310  	}
   311  }
   312  
   313  func (cond *FilterConditionIsNull) _IsFilterCondition() {}
   314  
   315  func (cond *FilterConditionIsNull) _IsLogFilterBuilderOrCondition() {}
   316  
   317  func (cond *FilterConditionIsNull) And(conds ...FilterCondition) FilterCondition {
   318  	return AndFilterConditions(append([]FilterCondition{cond}, conds...)...)
   319  }
   320  
   321  func (cond *FilterConditionIsNull) Evaluate(res *Log) bool {
   322  	if v, ok := cond.FieldPath.GetSingleRaw(res); !ok {
   323  		return !cond.Not
   324  	} else {
   325  		return cond.Not != utils.IsNil(v)
   326  	}
   327  }
   328  
   329  func (cond *FilterConditionIsNull) EvaluateRaw(res gotenresource.Resource) bool {
   330  	if typedRes, ok := res.(*Log); !ok {
   331  		return false
   332  	} else {
   333  		return cond.Evaluate(typedRes)
   334  	}
   335  }
   336  
   337  func (cond *FilterConditionIsNull) asCompare() FilterCondition {
   338  	res := &FilterConditionCompare{
   339  		Operator:           filterParser.Eq,
   340  		Log_FieldPathValue: cond.FieldPath.WithIValue(nil),
   341  	}
   342  	if cond.Not {
   343  		res.Operator = filterParser.Neq
   344  	}
   345  	return res
   346  }
   347  
   348  func (cond *FilterConditionIsNull) Satisfies(other FilterCondition) bool {
   349  	switch tother := other.(type) {
   350  	case *FilterConditionIsNull:
   351  		return cond.FieldPath.String() == tother.FieldPath.String() && cond.Not == tother.Not
   352  	case *FilterConditionCompare:
   353  		return cond.asCompare().Satisfies(tother)
   354  	default:
   355  		return false
   356  	}
   357  }
   358  
   359  func (cond *FilterConditionIsNull) SatisfiesRaw(other gotenresource.FilterCondition) bool {
   360  	if typedCond, ok := other.(FilterCondition); !ok {
   361  		return false
   362  	} else {
   363  		return cond.Satisfies(typedCond)
   364  	}
   365  }
   366  
   367  func (cond *FilterConditionIsNull) SpecifiesFieldPath(fp Log_FieldPath) bool {
   368  	return cond.FieldPath.String() == fp.String()
   369  }
   370  
   371  func (cond *FilterConditionIsNull) SpecifiesRawFieldPath(fp gotenobject.FieldPath) bool {
   372  	if typedFp, ok := fp.(Log_FieldPath); !ok {
   373  		return false
   374  	} else {
   375  		return cond.SpecifiesFieldPath(typedFp)
   376  	}
   377  }
   378  
   379  func (cond *FilterConditionIsNull) NotNull() bool {
   380  	return cond.Not
   381  }
   382  
   383  func (cond *FilterConditionIsNull) GetRawFieldPath() gotenobject.FieldPath {
   384  	return cond.FieldPath
   385  }
   386  
   387  func (cond *FilterConditionIsNull) ConditionIsNull() {}
   388  
   389  type FilterConditionIsNaN struct {
   390  	Not       bool
   391  	FieldPath Log_FieldPath
   392  }
   393  
   394  func (cond *FilterConditionIsNaN) String() string {
   395  	if cond.Not {
   396  		return cond.FieldPath.String() + " IS NOT NaN"
   397  	} else {
   398  		return cond.FieldPath.String() + " IS NaN"
   399  	}
   400  }
   401  
   402  func (cond *FilterConditionIsNaN) _IsFilterCondition() {}
   403  
   404  func (cond *FilterConditionIsNaN) _IsLogFilterBuilderOrCondition() {}
   405  
   406  func (cond *FilterConditionIsNaN) And(conds ...FilterCondition) FilterCondition {
   407  	return AndFilterConditions(append([]FilterCondition{cond}, conds...)...)
   408  }
   409  
   410  func (cond *FilterConditionIsNaN) Evaluate(res *Log) bool {
   411  	v, ok := cond.FieldPath.GetSingleRaw(res)
   412  	if !ok {
   413  		return false
   414  	}
   415  	fv, ok := v.(float64)
   416  	if !ok {
   417  		return false
   418  	}
   419  	return math.IsNaN(fv)
   420  }
   421  
   422  func (cond *FilterConditionIsNaN) EvaluateRaw(res gotenresource.Resource) bool {
   423  	if typedRes, ok := res.(*Log); !ok {
   424  		return false
   425  	} else {
   426  		return cond.Evaluate(typedRes)
   427  	}
   428  }
   429  
   430  func (cond *FilterConditionIsNaN) Satisfies(other FilterCondition) bool {
   431  	switch tother := other.(type) {
   432  	case *FilterConditionIsNaN:
   433  		return cond.FieldPath.String() == tother.FieldPath.String() && cond.Not == tother.Not
   434  	default:
   435  		return false
   436  	}
   437  }
   438  
   439  func (cond *FilterConditionIsNaN) SatisfiesRaw(other gotenresource.FilterCondition) bool {
   440  	if typedCond, ok := other.(FilterCondition); !ok {
   441  		return false
   442  	} else {
   443  		return cond.Satisfies(typedCond)
   444  	}
   445  }
   446  
   447  func (cond *FilterConditionIsNaN) SpecifiesFieldPath(fp Log_FieldPath) bool {
   448  	return cond.FieldPath.String() == fp.String()
   449  }
   450  
   451  func (cond *FilterConditionIsNaN) SpecifiesRawFieldPath(fp gotenobject.FieldPath) bool {
   452  	if typedFp, ok := fp.(Log_FieldPath); !ok {
   453  		return false
   454  	} else {
   455  		return cond.SpecifiesFieldPath(typedFp)
   456  	}
   457  }
   458  
   459  func (cond *FilterConditionIsNaN) GetRawFieldPath() gotenobject.FieldPath {
   460  	return cond.FieldPath
   461  }
   462  
   463  func (cond *FilterConditionIsNaN) ConditionIsNaN() {}
   464  
   465  type FilterConditionCompare struct {
   466  	Operator filterParser.CompareOperator
   467  	Log_FieldPathValue
   468  }
   469  
   470  func (cond *FilterConditionCompare) String() string {
   471  	jsonValue, err := utils.JsonMarshal(cond.Log_FieldPathValue.GetRawValue())
   472  	if err != nil {
   473  		panic(err)
   474  	}
   475  	return fmt.Sprintf("%s %s %s", cond.Log_FieldPathValue, cond.Operator, jsonValue)
   476  }
   477  
   478  func (cond *FilterConditionCompare) _IsFilterCondition() {}
   479  
   480  func (cond *FilterConditionCompare) _IsLogFilterBuilderOrCondition() {}
   481  
   482  func (cond *FilterConditionCompare) And(conds ...FilterCondition) FilterCondition {
   483  	return AndFilterConditions(append([]FilterCondition{cond}, conds...)...)
   484  }
   485  
   486  func (cond *FilterConditionCompare) Evaluate(res *Log) bool {
   487  	// Special evaluation for name or reference - may include wildcards
   488  	if nameOrRefFPV, ok := cond.Log_FieldPathValue.GetRawValue().(gotenresource.Name); ok {
   489  		if otherObj, ok := cond.Log_FieldPathValue.GetSingleRaw(res); ok {
   490  			match := nameOrRefFPV.Matches(otherObj)
   491  			switch cond.Operator {
   492  			case filterParser.Eq:
   493  				return match
   494  			case filterParser.Neq:
   495  				return !match
   496  			default:
   497  				return false
   498  			}
   499  		}
   500  	}
   501  	// special evaluation for objects
   502  	if objValue, ok := cond.Log_FieldPathValue.GetRawValue().(proto.Message); ok {
   503  		if otherObj, ok := cond.Log_FieldPathValue.GetSingleRaw(res); ok {
   504  			switch cond.Operator {
   505  			case filterParser.Eq:
   506  				return proto.Equal(objValue, otherObj.(proto.Message))
   507  			case filterParser.Neq:
   508  				return !proto.Equal(objValue, otherObj.(proto.Message))
   509  			default:
   510  				return false
   511  			}
   512  		}
   513  	}
   514  	cmpResult, comparable := cond.Log_FieldPathValue.CompareWith(res)
   515  	if !comparable {
   516  		return false
   517  	}
   518  	return cond.Operator.MatchCompareResult(cmpResult)
   519  }
   520  
   521  func (cond *FilterConditionCompare) EvaluateRaw(res gotenresource.Resource) bool {
   522  	if typedRes, ok := res.(*Log); !ok {
   523  		return false
   524  	} else {
   525  		return cond.Evaluate(typedRes)
   526  	}
   527  }
   528  
   529  func (cond *FilterConditionCompare) Satisfies(other FilterCondition) bool {
   530  	switch tother := other.(type) {
   531  	case *FilterConditionCompare:
   532  		if cond.Log_FieldPathValue.String() != tother.Log_FieldPathValue.String() {
   533  			return false
   534  		}
   535  		othertmp := new(Log)
   536  		tother.SetTo(&othertmp)
   537  		if cmp, comparable := cond.CompareWith(othertmp); !comparable {
   538  			return false
   539  		} else {
   540  			return filterParser.CompareSatisfies(tother.Operator, cond.Operator, cmp)
   541  		}
   542  	case *FilterConditionIn:
   543  		if cond.Operator != filterParser.Eq {
   544  			return false
   545  		}
   546  		if cond.Log_FieldPathValue.String() != tother.Log_FieldPathArrayOfValues.String() {
   547  			return false
   548  		}
   549  		for _, inv := range tother.GetRawValues() {
   550  			othertmp := new(Log)
   551  			tother.WithIValue(inv).SetTo(&othertmp)
   552  			if cmp, comparable := cond.Log_FieldPathValue.CompareWith(othertmp); comparable && cmp == 0 {
   553  				return true
   554  			}
   555  		}
   556  		return false
   557  	case *FilterConditionComposite:
   558  		if tother.Operator == filterParser.AND {
   559  			for _, othersubcnd := range tother.flattenConditions() {
   560  				if !cond.Satisfies(othersubcnd) {
   561  					return false
   562  				}
   563  			}
   564  			return true
   565  		} else { // OR
   566  			for _, othersubcnd := range tother.flattenConditions() {
   567  				if cond.Satisfies(othersubcnd) {
   568  					return true
   569  				}
   570  			}
   571  			return false
   572  		}
   573  	default:
   574  		return false
   575  	}
   576  }
   577  
   578  func (cond *FilterConditionCompare) SatisfiesRaw(other gotenresource.FilterCondition) bool {
   579  	if typedCond, ok := other.(FilterCondition); !ok {
   580  		return false
   581  	} else {
   582  		return cond.Satisfies(typedCond)
   583  	}
   584  }
   585  
   586  func (cond *FilterConditionCompare) SpecifiesFieldPath(fp Log_FieldPath) bool {
   587  	return cond.Log_FieldPathValue.String() == fp.String()
   588  }
   589  
   590  func (cond *FilterConditionCompare) SpecifiesRawFieldPath(fp gotenobject.FieldPath) bool {
   591  	if typedFp, ok := fp.(Log_FieldPath); !ok {
   592  		return false
   593  	} else {
   594  		return cond.SpecifiesFieldPath(typedFp)
   595  	}
   596  }
   597  
   598  func (cond *FilterConditionCompare) GetOperator() filterParser.CompareOperator {
   599  	return cond.Operator
   600  }
   601  
   602  func (cond *FilterConditionCompare) GetRawFieldPath() gotenobject.FieldPath {
   603  	return cond.Log_FieldPathValue
   604  }
   605  
   606  func (cond *FilterConditionCompare) GetRawFieldPathValue() gotenobject.FieldPathValue {
   607  	return cond.Log_FieldPathValue
   608  }
   609  
   610  func (cond *FilterConditionCompare) ConditionCompare() {}
   611  
   612  type FilterConditionContains struct {
   613  	Type      gotenresource.ConditionContainsType
   614  	FieldPath Log_FieldPath
   615  
   616  	Value  Log_FieldPathArrayItemValue
   617  	Values []Log_FieldPathArrayItemValue
   618  }
   619  
   620  func (cond *FilterConditionContains) String() string {
   621  	switch cond.ConditionContainsType() {
   622  	case gotenresource.ConditionContainsTypeValue:
   623  		jsonValue, err := utils.JsonMarshal(cond.Value.GetRawItemValue())
   624  		if err != nil {
   625  			panic(err)
   626  		}
   627  		return fmt.Sprintf("%s CONTAINS %s", cond.FieldPath, string(jsonValue))
   628  	case gotenresource.ConditionContainsTypeAny, gotenresource.ConditionContainsTypeAll:
   629  		jsonValues := make([]string, len(cond.Values))
   630  		for i, v := range cond.Values {
   631  			if jsonValue, err := utils.JsonMarshal(v.GetRawItemValue()); err != nil {
   632  				panic(err)
   633  			} else {
   634  				jsonValues[i] = string(jsonValue)
   635  			}
   636  		}
   637  		return fmt.Sprintf("%s CONTAINS %s %s", cond.FieldPath, cond.ConditionContainsType(), fmt.Sprintf("(%s)", strings.Join(jsonValues, ", ")))
   638  	default:
   639  		panic(gotenresource.NewUnknownConditionContainsType(cond.ConditionContainsType()))
   640  	}
   641  }
   642  
   643  func (cond *FilterConditionContains) ConditionContainsType() gotenresource.ConditionContainsType {
   644  	return cond.Type
   645  }
   646  
   647  func (cond *FilterConditionContains) _IsFilterCondition() {}
   648  
   649  func (cond *FilterConditionContains) _IsLogFilterBuilderOrCondition() {}
   650  
   651  func (cond *FilterConditionContains) And(conds ...FilterCondition) FilterCondition {
   652  	return AndFilterConditions(append([]FilterCondition{cond}, conds...)...)
   653  }
   654  
   655  func (cond *FilterConditionContains) Evaluate(res *Log) bool {
   656  	switch cond.ConditionContainsType() {
   657  	case gotenresource.ConditionContainsTypeValue:
   658  		return cond.Value.ContainsValue(res)
   659  	case gotenresource.ConditionContainsTypeAny:
   660  		for _, v := range cond.Values {
   661  			if v.ContainsValue(res) {
   662  				return true
   663  			}
   664  		}
   665  		return false
   666  	case gotenresource.ConditionContainsTypeAll:
   667  		for _, v := range cond.Values {
   668  			if !v.ContainsValue(res) {
   669  				return false
   670  			}
   671  		}
   672  		return true
   673  	default:
   674  		panic(gotenresource.NewUnknownConditionContainsType(cond.ConditionContainsType()))
   675  	}
   676  }
   677  
   678  func (cond *FilterConditionContains) EvaluateRaw(res gotenresource.Resource) bool {
   679  	if typedRes, ok := res.(*Log); !ok {
   680  		return false
   681  	} else {
   682  		return cond.Evaluate(typedRes)
   683  	}
   684  }
   685  
   686  func (cond *FilterConditionContains) Satisfies(other FilterCondition) bool {
   687  	switch tother := other.(type) {
   688  	case *FilterConditionContains:
   689  		if cond.ConditionContainsType().IsValue() && tother.ConditionContainsType().IsValue() {
   690  			othertmp := new(Log)
   691  			tother.Value.WithIValue(tother.GetRawFieldPathItemValue().GetRawItemValue()).SetTo(&othertmp)
   692  			return cond.Value.ContainsValue(othertmp)
   693  		}
   694  		return false
   695  	default:
   696  		return false
   697  	}
   698  }
   699  
   700  func (cond *FilterConditionContains) SatisfiesRaw(other gotenresource.FilterCondition) bool {
   701  	if typedCond, ok := other.(FilterCondition); !ok {
   702  		return false
   703  	} else {
   704  		return cond.Satisfies(typedCond)
   705  	}
   706  }
   707  
   708  func (cond *FilterConditionContains) SpecifiesFieldPath(fp Log_FieldPath) bool {
   709  	return cond.FieldPath.String() == fp.String()
   710  }
   711  
   712  func (cond *FilterConditionContains) SpecifiesRawFieldPath(fp gotenobject.FieldPath) bool {
   713  	if typedFp, ok := fp.(Log_FieldPath); !ok {
   714  		return false
   715  	} else {
   716  		return cond.SpecifiesFieldPath(typedFp)
   717  	}
   718  }
   719  
   720  func (cond *FilterConditionContains) GetFieldPath() Log_FieldPath {
   721  	return cond.FieldPath
   722  }
   723  
   724  func (cond *FilterConditionContains) GetRawFieldPath() gotenobject.FieldPath {
   725  	return cond.FieldPath
   726  }
   727  
   728  func (cond *FilterConditionContains) GetRawFieldPathItemValue() gotenobject.FieldPathArrayItemValue {
   729  	switch cond.ConditionContainsType() {
   730  	case gotenresource.ConditionContainsTypeValue:
   731  		return cond.Value
   732  	default:
   733  		panic(fmt.Errorf("unable to get value for condition contains type %s", cond.ConditionContainsType()))
   734  	}
   735  }
   736  
   737  func (cond *FilterConditionContains) GetRawFieldPathItemValues() (res []gotenobject.FieldPathArrayItemValue) {
   738  	switch cond.ConditionContainsType() {
   739  	case gotenresource.ConditionContainsTypeAny, gotenresource.ConditionContainsTypeAll:
   740  		for _, fpaiv := range cond.Values {
   741  			res = append(res, fpaiv)
   742  		}
   743  	default:
   744  		panic(fmt.Errorf("unable to get values for condition contains type %s", cond.ConditionContainsType()))
   745  	}
   746  	return
   747  }
   748  
   749  func (cond *FilterConditionContains) ConditionContains() {}
   750  
   751  type FilterConditionIn struct {
   752  	Log_FieldPathArrayOfValues
   753  }
   754  
   755  func (cond *FilterConditionIn) String() string {
   756  	jsonValues, err := utils.JsonMarshal(cond.Log_FieldPathArrayOfValues.GetRawValues())
   757  	if err != nil {
   758  		panic(err)
   759  	}
   760  	return fmt.Sprintf("%s IN %s", cond.Log_FieldPathArrayOfValues, jsonValues)
   761  }
   762  
   763  func (cond *FilterConditionIn) _IsFilterCondition() {}
   764  
   765  func (cond *FilterConditionIn) _IsLogFilterBuilderOrCondition() {}
   766  
   767  func (cond *FilterConditionIn) And(conds ...FilterCondition) FilterCondition {
   768  	return AndFilterConditions(append([]FilterCondition{cond}, conds...)...)
   769  }
   770  
   771  func (cond *FilterConditionIn) Evaluate(res *Log) bool {
   772  	for _, inValue := range cond.Log_FieldPathArrayOfValues.GetRawValues() {
   773  		if cmp, ok := cond.Log_FieldPathArrayOfValues.WithIValue(inValue).CompareWith(res); ok && cmp == 0 {
   774  			return true
   775  		}
   776  	}
   777  	return false
   778  }
   779  
   780  func (cond *FilterConditionIn) EvaluateRaw(res gotenresource.Resource) bool {
   781  	if typedRes, ok := res.(*Log); !ok {
   782  		return false
   783  	} else {
   784  		return cond.Evaluate(typedRes)
   785  	}
   786  }
   787  
   788  func (cond *FilterConditionIn) Satisfies(other FilterCondition) bool {
   789  	switch tother := other.(type) {
   790  	case *FilterConditionIn:
   791  	outer:
   792  		for _, cval := range cond.Log_FieldPathArrayOfValues.GetRawValues() {
   793  			for _, otherval := range tother.Log_FieldPathArrayOfValues.GetRawValues() {
   794  				othertmp := new(Log)
   795  				tother.Log_FieldPathArrayOfValues.WithIValue(otherval).SetTo(&othertmp)
   796  				if cmp, comparable := cond.Log_FieldPathArrayOfValues.WithIValue(cval).CompareWith(othertmp); comparable && cmp == 0 {
   797  					continue outer
   798  				}
   799  			}
   800  			return false
   801  		}
   802  		return true
   803  	default:
   804  		for _, cval := range cond.Log_FieldPathArrayOfValues.GetRawValues() {
   805  			subcnd := &FilterConditionCompare{
   806  				Operator:           filterParser.Eq,
   807  				Log_FieldPathValue: cond.Log_FieldPathArrayOfValues.WithIValue(cval),
   808  			}
   809  			if !subcnd.Satisfies(tother) {
   810  				return false
   811  			}
   812  		}
   813  		return true
   814  	}
   815  }
   816  
   817  func (cond *FilterConditionIn) SatisfiesRaw(other gotenresource.FilterCondition) bool {
   818  	if typedCond, ok := other.(FilterCondition); !ok {
   819  		return false
   820  	} else {
   821  		return cond.Satisfies(typedCond)
   822  	}
   823  }
   824  
   825  func (cond *FilterConditionIn) SpecifiesFieldPath(fp Log_FieldPath) bool {
   826  	return cond.Log_FieldPathArrayOfValues.String() == fp.String()
   827  }
   828  
   829  func (cond *FilterConditionIn) SpecifiesRawFieldPath(fp gotenobject.FieldPath) bool {
   830  	if typedFp, ok := fp.(Log_FieldPath); !ok {
   831  		return false
   832  	} else {
   833  		return cond.SpecifiesFieldPath(typedFp)
   834  	}
   835  }
   836  
   837  func (cond *FilterConditionIn) GetRawFieldPath() gotenobject.FieldPath {
   838  	return cond.Log_FieldPathArrayOfValues
   839  }
   840  
   841  func (cond *FilterConditionIn) GetRawFieldPathArrayOfValues() gotenobject.FieldPathArrayOfValues {
   842  	return cond.Log_FieldPathArrayOfValues
   843  }
   844  
   845  func (cond *FilterConditionIn) ConditionIn() {}
   846  
   847  type FilterConditionNotIn struct {
   848  	Log_FieldPathArrayOfValues
   849  }
   850  
   851  func (cond *FilterConditionNotIn) String() string {
   852  	jsonValues, err := utils.JsonMarshal(cond.Log_FieldPathArrayOfValues.GetRawValues())
   853  	if err != nil {
   854  		panic(err)
   855  	}
   856  	return fmt.Sprintf("%s NOT IN %s", cond.Log_FieldPathArrayOfValues, jsonValues)
   857  }
   858  
   859  func (cond *FilterConditionNotIn) _IsFilterCondition() {}
   860  
   861  func (cond *FilterConditionNotIn) _IsLogFilterBuilderOrCondition() {}
   862  
   863  func (cond *FilterConditionNotIn) And(conds ...FilterCondition) FilterCondition {
   864  	return AndFilterConditions(append([]FilterCondition{cond}, conds...)...)
   865  }
   866  
   867  func (cond *FilterConditionNotIn) Evaluate(res *Log) bool {
   868  	for _, inValue := range cond.Log_FieldPathArrayOfValues.GetRawValues() {
   869  		if cmp, ok := cond.Log_FieldPathArrayOfValues.WithIValue(inValue).CompareWith(res); ok && cmp == 0 {
   870  			return false
   871  		}
   872  	}
   873  	return true
   874  }
   875  
   876  func (cond *FilterConditionNotIn) EvaluateRaw(res gotenresource.Resource) bool {
   877  	if typedRes, ok := res.(*Log); !ok {
   878  		return false
   879  	} else {
   880  		return cond.Evaluate(typedRes)
   881  	}
   882  }
   883  
   884  func (cond *FilterConditionNotIn) Satisfies(other FilterCondition) bool {
   885  	return false
   886  }
   887  
   888  func (cond *FilterConditionNotIn) SatisfiesRaw(other gotenresource.FilterCondition) bool {
   889  	if typedCond, ok := other.(FilterCondition); !ok {
   890  		return false
   891  	} else {
   892  		return cond.Satisfies(typedCond)
   893  	}
   894  }
   895  
   896  func (cond *FilterConditionNotIn) SpecifiesFieldPath(fp Log_FieldPath) bool {
   897  	return cond.Log_FieldPathArrayOfValues.String() == fp.String()
   898  }
   899  
   900  func (cond *FilterConditionNotIn) SpecifiesRawFieldPath(fp gotenobject.FieldPath) bool {
   901  	if typedFp, ok := fp.(Log_FieldPath); !ok {
   902  		return false
   903  	} else {
   904  		return cond.SpecifiesFieldPath(typedFp)
   905  	}
   906  }
   907  
   908  func (cond *FilterConditionNotIn) GetRawFieldPath() gotenobject.FieldPath {
   909  	return cond.Log_FieldPathArrayOfValues
   910  }
   911  
   912  func (cond *FilterConditionNotIn) GetRawFieldPathArrayOfValues() gotenobject.FieldPathArrayOfValues {
   913  	return cond.Log_FieldPathArrayOfValues
   914  }
   915  
   916  func (cond *FilterConditionNotIn) ConditionNotIn() {}
   917  
   918  type Filter struct {
   919  	FilterCondition
   920  }
   921  
   922  func (filter *Filter) _IsLogFilterBuilderOrCondition() {}
   923  
   924  // GetCondition is a getter of FilterCondition, which also handles nil pointer
   925  func (filter *Filter) GetCondition() FilterCondition {
   926  	if filter == nil {
   927  		return AndFilterConditions()
   928  	} else {
   929  		return filter.FilterCondition
   930  	}
   931  }
   932  
   933  // Evaluate is a wrapper on FilterCondition, which also handles nil pointer
   934  func (filter *Filter) Evaluate(res *Log) bool {
   935  	return filter.GetCondition().Evaluate(res)
   936  }
   937  
   938  func (filter *Filter) EvaluateRaw(res gotenresource.Resource) bool {
   939  	if typedRes, ok := res.(*Log); !ok {
   940  		return false
   941  	} else {
   942  		return filter.Evaluate(typedRes)
   943  	}
   944  }
   945  
   946  func (filter *Filter) GetRawCondition() gotenresource.FilterCondition {
   947  	if filter == nil {
   948  		return nil
   949  	}
   950  	return filter.GetCondition()
   951  }
   952  
   953  // FilterSlice is a helper for filtering arrays
   954  func (filter *Filter) FilterSlice(in []*Log) (out []*Log) {
   955  	for _, res := range in {
   956  		if filter.Evaluate(res) {
   957  			out = append(out, res)
   958  		}
   959  	}
   960  	return
   961  }
   962  
   963  // implement methods required by protobuf-go library for string-struct conversion
   964  
   965  func (filter *Filter) ProtoString() (string, error) {
   966  	if filter == nil || filter.FilterCondition == nil {
   967  		return "", nil
   968  	}
   969  	return filter.FilterCondition.String(), nil
   970  }
   971  
   972  func (filter *Filter) ParseProtoString(data string) error {
   973  	expression, err := filterParser.Parse([]byte(data))
   974  	if err != nil {
   975  		return status.Error(codes.InvalidArgument, err.Error())
   976  	}
   977  
   978  	condition, err := makeFilterConditionFromOr(expression.And)
   979  	if err != nil {
   980  		return err
   981  	}
   982  	filter.FilterCondition = condition
   983  	return nil
   984  }
   985  
   986  func (filter *Filter) String() string {
   987  	if filter == nil || filter.FilterCondition == nil {
   988  		return "<nil>"
   989  	}
   990  	return filter.FilterCondition.String()
   991  }
   992  
   993  func (filter *Filter) SetFromCliFlag(raw string) error {
   994  	return filter.ParseProtoString(raw)
   995  }
   996  
   997  // helpers
   998  
   999  func makeFilterConditionFromOperand(condition *filterParser.ConditionOperand) (FilterCondition, error) {
  1000  	path, err := ParseLog_FieldPath(condition.FieldPath)
  1001  	if err != nil {
  1002  		return nil, err
  1003  	}
  1004  	rhs := condition.ConditionRHS
  1005  	valueJSON, err := rhs.JSONValue()
  1006  	if err != nil {
  1007  		return nil, status.Error(codes.Internal, err.Error())
  1008  	}
  1009  
  1010  	if rhs.Compare != nil {
  1011  		cmp := rhs.Compare
  1012  		if !path.IsLeaf() && !(cmp.Operator == filterParser.Eq || cmp.Operator == filterParser.Neq) {
  1013  			return nil, status.Errorf(codes.InvalidArgument, "path '%s' is not comparable leaf value for operator %s", path, cmp.Operator)
  1014  		}
  1015  
  1016  		// translate null comparison to IS(NOT)NULL
  1017  		if cmp.Value.Null {
  1018  			switch cmp.Operator {
  1019  			case filterParser.Eq:
  1020  				return &FilterConditionIsNull{false, path}, nil
  1021  			case filterParser.Neq:
  1022  				return &FilterConditionIsNull{true, path}, nil
  1023  			default:
  1024  				return nil, status.Errorf(codes.InvalidArgument, "operator '%s' isn't valid when comparing null value", cmp.Operator)
  1025  			}
  1026  		}
  1027  
  1028  		pfv, err := ParseLog_FieldPathValue(path.String(), string(valueJSON))
  1029  		if err != nil {
  1030  			return nil, status.Errorf(codes.InvalidArgument, "error when parsing filter value for field path '%s': %s", path, err)
  1031  		}
  1032  
  1033  		return &FilterConditionCompare{
  1034  			Operator:           cmp.Operator,
  1035  			Log_FieldPathValue: pfv,
  1036  		}, nil
  1037  	} else if rhs.Is != nil {
  1038  		if rhs.Is.Null {
  1039  			return &FilterConditionIsNull{rhs.Is.Not, path}, nil
  1040  		} else if rhs.Is.NaN {
  1041  			return &FilterConditionIsNaN{rhs.Is.Not, path}, nil
  1042  		} else {
  1043  			return nil, status.Error(codes.Internal, "unknown filter IS type - expected NULL or NaN")
  1044  		}
  1045  	} else if rhs.Contains != nil {
  1046  		ct := gotenresource.ConditionContainsTypeFromParser(rhs.Contains)
  1047  		fp, err := ParseLog_FieldPath(path.String())
  1048  		if err != nil {
  1049  			return nil, err
  1050  		}
  1051  		if rhs.Contains.Value != nil {
  1052  			pfav, err := ParseLog_FieldPathArrayItemValue(path.String(), string(valueJSON))
  1053  			if err != nil {
  1054  				return nil, err
  1055  			}
  1056  			return &FilterConditionContains{ct, fp, pfav, nil}, nil
  1057  		} else if rhs.Contains.Any != nil || rhs.Contains.All != nil {
  1058  			parrv := rhs.Contains.GetArray()
  1059  			vals := make([]Log_FieldPathArrayItemValue, len(parrv))
  1060  			for i, pv := range parrv {
  1061  				jsonv, err := utils.JsonMarshal(pv)
  1062  				if err != nil {
  1063  					return nil, err
  1064  				}
  1065  				if pfav, err := ParseLog_FieldPathArrayItemValue(path.String(), string(jsonv)); err != nil {
  1066  					return nil, err
  1067  				} else {
  1068  					vals[i] = pfav
  1069  				}
  1070  			}
  1071  			return &FilterConditionContains{ct, fp, nil, vals}, nil
  1072  		} else {
  1073  			return nil, status.Error(codes.Internal, "unknown condition contains type")
  1074  		}
  1075  	} else if rhs.Like != nil {
  1076  		return nil, status.Errorf(codes.Unimplemented, "'LIKE' condition is not supported")
  1077  	} else if rhs.In != nil {
  1078  		if fpaov, err := ParseLog_FieldPathArrayOfValues(path.String(), string(valueJSON)); err != nil {
  1079  			return nil, err
  1080  		} else {
  1081  			return &FilterConditionIn{fpaov}, nil
  1082  		}
  1083  	} else if rhs.NotIn != nil {
  1084  		if fpaov, err := ParseLog_FieldPathArrayOfValues(path.String(), string(valueJSON)); err != nil {
  1085  			return nil, err
  1086  		} else {
  1087  			return &FilterConditionNotIn{fpaov}, nil
  1088  		}
  1089  	}
  1090  	return nil, status.Error(codes.Internal, "unknown filter RHS operand type")
  1091  
  1092  }
  1093  
  1094  func makeFilterConditionFromCondition(condition *filterParser.Condition) (FilterCondition, error) {
  1095  	if condition.SubExpression != nil {
  1096  		return makeFilterConditionFromOr(condition.SubExpression.And)
  1097  	} else if condition.Not != nil {
  1098  		not, err := makeFilterConditionFromCondition(condition.Not)
  1099  		if err != nil {
  1100  			return nil, err
  1101  		}
  1102  		return &FilterConditionNot{not}, nil
  1103  	} else if condition.Operand != nil {
  1104  		return makeFilterConditionFromOperand(condition.Operand)
  1105  	} else {
  1106  		return nil, status.Error(codes.Internal, "unknown condition type")
  1107  	}
  1108  }
  1109  
  1110  func makeFilterConditionFromAnd(conditions []filterParser.Condition) (FilterCondition, error) {
  1111  	if len(conditions) == 1 {
  1112  		return makeFilterConditionFromCondition(&conditions[0])
  1113  	} else {
  1114  		cnds := make([]FilterCondition, 0, len(conditions))
  1115  		for _, condition := range conditions {
  1116  			cnd, err := makeFilterConditionFromCondition(&condition)
  1117  			if err != nil {
  1118  				return nil, err
  1119  			}
  1120  			cnds = append(cnds, cnd)
  1121  		}
  1122  		return &FilterConditionComposite{Operator: filterParser.AND, Conditions: cnds}, nil
  1123  	}
  1124  }
  1125  
  1126  func makeFilterConditionFromOr(conditions []filterParser.AndCondition) (FilterCondition, error) {
  1127  	if len(conditions) == 1 {
  1128  		return makeFilterConditionFromAnd(conditions[0].Or)
  1129  	} else {
  1130  		cnds := make([]FilterCondition, 0, len(conditions))
  1131  		for _, condition := range conditions {
  1132  			cnd, err := makeFilterConditionFromAnd(condition.Or)
  1133  			if err != nil {
  1134  				return nil, err
  1135  			}
  1136  			cnds = append(cnds, cnd)
  1137  		}
  1138  		return &FilterConditionComposite{Operator: filterParser.OR, Conditions: cnds}, nil
  1139  	}
  1140  }