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