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