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

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