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

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