github.com/cloudwan/edgelq-sdk@v1.15.4/monitoring/resources/v4/alerting_condition/alerting_condition.pb.name.go (about)

     1  // Code generated by protoc-gen-goten-resource
     2  // Resource: AlertingCondition
     3  // DO NOT EDIT!!!
     4  
     5  package alerting_condition
     6  
     7  import (
     8  	"fmt"
     9  	"net/url"
    10  	"reflect"
    11  	"regexp"
    12  	"strings"
    13  
    14  	"google.golang.org/grpc/codes"
    15  	"google.golang.org/grpc/status"
    16  	"google.golang.org/protobuf/proto"
    17  
    18  	"github.com/cloudwan/goten-sdk/runtime/goten"
    19  	gotenresource "github.com/cloudwan/goten-sdk/runtime/resource"
    20  )
    21  
    22  // proto imports
    23  import (
    24  	alerting_policy "github.com/cloudwan/edgelq-sdk/monitoring/resources/v4/alerting_policy"
    25  	common "github.com/cloudwan/edgelq-sdk/monitoring/resources/v4/common"
    26  	time_serie "github.com/cloudwan/edgelq-sdk/monitoring/resources/v4/time_serie"
    27  	meta "github.com/cloudwan/goten-sdk/types/meta"
    28  	durationpb "google.golang.org/protobuf/types/known/durationpb"
    29  )
    30  
    31  // ensure the imports are used
    32  var (
    33  	_ = codes.NotFound
    34  	_ = new(fmt.Stringer)
    35  	_ = new(proto.Message)
    36  	_ = status.Status{}
    37  	_ = url.URL{}
    38  	_ = strings.Builder{}
    39  
    40  	_ = new(goten.GotenMessage)
    41  	_ = new(gotenresource.ListQuery)
    42  )
    43  
    44  // make sure we're using proto imports
    45  var (
    46  	_ = &alerting_policy.AlertingPolicy{}
    47  	_ = &common.LabelDescriptor{}
    48  	_ = &time_serie.Point{}
    49  	_ = &durationpb.Duration{}
    50  	_ = &meta.Meta{}
    51  )
    52  
    53  var alertingCondition_RegexpId = regexp.MustCompile("^(?P<alerting_condition_id>[\\w][\\w.-]{0,127})$")
    54  var regexPath_Project_Region_AlertingPolicy = regexp.MustCompile("^projects/(?P<project_id>-|[\\w][\\w.-]{0,127})/regions/(?P<region_id>-|[a-z][a-z0-9\\-]{0,28}[a-z0-9])/alertingPolicies/(?P<alerting_policy_id>-|[\\w][\\w.-]{0,127})/alertingConditions/(?P<alerting_condition_id>-|[\\w][\\w.-]{0,127})$")
    55  
    56  func (r *AlertingCondition) MaybePopulateDefaults() error {
    57  	alertingConditionInterface := interface{}(r)
    58  	if defaulter, ok := alertingConditionInterface.(goten.Defaulter); ok {
    59  		return defaulter.PopulateDefaults()
    60  	}
    61  	return nil
    62  }
    63  
    64  type Name struct {
    65  	ParentName
    66  	AlertingConditionId string `firestore:"alertingConditionId"`
    67  }
    68  
    69  func ParseName(name string) (*Name, error) {
    70  	var matches []string
    71  	if matches = regexPath_Project_Region_AlertingPolicy.FindStringSubmatch(name); matches != nil {
    72  		return NewNameBuilder().
    73  			SetProjectId(matches[1]).
    74  			SetRegionId(matches[2]).
    75  			SetAlertingPolicyId(matches[3]).
    76  			SetId(matches[4]).
    77  			Name(), nil
    78  	}
    79  
    80  	return nil, status.Errorf(codes.InvalidArgument, "unable to parse '%s' as AlertingCondition name", name)
    81  }
    82  
    83  func MustParseName(name string) *Name {
    84  	result, err := ParseName(name)
    85  	if err != nil {
    86  		panic(err)
    87  	}
    88  	return result
    89  }
    90  
    91  func ParseNameOrId(nameOrId string) (*Name, error) {
    92  	name, err := ParseName(nameOrId)
    93  	if err == nil {
    94  		return name, err
    95  	}
    96  	if alertingCondition_RegexpId.MatchString(nameOrId) {
    97  		return &Name{AlertingConditionId: nameOrId}, nil
    98  	} else {
    99  		return nil, fmt.Errorf("unable to parse '%s' as AlertingCondition name or id", nameOrId)
   100  	}
   101  }
   102  
   103  func (name *Name) SetFromSegments(segments gotenresource.NameSegments) error {
   104  	if len(segments) == 0 {
   105  		return status.Errorf(codes.InvalidArgument, "No segments given for AlertingCondition name")
   106  	}
   107  	if err := name.ParentName.SetFromSegments(segments[:len(segments)-1]); err != nil {
   108  		return err
   109  	}
   110  	if segments[len(segments)-1].CollectionLowerJson != "alertingConditions" {
   111  		return status.Errorf(codes.InvalidArgument, "unable to use segments %s to form AlertingCondition name", segments)
   112  	}
   113  	name.AlertingConditionId = segments[len(segments)-1].Id
   114  	return nil
   115  }
   116  
   117  func (name *Name) GetAlertingPolicyName() *alerting_policy.Name {
   118  	if name == nil {
   119  		return nil
   120  	}
   121  	return name.ParentName.GetAlertingPolicyName()
   122  }
   123  
   124  func (name *Name) IsSpecified() bool {
   125  	if name == nil || name.Pattern == "" || name.AlertingConditionId == "" {
   126  		return false
   127  	}
   128  	return name.ParentName.IsSpecified()
   129  }
   130  
   131  func (name *Name) IsFullyQualified() bool {
   132  	if name == nil {
   133  		return false
   134  	}
   135  	if name.ParentName.IsFullyQualified() == false {
   136  		return false
   137  	}
   138  	if name.AlertingConditionId == "" || name.AlertingConditionId == gotenresource.WildcardId {
   139  		return false
   140  	}
   141  	return true
   142  }
   143  
   144  func (name *Name) FullyQualifiedName() (string, error) {
   145  	if !name.IsFullyQualified() {
   146  		return "", status.Errorf(codes.InvalidArgument, "Name for AlertingCondition is not fully qualified")
   147  	}
   148  	return fmt.Sprintf("//monitoring.edgelq.com/%s", name.String()), nil
   149  }
   150  
   151  func (name *Name) String() string {
   152  	if name == nil {
   153  		return "<nil>"
   154  	}
   155  	if valueStr, err := name.ProtoString(); err != nil {
   156  		panic(err)
   157  	} else {
   158  		return valueStr
   159  	}
   160  }
   161  
   162  func (name *Name) AsReference() *Reference {
   163  	return &Reference{Name: *name}
   164  }
   165  
   166  func (name *Name) AsRawReference() gotenresource.Reference {
   167  	return name.AsReference()
   168  }
   169  
   170  func (name *Name) GetResourceDescriptor() gotenresource.Descriptor {
   171  	return descriptor
   172  }
   173  
   174  func (name *Name) GetPattern() gotenresource.NamePattern {
   175  	if name == nil {
   176  		return ""
   177  	}
   178  	return name.Pattern
   179  }
   180  
   181  func (name *Name) GetIdParts() map[string]string {
   182  	if name != nil {
   183  		return map[string]string{
   184  			"projectId":           name.ProjectId,
   185  			"regionId":            name.RegionId,
   186  			"alertingPolicyId":    name.AlertingPolicyId,
   187  			"alertingConditionId": name.AlertingConditionId,
   188  		}
   189  	}
   190  	return map[string]string{
   191  		"projectId":           "",
   192  		"regionId":            "",
   193  		"alertingPolicyId":    "",
   194  		"alertingConditionId": "",
   195  	}
   196  }
   197  
   198  func (name *Name) GetSegments() gotenresource.NameSegments {
   199  	if name == nil || name.Pattern == "" {
   200  		return nil
   201  	}
   202  	segments := name.ParentName.GetSegments()
   203  	return append(segments, gotenresource.NameSegment{
   204  		CollectionLowerJson: "alertingConditions",
   205  		Id:                  name.AlertingConditionId,
   206  	})
   207  }
   208  
   209  func (name *Name) GetIParentName() gotenresource.Name {
   210  	if name == nil {
   211  		return (*ParentName)(nil)
   212  	}
   213  	return &name.ParentName
   214  }
   215  
   216  func (name *Name) GetIUnderlyingParentName() gotenresource.Name {
   217  	if parentName := name.GetAlertingPolicyName(); parentName != nil {
   218  		return parentName
   219  	}
   220  	return nil
   221  }
   222  
   223  // implement methods required by protobuf-go library for string-struct conversion
   224  
   225  func (name *Name) ProtoString() (string, error) {
   226  	if name == nil {
   227  		return "", nil
   228  	}
   229  	result := ""
   230  	parentPrefix, err := name.ParentName.ProtoString()
   231  	if err != nil {
   232  		return "", err
   233  	}
   234  	if parentPrefix != "" {
   235  		result += parentPrefix + "/"
   236  	}
   237  	result += "alertingConditions/" + name.AlertingConditionId
   238  	return result, nil
   239  }
   240  
   241  func (name *Name) ParseProtoString(data string) error {
   242  	parsed, err := ParseName(data)
   243  	if err != nil {
   244  		return err
   245  	}
   246  	*name = *parsed
   247  	return nil
   248  }
   249  
   250  // GotenEqual returns true if other is of same type and paths are equal (implements goten.Equaler interface)
   251  func (name *Name) GotenEqual(other interface{}) bool {
   252  	if other == nil {
   253  		return name == nil
   254  	}
   255  	other1, ok := other.(*Name)
   256  	if !ok {
   257  		other2, ok := other.(Name)
   258  		if ok {
   259  			other1 = &other2
   260  		} else {
   261  			return false
   262  		}
   263  	}
   264  	if other1 == nil {
   265  		return name == nil
   266  	} else if name == nil {
   267  		return false
   268  	}
   269  	if name.ParentName.GotenEqual(other1.ParentName) == false {
   270  		return false
   271  	}
   272  	if name.AlertingConditionId != other1.AlertingConditionId {
   273  		return false
   274  	}
   275  
   276  	return true
   277  }
   278  
   279  // Matches is same as GotenEqual, but also will accept "other" if name is wildcard.
   280  func (name *Name) Matches(other interface{}) bool {
   281  	if other == nil {
   282  		return name == nil
   283  	}
   284  	other1, ok := other.(*Name)
   285  	if !ok {
   286  		other2, ok := other.(Name)
   287  		if ok {
   288  			other1 = &other2
   289  		} else {
   290  			return false
   291  		}
   292  	}
   293  	if other1 == nil {
   294  		return name == nil
   295  	} else if name == nil {
   296  		return false
   297  	}
   298  	if name.ParentName.Matches(other1.ParentName) == false {
   299  		return false
   300  	}
   301  	if name.AlertingConditionId != other1.AlertingConditionId {
   302  		return name.AlertingConditionId == gotenresource.WildcardId
   303  	}
   304  
   305  	return true
   306  }
   307  
   308  // implement CustomTypeCliValue method
   309  func (name *Name) SetFromCliFlag(raw string) error {
   310  	parsedName, err := ParseName(raw)
   311  	if err != nil {
   312  		return err
   313  	}
   314  	*name = *parsedName
   315  	return nil
   316  }
   317  
   318  type Reference struct {
   319  	Name
   320  	alertingCondition *AlertingCondition
   321  }
   322  
   323  func MakeReference(name *Name, alertingCondition *AlertingCondition) (*Reference, error) {
   324  	return &Reference{
   325  		Name:              *name,
   326  		alertingCondition: alertingCondition,
   327  	}, nil
   328  }
   329  
   330  func ParseReference(name string) (*Reference, error) {
   331  	parsedName, err := ParseName(name)
   332  	if err != nil {
   333  		return nil, err
   334  	}
   335  	return MakeReference(parsedName, nil)
   336  }
   337  
   338  func MustParseReference(name string) *Reference {
   339  	result, err := ParseReference(name)
   340  	if err != nil {
   341  		panic(err)
   342  	}
   343  	return result
   344  }
   345  
   346  func (ref *Reference) Resolve(resolved *AlertingCondition) {
   347  	ref.alertingCondition = resolved
   348  }
   349  
   350  func (ref *Reference) ResolveRaw(res gotenresource.Resource) error {
   351  	if res == nil {
   352  		ref.Resolve(nil)
   353  		return nil
   354  	}
   355  	if typedRes, ok := res.(*AlertingCondition); ok {
   356  		ref.Resolve(typedRes)
   357  		return nil
   358  	}
   359  	return status.Errorf(codes.Internal, "Invalid resource type for AlertingCondition: %s", reflect.TypeOf(res).Elem().Name())
   360  }
   361  
   362  func (ref *Reference) Resolved() bool {
   363  	return ref != nil && ref.alertingCondition != nil
   364  }
   365  
   366  func (ref *Reference) ClearCached() {
   367  	ref.alertingCondition = nil
   368  }
   369  
   370  func (ref *Reference) GetAlertingCondition() *AlertingCondition {
   371  	if ref == nil {
   372  		return nil
   373  	}
   374  	return ref.alertingCondition
   375  }
   376  
   377  func (ref *Reference) GetRawResource() gotenresource.Resource {
   378  	if ref == nil {
   379  		return (*AlertingCondition)(nil)
   380  	}
   381  	return ref.alertingCondition
   382  }
   383  
   384  func (ref *Reference) IsFullyQualified() bool {
   385  	if ref == nil {
   386  		return false
   387  	}
   388  	return ref.Name.IsFullyQualified()
   389  }
   390  
   391  func (ref *Reference) IsSpecified() bool {
   392  	if ref == nil {
   393  		return false
   394  	}
   395  	return ref.Name.IsSpecified()
   396  }
   397  
   398  func (ref *Reference) FullyQualifiedName() (string, error) {
   399  	if !ref.IsFullyQualified() {
   400  		return "", status.Errorf(codes.InvalidArgument, "Name for AlertingCondition is not fully qualified")
   401  	}
   402  	return fmt.Sprintf("//monitoring.edgelq.com/%s", ref.String()), nil
   403  }
   404  
   405  func (ref *Reference) GetResourceDescriptor() gotenresource.Descriptor {
   406  	return descriptor
   407  }
   408  
   409  func (ref *Reference) GetPattern() gotenresource.NamePattern {
   410  	if ref == nil {
   411  		return ""
   412  	}
   413  	return ref.Pattern
   414  }
   415  
   416  func (ref *Reference) GetIdParts() map[string]string {
   417  	if ref != nil {
   418  		return ref.Name.GetIdParts()
   419  	}
   420  	return map[string]string{
   421  		"projectId":           "",
   422  		"regionId":            "",
   423  		"alertingPolicyId":    "",
   424  		"alertingConditionId": "",
   425  	}
   426  }
   427  
   428  func (ref *Reference) GetSegments() gotenresource.NameSegments {
   429  	if ref != nil {
   430  		return ref.Name.GetSegments()
   431  	}
   432  	return nil
   433  }
   434  
   435  func (ref *Reference) GetIParentName() gotenresource.Name {
   436  	if ref == nil {
   437  		return (*ParentName)(nil)
   438  	}
   439  	return ref.Name.GetIParentName()
   440  }
   441  
   442  func (ref *Reference) GetIUnderlyingParentName() gotenresource.Name {
   443  	if ref != nil {
   444  		return ref.Name.GetIUnderlyingParentName()
   445  	}
   446  	return nil
   447  }
   448  
   449  func (ref *Reference) String() string {
   450  	if ref == nil {
   451  		return "<nil>"
   452  	}
   453  	return ref.Name.String()
   454  }
   455  
   456  // implement methods required by protobuf-go library for string-struct conversion
   457  
   458  func (ref *Reference) ProtoString() (string, error) {
   459  	if ref == nil {
   460  		return "", nil
   461  	}
   462  	return ref.Name.ProtoString()
   463  }
   464  
   465  func (ref *Reference) ParseProtoString(data string) error {
   466  	parsed, err := ParseReference(data)
   467  	if err != nil {
   468  		return err
   469  	}
   470  	*ref = *parsed
   471  	return nil
   472  }
   473  
   474  // GotenEqual returns true if other is of same type and paths are equal (implements goten.Equaler interface)
   475  func (ref *Reference) GotenEqual(other interface{}) bool {
   476  	if other == nil {
   477  		return ref == nil
   478  	}
   479  	other1, ok := other.(*Reference)
   480  	if !ok {
   481  		other2, ok := other.(Reference)
   482  		if ok {
   483  			other1 = &other2
   484  		} else {
   485  			return false
   486  		}
   487  	}
   488  	if other1 == nil {
   489  		return ref == nil
   490  	} else if ref == nil {
   491  		return false
   492  	}
   493  
   494  	return ref.Name.GotenEqual(other1.Name)
   495  }
   496  
   497  // Matches is same as GotenEqual, but also will accept "other" if name is wildcard.
   498  func (name *Reference) Matches(other interface{}) bool {
   499  	if other == nil {
   500  		return name == nil
   501  	}
   502  	other1, ok := other.(*Reference)
   503  	if !ok {
   504  		other2, ok := other.(Reference)
   505  		if ok {
   506  			other1 = &other2
   507  		} else {
   508  			return false
   509  		}
   510  	}
   511  	if other1 == nil {
   512  		return name == nil
   513  	} else if name == nil {
   514  		return false
   515  	}
   516  	return name.Name.Matches(&other1.Name)
   517  }
   518  
   519  // implement CustomTypeCliValue method
   520  func (ref *Reference) SetFromCliFlag(raw string) error {
   521  	parsedRef, err := ParseReference(raw)
   522  	if err != nil {
   523  		return err
   524  	}
   525  	*ref = *parsedRef
   526  	return nil
   527  }