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

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