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

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