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

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