github.com/cloudwan/edgelq-sdk@v1.15.4/alerting/resources/v1/alert/alert.pb.name.go (about)

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