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

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