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