forked from emanic/gaia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheventlog.go
965 lines (799 loc) · 25.1 KB
/
eventlog.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
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
package gaia
import (
"fmt"
"time"
"github.com/globalsign/mgo/bson"
"github.com/mitchellh/copystructure"
"go.aporeto.io/elemental"
)
// EventLogLevelValue represents the possible values for attribute "level".
type EventLogLevelValue string
const (
// EventLogLevelCritical represents the value Critical.
EventLogLevelCritical EventLogLevelValue = "Critical"
// EventLogLevelDebug represents the value Debug.
EventLogLevelDebug EventLogLevelValue = "Debug"
// EventLogLevelError represents the value Error.
EventLogLevelError EventLogLevelValue = "Error"
// EventLogLevelInfo represents the value Info.
EventLogLevelInfo EventLogLevelValue = "Info"
// EventLogLevelWarning represents the value Warning.
EventLogLevelWarning EventLogLevelValue = "Warning"
)
// EventLogIdentity represents the Identity of the object.
var EventLogIdentity = elemental.Identity{
Name: "eventlog",
Category: "eventlogs",
Package: "leon",
Private: false,
}
// EventLogsList represents a list of EventLogs
type EventLogsList []*EventLog
// Identity returns the identity of the objects in the list.
func (o EventLogsList) Identity() elemental.Identity {
return EventLogIdentity
}
// Copy returns a pointer to a copy the EventLogsList.
func (o EventLogsList) Copy() elemental.Identifiables {
copy := append(EventLogsList{}, o...)
return ©
}
// Append appends the objects to the a new copy of the EventLogsList.
func (o EventLogsList) Append(objects ...elemental.Identifiable) elemental.Identifiables {
out := append(EventLogsList{}, o...)
for _, obj := range objects {
out = append(out, obj.(*EventLog))
}
return out
}
// List converts the object to an elemental.IdentifiablesList.
func (o EventLogsList) List() elemental.IdentifiablesList {
out := make(elemental.IdentifiablesList, len(o))
for i := 0; i < len(o); i++ {
out[i] = o[i]
}
return out
}
// DefaultOrder returns the default ordering fields of the content.
func (o EventLogsList) DefaultOrder() []string {
return []string{}
}
// ToSparse returns the EventLogsList converted to SparseEventLogsList.
// Objects in the list will only contain the given fields. No field means entire field set.
func (o EventLogsList) ToSparse(fields ...string) elemental.Identifiables {
out := make(SparseEventLogsList, len(o))
for i := 0; i < len(o); i++ {
out[i] = o[i].ToSparse(fields...).(*SparseEventLog)
}
return out
}
// Version returns the version of the content.
func (o EventLogsList) Version() int {
return 1
}
// EventLog represents the model of a eventlog
type EventLog struct {
// Category of the event log.
Category string `json:"category" msgpack:"category" bson:"category" mapstructure:"category,omitempty"`
// Content of the event log.
Content string `json:"content" msgpack:"content" bson:"content" mapstructure:"content,omitempty"`
// Creation date of the event log.
Date time.Time `json:"date" msgpack:"date" bson:"date" mapstructure:"date,omitempty"`
// Sets the log level.
Level EventLogLevelValue `json:"level" msgpack:"level" bson:"level" mapstructure:"level,omitempty"`
// Namespace tag attached to the event log.
Namespace string `json:"namespace" msgpack:"namespace" bson:"namespace" mapstructure:"namespace,omitempty"`
// Opaque data that can be attached to the event log, for further machine processing.
Opaque string `json:"opaque" msgpack:"opaque" bson:"opaque" mapstructure:"opaque,omitempty"`
// ID of the object this event log is attached to. The object must be in the same
// namespace than the event log.
TargetID string `json:"targetID" msgpack:"targetID" bson:"targetid" mapstructure:"targetID,omitempty"`
// Identity of the object this event log is attached to.
TargetIdentity string `json:"targetIdentity" msgpack:"targetIdentity" bson:"targetidentity" mapstructure:"targetIdentity,omitempty"`
// Title of the event log.
Title string `json:"title" msgpack:"title" bson:"title" mapstructure:"title,omitempty"`
ModelVersion int `json:"-" msgpack:"-" bson:"_modelversion"`
}
// NewEventLog returns a new *EventLog
func NewEventLog() *EventLog {
return &EventLog{
ModelVersion: 1,
Level: EventLogLevelInfo,
}
}
// Identity returns the Identity of the object.
func (o *EventLog) Identity() elemental.Identity {
return EventLogIdentity
}
// Identifier returns the value of the object's unique identifier.
func (o *EventLog) Identifier() string {
return ""
}
// SetIdentifier sets the value of the object's unique identifier.
func (o *EventLog) SetIdentifier(id string) {
}
// GetBSON implements the bson marshaling interface.
// This is used to transparently convert ID to MongoDBID as ObectID.
func (o *EventLog) GetBSON() (interface{}, error) {
if o == nil {
return nil, nil
}
s := &mongoAttributesEventLog{}
s.Category = o.Category
s.Content = o.Content
s.Date = o.Date
s.Level = o.Level
s.Namespace = o.Namespace
s.Opaque = o.Opaque
s.TargetID = o.TargetID
s.TargetIdentity = o.TargetIdentity
s.Title = o.Title
return s, nil
}
// SetBSON implements the bson marshaling interface.
// This is used to transparently convert ID to MongoDBID as ObectID.
func (o *EventLog) SetBSON(raw bson.Raw) error {
if o == nil {
return nil
}
s := &mongoAttributesEventLog{}
if err := raw.Unmarshal(s); err != nil {
return err
}
o.Category = s.Category
o.Content = s.Content
o.Date = s.Date
o.Level = s.Level
o.Namespace = s.Namespace
o.Opaque = s.Opaque
o.TargetID = s.TargetID
o.TargetIdentity = s.TargetIdentity
o.Title = s.Title
return nil
}
// Version returns the hardcoded version of the model.
func (o *EventLog) Version() int {
return 1
}
// BleveType implements the bleve.Classifier Interface.
func (o *EventLog) BleveType() string {
return "eventlog"
}
// DefaultOrder returns the list of default ordering fields.
func (o *EventLog) DefaultOrder() []string {
return []string{}
}
// Doc returns the documentation for the object
func (o *EventLog) Doc() string {
return `Allows you to report various events on any object.`
}
func (o *EventLog) String() string {
return fmt.Sprintf("<%s:%s>", o.Identity().Name, o.Identifier())
}
// GetNamespace returns the Namespace of the receiver.
func (o *EventLog) GetNamespace() string {
return o.Namespace
}
// SetNamespace sets the property Namespace of the receiver using the given value.
func (o *EventLog) SetNamespace(namespace string) {
o.Namespace = namespace
}
// ToSparse returns the sparse version of the model.
// The returned object will only contain the given fields. No field means entire field set.
func (o *EventLog) ToSparse(fields ...string) elemental.SparseIdentifiable {
if len(fields) == 0 {
// nolint: goimports
return &SparseEventLog{
Category: &o.Category,
Content: &o.Content,
Date: &o.Date,
Level: &o.Level,
Namespace: &o.Namespace,
Opaque: &o.Opaque,
TargetID: &o.TargetID,
TargetIdentity: &o.TargetIdentity,
Title: &o.Title,
}
}
sp := &SparseEventLog{}
for _, f := range fields {
switch f {
case "category":
sp.Category = &(o.Category)
case "content":
sp.Content = &(o.Content)
case "date":
sp.Date = &(o.Date)
case "level":
sp.Level = &(o.Level)
case "namespace":
sp.Namespace = &(o.Namespace)
case "opaque":
sp.Opaque = &(o.Opaque)
case "targetID":
sp.TargetID = &(o.TargetID)
case "targetIdentity":
sp.TargetIdentity = &(o.TargetIdentity)
case "title":
sp.Title = &(o.Title)
}
}
return sp
}
// Patch apply the non nil value of a *SparseEventLog to the object.
func (o *EventLog) Patch(sparse elemental.SparseIdentifiable) {
if !sparse.Identity().IsEqual(o.Identity()) {
panic("cannot patch from a parse with different identity")
}
so := sparse.(*SparseEventLog)
if so.Category != nil {
o.Category = *so.Category
}
if so.Content != nil {
o.Content = *so.Content
}
if so.Date != nil {
o.Date = *so.Date
}
if so.Level != nil {
o.Level = *so.Level
}
if so.Namespace != nil {
o.Namespace = *so.Namespace
}
if so.Opaque != nil {
o.Opaque = *so.Opaque
}
if so.TargetID != nil {
o.TargetID = *so.TargetID
}
if so.TargetIdentity != nil {
o.TargetIdentity = *so.TargetIdentity
}
if so.Title != nil {
o.Title = *so.Title
}
}
// DeepCopy returns a deep copy if the EventLog.
func (o *EventLog) DeepCopy() *EventLog {
if o == nil {
return nil
}
out := &EventLog{}
o.DeepCopyInto(out)
return out
}
// DeepCopyInto copies the receiver into the given *EventLog.
func (o *EventLog) DeepCopyInto(out *EventLog) {
target, err := copystructure.Copy(o)
if err != nil {
panic(fmt.Sprintf("Unable to deepcopy EventLog: %s", err))
}
*out = *target.(*EventLog)
}
// Validate valides the current information stored into the structure.
func (o *EventLog) Validate() error {
errors := elemental.Errors{}
requiredErrors := elemental.Errors{}
if err := elemental.ValidateRequiredString("category", o.Category); err != nil {
requiredErrors = requiredErrors.Append(err)
}
if err := elemental.ValidateRequiredString("content", o.Content); err != nil {
requiredErrors = requiredErrors.Append(err)
}
if err := elemental.ValidateStringInList("level", string(o.Level), []string{"Debug", "Info", "Warning", "Error", "Critical"}, false); err != nil {
errors = errors.Append(err)
}
if err := elemental.ValidateRequiredString("targetID", o.TargetID); err != nil {
requiredErrors = requiredErrors.Append(err)
}
if err := elemental.ValidateRequiredString("targetIdentity", o.TargetIdentity); err != nil {
requiredErrors = requiredErrors.Append(err)
}
if err := elemental.ValidateRequiredString("title", o.Title); err != nil {
requiredErrors = requiredErrors.Append(err)
}
if len(requiredErrors) > 0 {
return requiredErrors
}
if len(errors) > 0 {
return errors
}
return nil
}
// SpecificationForAttribute returns the AttributeSpecification for the given attribute name key.
func (*EventLog) SpecificationForAttribute(name string) elemental.AttributeSpecification {
if v, ok := EventLogAttributesMap[name]; ok {
return v
}
// We could not find it, so let's check on the lower case indexed spec map
return EventLogLowerCaseAttributesMap[name]
}
// AttributeSpecifications returns the full attribute specifications map.
func (*EventLog) AttributeSpecifications() map[string]elemental.AttributeSpecification {
return EventLogAttributesMap
}
// ValueForAttribute returns the value for the given attribute.
// This is a very advanced function that you should not need but in some
// very specific use cases.
func (o *EventLog) ValueForAttribute(name string) interface{} {
switch name {
case "category":
return o.Category
case "content":
return o.Content
case "date":
return o.Date
case "level":
return o.Level
case "namespace":
return o.Namespace
case "opaque":
return o.Opaque
case "targetID":
return o.TargetID
case "targetIdentity":
return o.TargetIdentity
case "title":
return o.Title
}
return nil
}
// EventLogAttributesMap represents the map of attribute for EventLog.
var EventLogAttributesMap = map[string]elemental.AttributeSpecification{
"Category": elemental.AttributeSpecification{
AllowedChoices: []string{},
ConvertedName: "Category",
CreationOnly: true,
Description: `Category of the event log.`,
Exposed: true,
Name: "category",
Required: true,
Stored: true,
Type: "string",
},
"Content": elemental.AttributeSpecification{
AllowedChoices: []string{},
ConvertedName: "Content",
CreationOnly: true,
Description: `Content of the event log.`,
Exposed: true,
Name: "content",
Required: true,
Stored: true,
Type: "string",
},
"Date": elemental.AttributeSpecification{
AllowedChoices: []string{},
Autogenerated: true,
ConvertedName: "Date",
CreationOnly: true,
Description: `Creation date of the event log.`,
Exposed: true,
Name: "date",
Orderable: true,
Stored: true,
Type: "time",
},
"Level": elemental.AttributeSpecification{
AllowedChoices: []string{"Debug", "Info", "Warning", "Error", "Critical"},
ConvertedName: "Level",
CreationOnly: true,
DefaultValue: EventLogLevelInfo,
Description: `Sets the log level.`,
Exposed: true,
Name: "level",
Stored: true,
Type: "enum",
},
"Namespace": elemental.AttributeSpecification{
AllowedChoices: []string{},
Autogenerated: true,
ConvertedName: "Namespace",
CreationOnly: true,
Description: `Namespace tag attached to the event log.`,
Exposed: true,
Getter: true,
Name: "namespace",
Orderable: true,
ReadOnly: true,
Setter: true,
Stored: true,
Type: "string",
},
"Opaque": elemental.AttributeSpecification{
AllowedChoices: []string{},
ConvertedName: "Opaque",
CreationOnly: true,
Description: `Opaque data that can be attached to the event log, for further machine processing.`,
Exposed: true,
Name: "opaque",
Orderable: true,
Stored: true,
Type: "string",
},
"TargetID": elemental.AttributeSpecification{
AllowedChoices: []string{},
ConvertedName: "TargetID",
CreationOnly: true,
Description: `ID of the object this event log is attached to. The object must be in the same
namespace than the event log.`,
Exposed: true,
Name: "targetID",
Required: true,
Stored: true,
Type: "string",
},
"TargetIdentity": elemental.AttributeSpecification{
AllowedChoices: []string{},
ConvertedName: "TargetIdentity",
CreationOnly: true,
Description: `Identity of the object this event log is attached to.`,
Exposed: true,
Name: "targetIdentity",
Required: true,
Stored: true,
Type: "string",
},
"Title": elemental.AttributeSpecification{
AllowedChoices: []string{},
ConvertedName: "Title",
CreationOnly: true,
Description: `Title of the event log.`,
Exposed: true,
Name: "title",
Required: true,
Stored: true,
Type: "string",
},
}
// EventLogLowerCaseAttributesMap represents the map of attribute for EventLog.
var EventLogLowerCaseAttributesMap = map[string]elemental.AttributeSpecification{
"category": elemental.AttributeSpecification{
AllowedChoices: []string{},
ConvertedName: "Category",
CreationOnly: true,
Description: `Category of the event log.`,
Exposed: true,
Name: "category",
Required: true,
Stored: true,
Type: "string",
},
"content": elemental.AttributeSpecification{
AllowedChoices: []string{},
ConvertedName: "Content",
CreationOnly: true,
Description: `Content of the event log.`,
Exposed: true,
Name: "content",
Required: true,
Stored: true,
Type: "string",
},
"date": elemental.AttributeSpecification{
AllowedChoices: []string{},
Autogenerated: true,
ConvertedName: "Date",
CreationOnly: true,
Description: `Creation date of the event log.`,
Exposed: true,
Name: "date",
Orderable: true,
Stored: true,
Type: "time",
},
"level": elemental.AttributeSpecification{
AllowedChoices: []string{"Debug", "Info", "Warning", "Error", "Critical"},
ConvertedName: "Level",
CreationOnly: true,
DefaultValue: EventLogLevelInfo,
Description: `Sets the log level.`,
Exposed: true,
Name: "level",
Stored: true,
Type: "enum",
},
"namespace": elemental.AttributeSpecification{
AllowedChoices: []string{},
Autogenerated: true,
ConvertedName: "Namespace",
CreationOnly: true,
Description: `Namespace tag attached to the event log.`,
Exposed: true,
Getter: true,
Name: "namespace",
Orderable: true,
ReadOnly: true,
Setter: true,
Stored: true,
Type: "string",
},
"opaque": elemental.AttributeSpecification{
AllowedChoices: []string{},
ConvertedName: "Opaque",
CreationOnly: true,
Description: `Opaque data that can be attached to the event log, for further machine processing.`,
Exposed: true,
Name: "opaque",
Orderable: true,
Stored: true,
Type: "string",
},
"targetid": elemental.AttributeSpecification{
AllowedChoices: []string{},
ConvertedName: "TargetID",
CreationOnly: true,
Description: `ID of the object this event log is attached to. The object must be in the same
namespace than the event log.`,
Exposed: true,
Name: "targetID",
Required: true,
Stored: true,
Type: "string",
},
"targetidentity": elemental.AttributeSpecification{
AllowedChoices: []string{},
ConvertedName: "TargetIdentity",
CreationOnly: true,
Description: `Identity of the object this event log is attached to.`,
Exposed: true,
Name: "targetIdentity",
Required: true,
Stored: true,
Type: "string",
},
"title": elemental.AttributeSpecification{
AllowedChoices: []string{},
ConvertedName: "Title",
CreationOnly: true,
Description: `Title of the event log.`,
Exposed: true,
Name: "title",
Required: true,
Stored: true,
Type: "string",
},
}
// SparseEventLogsList represents a list of SparseEventLogs
type SparseEventLogsList []*SparseEventLog
// Identity returns the identity of the objects in the list.
func (o SparseEventLogsList) Identity() elemental.Identity {
return EventLogIdentity
}
// Copy returns a pointer to a copy the SparseEventLogsList.
func (o SparseEventLogsList) Copy() elemental.Identifiables {
copy := append(SparseEventLogsList{}, o...)
return ©
}
// Append appends the objects to the a new copy of the SparseEventLogsList.
func (o SparseEventLogsList) Append(objects ...elemental.Identifiable) elemental.Identifiables {
out := append(SparseEventLogsList{}, o...)
for _, obj := range objects {
out = append(out, obj.(*SparseEventLog))
}
return out
}
// List converts the object to an elemental.IdentifiablesList.
func (o SparseEventLogsList) List() elemental.IdentifiablesList {
out := make(elemental.IdentifiablesList, len(o))
for i := 0; i < len(o); i++ {
out[i] = o[i]
}
return out
}
// DefaultOrder returns the default ordering fields of the content.
func (o SparseEventLogsList) DefaultOrder() []string {
return []string{}
}
// ToPlain returns the SparseEventLogsList converted to EventLogsList.
func (o SparseEventLogsList) ToPlain() elemental.IdentifiablesList {
out := make(elemental.IdentifiablesList, len(o))
for i := 0; i < len(o); i++ {
out[i] = o[i].ToPlain()
}
return out
}
// Version returns the version of the content.
func (o SparseEventLogsList) Version() int {
return 1
}
// SparseEventLog represents the sparse version of a eventlog.
type SparseEventLog struct {
// Category of the event log.
Category *string `json:"category,omitempty" msgpack:"category,omitempty" bson:"category,omitempty" mapstructure:"category,omitempty"`
// Content of the event log.
Content *string `json:"content,omitempty" msgpack:"content,omitempty" bson:"content,omitempty" mapstructure:"content,omitempty"`
// Creation date of the event log.
Date *time.Time `json:"date,omitempty" msgpack:"date,omitempty" bson:"date,omitempty" mapstructure:"date,omitempty"`
// Sets the log level.
Level *EventLogLevelValue `json:"level,omitempty" msgpack:"level,omitempty" bson:"level,omitempty" mapstructure:"level,omitempty"`
// Namespace tag attached to the event log.
Namespace *string `json:"namespace,omitempty" msgpack:"namespace,omitempty" bson:"namespace,omitempty" mapstructure:"namespace,omitempty"`
// Opaque data that can be attached to the event log, for further machine processing.
Opaque *string `json:"opaque,omitempty" msgpack:"opaque,omitempty" bson:"opaque,omitempty" mapstructure:"opaque,omitempty"`
// ID of the object this event log is attached to. The object must be in the same
// namespace than the event log.
TargetID *string `json:"targetID,omitempty" msgpack:"targetID,omitempty" bson:"targetid,omitempty" mapstructure:"targetID,omitempty"`
// Identity of the object this event log is attached to.
TargetIdentity *string `json:"targetIdentity,omitempty" msgpack:"targetIdentity,omitempty" bson:"targetidentity,omitempty" mapstructure:"targetIdentity,omitempty"`
// Title of the event log.
Title *string `json:"title,omitempty" msgpack:"title,omitempty" bson:"title,omitempty" mapstructure:"title,omitempty"`
ModelVersion int `json:"-" msgpack:"-" bson:"_modelversion"`
}
// NewSparseEventLog returns a new SparseEventLog.
func NewSparseEventLog() *SparseEventLog {
return &SparseEventLog{}
}
// Identity returns the Identity of the sparse object.
func (o *SparseEventLog) Identity() elemental.Identity {
return EventLogIdentity
}
// Identifier returns the value of the sparse object's unique identifier.
func (o *SparseEventLog) Identifier() string {
return ""
}
// SetIdentifier sets the value of the sparse object's unique identifier.
func (o *SparseEventLog) SetIdentifier(id string) {
}
// GetBSON implements the bson marshaling interface.
// This is used to transparently convert ID to MongoDBID as ObectID.
func (o *SparseEventLog) GetBSON() (interface{}, error) {
if o == nil {
return nil, nil
}
s := &mongoAttributesSparseEventLog{}
if o.Category != nil {
s.Category = o.Category
}
if o.Content != nil {
s.Content = o.Content
}
if o.Date != nil {
s.Date = o.Date
}
if o.Level != nil {
s.Level = o.Level
}
if o.Namespace != nil {
s.Namespace = o.Namespace
}
if o.Opaque != nil {
s.Opaque = o.Opaque
}
if o.TargetID != nil {
s.TargetID = o.TargetID
}
if o.TargetIdentity != nil {
s.TargetIdentity = o.TargetIdentity
}
if o.Title != nil {
s.Title = o.Title
}
return s, nil
}
// SetBSON implements the bson marshaling interface.
// This is used to transparently convert ID to MongoDBID as ObectID.
func (o *SparseEventLog) SetBSON(raw bson.Raw) error {
if o == nil {
return nil
}
s := &mongoAttributesSparseEventLog{}
if err := raw.Unmarshal(s); err != nil {
return err
}
if s.Category != nil {
o.Category = s.Category
}
if s.Content != nil {
o.Content = s.Content
}
if s.Date != nil {
o.Date = s.Date
}
if s.Level != nil {
o.Level = s.Level
}
if s.Namespace != nil {
o.Namespace = s.Namespace
}
if s.Opaque != nil {
o.Opaque = s.Opaque
}
if s.TargetID != nil {
o.TargetID = s.TargetID
}
if s.TargetIdentity != nil {
o.TargetIdentity = s.TargetIdentity
}
if s.Title != nil {
o.Title = s.Title
}
return nil
}
// Version returns the hardcoded version of the model.
func (o *SparseEventLog) Version() int {
return 1
}
// ToPlain returns the plain version of the sparse model.
func (o *SparseEventLog) ToPlain() elemental.PlainIdentifiable {
out := NewEventLog()
if o.Category != nil {
out.Category = *o.Category
}
if o.Content != nil {
out.Content = *o.Content
}
if o.Date != nil {
out.Date = *o.Date
}
if o.Level != nil {
out.Level = *o.Level
}
if o.Namespace != nil {
out.Namespace = *o.Namespace
}
if o.Opaque != nil {
out.Opaque = *o.Opaque
}
if o.TargetID != nil {
out.TargetID = *o.TargetID
}
if o.TargetIdentity != nil {
out.TargetIdentity = *o.TargetIdentity
}
if o.Title != nil {
out.Title = *o.Title
}
return out
}
// GetNamespace returns the Namespace of the receiver.
func (o *SparseEventLog) GetNamespace() (out string) {
if o.Namespace == nil {
return
}
return *o.Namespace
}
// SetNamespace sets the property Namespace of the receiver using the address of the given value.
func (o *SparseEventLog) SetNamespace(namespace string) {
o.Namespace = &namespace
}
// DeepCopy returns a deep copy if the SparseEventLog.
func (o *SparseEventLog) DeepCopy() *SparseEventLog {
if o == nil {
return nil
}
out := &SparseEventLog{}
o.DeepCopyInto(out)
return out
}
// DeepCopyInto copies the receiver into the given *SparseEventLog.
func (o *SparseEventLog) DeepCopyInto(out *SparseEventLog) {
target, err := copystructure.Copy(o)
if err != nil {
panic(fmt.Sprintf("Unable to deepcopy SparseEventLog: %s", err))
}
*out = *target.(*SparseEventLog)
}
type mongoAttributesEventLog struct {
Category string `bson:"category"`
Content string `bson:"content"`
Date time.Time `bson:"date"`
Level EventLogLevelValue `bson:"level"`
Namespace string `bson:"namespace"`
Opaque string `bson:"opaque"`
TargetID string `bson:"targetid"`
TargetIdentity string `bson:"targetidentity"`
Title string `bson:"title"`
}
type mongoAttributesSparseEventLog struct {
Category *string `bson:"category,omitempty"`
Content *string `bson:"content,omitempty"`
Date *time.Time `bson:"date,omitempty"`
Level *EventLogLevelValue `bson:"level,omitempty"`
Namespace *string `bson:"namespace,omitempty"`
Opaque *string `bson:"opaque,omitempty"`
TargetID *string `bson:"targetid,omitempty"`
TargetIdentity *string `bson:"targetidentity,omitempty"`
Title *string `bson:"title,omitempty"`
}