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