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

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