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

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