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

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