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

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