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