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

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