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

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