github.com/cloudwan/edgelq-sdk@v1.15.4/logging/resources/v1/bucket/bucket.pb.name.go (about)

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