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

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