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

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