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