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

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