github.com/cloudwan/edgelq-sdk@v1.15.4/limits/resources/v1/plan/plan.pb.parentname.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 parentRegexPath_Service = regexp.MustCompile("^services/(?P<service_id>-|[a-z][a-z0-9\\-.]{0,28}[a-z0-9])$")
    54  var parentRegexPath_Organization = regexp.MustCompile("^organizations/(?P<organization_id>-|[\\w][\\w.-]{0,127})$")
    55  
    56  type ParentName struct {
    57  	NamePattern
    58  	ServiceId      string `firestore:"serviceId"`
    59  	OrganizationId string `firestore:"organizationId"`
    60  }
    61  
    62  func ParseParentName(name string) (*ParentName, error) {
    63  	var matches []string
    64  	if matches = parentRegexPath_Service.FindStringSubmatch(name); matches != nil {
    65  		return NewNameBuilder().
    66  			SetServiceId(matches[1]).
    67  			Parent(), nil
    68  	}
    69  	if matches = parentRegexPath_Organization.FindStringSubmatch(name); matches != nil {
    70  		return NewNameBuilder().
    71  			SetOrganizationId(matches[1]).
    72  			Parent(), nil
    73  	}
    74  
    75  	return nil, status.Errorf(codes.InvalidArgument, "unable to parse '%s' as Plan parent name", name)
    76  }
    77  
    78  func MustParseParentName(name string) *ParentName {
    79  	result, err := ParseParentName(name)
    80  	if err != nil {
    81  		panic(err)
    82  	}
    83  	return result
    84  }
    85  
    86  func (name *ParentName) SetFromSegments(segments gotenresource.NameSegments) error {
    87  	if len(segments) == 1 && segments[0].CollectionLowerJson == "services" {
    88  		name.Pattern = NamePattern_Service
    89  		name.ServiceId = segments[0].Id
    90  		return nil
    91  	} else if len(segments) == 1 && segments[0].CollectionLowerJson == "organizations" {
    92  		name.Pattern = NamePattern_Organization
    93  		name.OrganizationId = segments[0].Id
    94  		return nil
    95  	}
    96  	return status.Errorf(codes.InvalidArgument, "unable to use segments %s to form Plan parent name", segments)
    97  }
    98  
    99  func (name *ParentName) GetServiceName() *meta_service.Name {
   100  	if name == nil {
   101  		return nil
   102  	}
   103  
   104  	switch name.Pattern {
   105  	case NamePattern_Service:
   106  		return meta_service.NewNameBuilder().
   107  			SetId(name.ServiceId).
   108  			Name()
   109  	default:
   110  		return nil
   111  	}
   112  }
   113  
   114  func (name *ParentName) GetOrganizationName() *iam_organization.Name {
   115  	if name == nil {
   116  		return nil
   117  	}
   118  
   119  	switch name.Pattern {
   120  	case NamePattern_Organization:
   121  		return iam_organization.NewNameBuilder().
   122  			SetId(name.OrganizationId).
   123  			Name()
   124  	default:
   125  		return nil
   126  	}
   127  }
   128  
   129  func (name *ParentName) IsSpecified() bool {
   130  	if name == nil || name.Pattern == "" {
   131  		return false
   132  	}
   133  	switch name.Pattern {
   134  	case NamePattern_Service:
   135  		return name.ServiceId != ""
   136  	case NamePattern_Organization:
   137  		return name.OrganizationId != ""
   138  	}
   139  	return false
   140  }
   141  
   142  func (name *ParentName) IsFullyQualified() bool {
   143  	if name == nil || name.Pattern == "" {
   144  		return false
   145  	}
   146  
   147  	switch name.Pattern {
   148  	case NamePattern_Service:
   149  		return name.ServiceId != "" && name.ServiceId != gotenresource.WildcardId
   150  	case NamePattern_Organization:
   151  		return name.OrganizationId != "" && name.OrganizationId != gotenresource.WildcardId
   152  	}
   153  
   154  	return false
   155  }
   156  
   157  func (name *ParentName) FullyQualifiedName() (string, error) {
   158  	if !name.IsFullyQualified() {
   159  		return "", status.Errorf(codes.InvalidArgument, "Parent name for Plan is not fully qualified")
   160  	}
   161  	return fmt.Sprintf("//limits.edgelq.com/%s", name.String()), nil
   162  }
   163  
   164  func (name *ParentName) GetResourceDescriptor() gotenresource.Descriptor {
   165  	return descriptor
   166  }
   167  
   168  func (name *ParentName) GetPattern() gotenresource.NamePattern {
   169  	if name == nil {
   170  		return ""
   171  	}
   172  	return name.Pattern
   173  }
   174  
   175  func (name *ParentName) GetIdParts() map[string]string {
   176  	if name != nil {
   177  		return map[string]string{
   178  			"serviceId":      name.ServiceId,
   179  			"organizationId": name.OrganizationId,
   180  		}
   181  	}
   182  	return map[string]string{
   183  		"serviceId":      "",
   184  		"organizationId": "",
   185  	}
   186  }
   187  
   188  func (name *ParentName) GetSegments() gotenresource.NameSegments {
   189  	if name == nil {
   190  		return nil
   191  	}
   192  
   193  	switch name.Pattern {
   194  	case NamePattern_Service:
   195  		return gotenresource.NameSegments{
   196  			gotenresource.NameSegment{
   197  				CollectionLowerJson: "services",
   198  				Id:                  name.ServiceId,
   199  			},
   200  		}
   201  	case NamePattern_Organization:
   202  		return gotenresource.NameSegments{
   203  			gotenresource.NameSegment{
   204  				CollectionLowerJson: "organizations",
   205  				Id:                  name.OrganizationId,
   206  			},
   207  		}
   208  	}
   209  	return nil
   210  }
   211  
   212  func (name *ParentName) GetIParentName() gotenresource.Name {
   213  	return nil
   214  }
   215  
   216  func (name *ParentName) GetIUnderlyingParentName() gotenresource.Name {
   217  	return nil
   218  }
   219  
   220  func (name *ParentName) String() string {
   221  	if name == nil {
   222  		return "<nil>"
   223  	}
   224  
   225  	if valueStr, err := name.ProtoString(); err != nil {
   226  		panic(err)
   227  	} else {
   228  		return valueStr
   229  	}
   230  }
   231  
   232  func (name *ParentName) DescendsFrom(ancestor string) bool {
   233  	if name == nil {
   234  		return false
   235  	}
   236  
   237  	switch name.Pattern {
   238  	case NamePattern_Service:
   239  		return ancestor == "services"
   240  	case NamePattern_Organization:
   241  		return ancestor == "organizations"
   242  	}
   243  
   244  	return false
   245  }
   246  
   247  func (name *ParentName) AsReference() *ParentReference {
   248  	return &ParentReference{ParentName: *name}
   249  }
   250  
   251  func (name *ParentName) AsRawReference() gotenresource.Reference {
   252  	return name.AsReference()
   253  }
   254  
   255  // implement methods required by protobuf-go library for string-struct conversion
   256  
   257  func (name *ParentName) ProtoString() (string, error) {
   258  	if name == nil {
   259  		return "", nil
   260  	}
   261  	switch name.Pattern {
   262  	case NamePattern_Service:
   263  		return "services/" + name.ServiceId, nil
   264  	case NamePattern_Organization:
   265  		return "organizations/" + name.OrganizationId, nil
   266  	}
   267  	return "", nil
   268  }
   269  
   270  func (name *ParentName) ParseProtoString(data string) error {
   271  	parsed, err := ParseParentName(data)
   272  	if err != nil {
   273  		return err
   274  	}
   275  	*name = *parsed
   276  	return nil
   277  }
   278  
   279  // GotenEqual returns true if other is of same type and paths are equal (implements goten.Equaler interface)
   280  func (name *ParentName) GotenEqual(other interface{}) bool {
   281  	if other == nil {
   282  		return name == nil
   283  	}
   284  	other1, ok := other.(*ParentName)
   285  	if !ok {
   286  		other2, ok := other.(ParentName)
   287  		if ok {
   288  			other1 = &other2
   289  		} else {
   290  			return false
   291  		}
   292  	}
   293  	if other1 == nil {
   294  		return name == nil
   295  	} else if name == nil {
   296  		return false
   297  	}
   298  	if name.ServiceId != other1.ServiceId {
   299  		return false
   300  	}
   301  	if name.OrganizationId != other1.OrganizationId {
   302  		return false
   303  	}
   304  	if name.Pattern != other1.Pattern {
   305  		return false
   306  	}
   307  
   308  	return true
   309  }
   310  
   311  // Matches is same as GotenEqual, but also will accept "other" if name is wildcard.
   312  func (name *ParentName) Matches(other interface{}) bool {
   313  	if other == nil {
   314  		return name == nil
   315  	}
   316  	other1, ok := other.(*ParentName)
   317  	if !ok {
   318  		other2, ok := other.(ParentName)
   319  		if ok {
   320  			other1 = &other2
   321  		} else {
   322  			return false
   323  		}
   324  	}
   325  	if other1 == nil {
   326  		return name == nil
   327  	} else if name == nil {
   328  		return false
   329  	}
   330  
   331  	if name.Pattern != other1.Pattern {
   332  		return false
   333  	}
   334  	switch name.Pattern {
   335  	case NamePattern_Service:
   336  		if name.ServiceId != other1.ServiceId &&
   337  			name.ServiceId != gotenresource.WildcardId {
   338  			return false
   339  		}
   340  	case NamePattern_Organization:
   341  		if name.OrganizationId != other1.OrganizationId &&
   342  			name.OrganizationId != gotenresource.WildcardId {
   343  			return false
   344  		}
   345  	}
   346  
   347  	return true
   348  }
   349  
   350  // implement CustomTypeCliValue method
   351  func (name *ParentName) SetFromCliFlag(raw string) error {
   352  	parsedName, err := ParseParentName(raw)
   353  	if err != nil {
   354  		return err
   355  	}
   356  	*name = *parsedName
   357  	return nil
   358  }
   359  
   360  type ParentReference struct {
   361  	ParentName
   362  	service      *meta_service.Service
   363  	organization *iam_organization.Organization
   364  }
   365  
   366  func MakeParentReference(name *ParentName) (*ParentReference, error) {
   367  	return &ParentReference{
   368  		ParentName: *name,
   369  	}, nil
   370  }
   371  
   372  func ParseParentReference(name string) (*ParentReference, error) {
   373  	parsedName, err := ParseParentName(name)
   374  	if err != nil {
   375  		return nil, err
   376  	}
   377  	return MakeParentReference(parsedName)
   378  }
   379  
   380  func MustParseParentReference(name string) *ParentReference {
   381  	result, err := ParseParentReference(name)
   382  	if err != nil {
   383  		panic(err)
   384  	}
   385  	return result
   386  }
   387  func (ref *ParentReference) GetServiceReference() *meta_service.Reference {
   388  	if ref == nil {
   389  		return nil
   390  	}
   391  
   392  	switch ref.Pattern {
   393  	case NamePattern_Service:
   394  		return meta_service.NewNameBuilder().
   395  			SetId(ref.ServiceId).
   396  			Reference()
   397  	default:
   398  		return nil
   399  	}
   400  }
   401  func (ref *ParentReference) GetOrganizationReference() *iam_organization.Reference {
   402  	if ref == nil {
   403  		return nil
   404  	}
   405  
   406  	switch ref.Pattern {
   407  	case NamePattern_Organization:
   408  		return iam_organization.NewNameBuilder().
   409  			SetId(ref.OrganizationId).
   410  			Reference()
   411  	default:
   412  		return nil
   413  	}
   414  }
   415  
   416  func (ref *ParentReference) GetUnderlyingReference() gotenresource.Reference {
   417  	if ref == nil {
   418  		return nil
   419  	}
   420  	serviceRef := ref.GetServiceReference()
   421  	if serviceRef != nil {
   422  		return serviceRef
   423  	}
   424  	organizationRef := ref.GetOrganizationReference()
   425  	if organizationRef != nil {
   426  		return organizationRef
   427  	}
   428  
   429  	return nil
   430  }
   431  
   432  func (ref *ParentReference) ResolveRaw(res gotenresource.Resource) error {
   433  	switch typedRes := res.(type) {
   434  	case *meta_service.Service:
   435  		if name := ref.GetServiceName(); name == nil {
   436  			return status.Errorf(codes.InvalidArgument, "cannot set Service as parent of Plan, because pattern does not match")
   437  		}
   438  		ref.service = typedRes
   439  		return nil
   440  	case *iam_organization.Organization:
   441  		if name := ref.GetOrganizationName(); name == nil {
   442  			return status.Errorf(codes.InvalidArgument, "cannot set Organization as parent of Plan, because pattern does not match")
   443  		}
   444  		ref.organization = typedRes
   445  		return nil
   446  	default:
   447  		return status.Errorf(codes.Internal, "Invalid parent type for Plan, got %s", reflect.TypeOf(res).Elem().Name())
   448  	}
   449  }
   450  
   451  func (ref *ParentReference) Resolved() bool {
   452  	if name := ref.GetServiceName(); name != nil {
   453  		return ref.service != nil
   454  	}
   455  	if name := ref.GetOrganizationName(); name != nil {
   456  		return ref.organization != nil
   457  	}
   458  	return true
   459  }
   460  
   461  func (ref *ParentReference) ClearCached() {
   462  	ref.service = nil
   463  	ref.organization = nil
   464  }
   465  
   466  func (ref *ParentReference) GetService() *meta_service.Service {
   467  	if ref == nil {
   468  		return nil
   469  	}
   470  	return ref.service
   471  }
   472  func (ref *ParentReference) GetOrganization() *iam_organization.Organization {
   473  	if ref == nil {
   474  		return nil
   475  	}
   476  	return ref.organization
   477  }
   478  
   479  func (ref *ParentReference) GetRawResource() gotenresource.Resource {
   480  	if name := ref.ParentName.GetServiceName(); name != nil {
   481  		return ref.service
   482  	}
   483  	if name := ref.ParentName.GetOrganizationName(); name != nil {
   484  		return ref.organization
   485  	}
   486  	return nil
   487  }
   488  
   489  func (ref *ParentReference) IsFullyQualified() bool {
   490  	if ref == nil {
   491  		return false
   492  	}
   493  	return ref.ParentName.IsFullyQualified()
   494  }
   495  
   496  func (ref *ParentReference) IsSpecified() bool {
   497  	if ref == nil {
   498  		return false
   499  	}
   500  	return ref.ParentName.IsSpecified()
   501  }
   502  
   503  func (ref *ParentReference) GetResourceDescriptor() gotenresource.Descriptor {
   504  	return descriptor
   505  }
   506  
   507  func (ref *ParentReference) GetPattern() gotenresource.NamePattern {
   508  	if ref == nil {
   509  		return ""
   510  	}
   511  	return ref.Pattern
   512  }
   513  
   514  func (ref *ParentReference) GetIdParts() map[string]string {
   515  	if ref != nil {
   516  		return ref.ParentName.GetIdParts()
   517  	}
   518  	return map[string]string{
   519  		"serviceId":      "",
   520  		"organizationId": "",
   521  	}
   522  }
   523  
   524  func (ref *ParentReference) GetSegments() gotenresource.NameSegments {
   525  	if ref != nil {
   526  		return ref.ParentName.GetSegments()
   527  	}
   528  	return nil
   529  }
   530  
   531  func (ref *ParentReference) GetIParentName() gotenresource.Name {
   532  	return nil
   533  }
   534  
   535  func (ref *ParentReference) GetIUnderlyingParentName() gotenresource.Name {
   536  	return nil
   537  }
   538  
   539  func (ref *ParentReference) String() string {
   540  	if ref == nil {
   541  		return "<nil>"
   542  	}
   543  	return ref.ParentName.String()
   544  }
   545  
   546  // implement methods required by protobuf-go library for string-struct conversion
   547  
   548  func (ref *ParentReference) ProtoString() (string, error) {
   549  	if ref == nil {
   550  		return "", nil
   551  	}
   552  	return ref.ParentName.ProtoString()
   553  }
   554  
   555  func (ref *ParentReference) ParseProtoString(data string) error {
   556  	parsed, err := ParseParentReference(data)
   557  	if err != nil {
   558  		return err
   559  	}
   560  	*ref = *parsed
   561  	return nil
   562  }
   563  
   564  // GotenEqual returns true if other is of same type and paths are equal (implements goten.Equaler interface)
   565  func (ref *ParentReference) GotenEqual(other interface{}) bool {
   566  	if other == nil {
   567  		return ref == nil
   568  	}
   569  	other1, ok := other.(*ParentReference)
   570  	if !ok {
   571  		other2, ok := other.(ParentReference)
   572  		if ok {
   573  			other1 = &other2
   574  		} else {
   575  			return false
   576  		}
   577  	}
   578  	if other1 == nil {
   579  		return ref == nil
   580  	} else if ref == nil {
   581  		return false
   582  	}
   583  	if ref.service != other1.service {
   584  		return false
   585  	}
   586  	if ref.organization != other1.organization {
   587  		return false
   588  	}
   589  
   590  	return ref.ParentName.GotenEqual(other1.ParentName)
   591  }
   592  
   593  // Matches is same as GotenEqual, but also will accept "other" if name is wildcard.
   594  func (name *ParentReference) Matches(other interface{}) bool {
   595  	if other == nil {
   596  		return name == nil
   597  	}
   598  	other1, ok := other.(*ParentReference)
   599  	if !ok {
   600  		other2, ok := other.(ParentReference)
   601  		if ok {
   602  			other1 = &other2
   603  		} else {
   604  			return false
   605  		}
   606  	}
   607  	if other1 == nil {
   608  		return name == nil
   609  	} else if name == nil {
   610  		return false
   611  	}
   612  	return name.ParentName.Matches(&other1.ParentName)
   613  }
   614  
   615  // implement CustomTypeCliValue method
   616  func (ref *ParentReference) SetFromCliFlag(raw string) error {
   617  	parsedRef, err := ParseParentReference(raw)
   618  	if err != nil {
   619  		return err
   620  	}
   621  	*ref = *parsedRef
   622  	return nil
   623  }