-
Notifications
You must be signed in to change notification settings - Fork 459
/
mutation.go
7001 lines (6375 loc) · 202 KB
/
mutation.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
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Code generated by entc, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"sync"
"time"
"github.com/crowdsecurity/crowdsec/pkg/database/ent/alert"
"github.com/crowdsecurity/crowdsec/pkg/database/ent/bouncer"
"github.com/crowdsecurity/crowdsec/pkg/database/ent/decision"
"github.com/crowdsecurity/crowdsec/pkg/database/ent/event"
"github.com/crowdsecurity/crowdsec/pkg/database/ent/machine"
"github.com/crowdsecurity/crowdsec/pkg/database/ent/meta"
"github.com/crowdsecurity/crowdsec/pkg/database/ent/predicate"
"entgo.io/ent"
)
const (
// Operation types.
OpCreate = ent.OpCreate
OpDelete = ent.OpDelete
OpDeleteOne = ent.OpDeleteOne
OpUpdate = ent.OpUpdate
OpUpdateOne = ent.OpUpdateOne
// Node types.
TypeAlert = "Alert"
TypeBouncer = "Bouncer"
TypeDecision = "Decision"
TypeEvent = "Event"
TypeMachine = "Machine"
TypeMeta = "Meta"
)
// AlertMutation represents an operation that mutates the Alert nodes in the graph.
type AlertMutation struct {
config
op Op
typ string
id *int
created_at *time.Time
updated_at *time.Time
scenario *string
bucketId *string
message *string
eventsCount *int32
addeventsCount *int32
startedAt *time.Time
stoppedAt *time.Time
sourceIp *string
sourceRange *string
sourceAsNumber *string
sourceAsName *string
sourceCountry *string
sourceLatitude *float32
addsourceLatitude *float32
sourceLongitude *float32
addsourceLongitude *float32
sourceScope *string
sourceValue *string
capacity *int32
addcapacity *int32
leakSpeed *string
scenarioVersion *string
scenarioHash *string
simulated *bool
clearedFields map[string]struct{}
owner *int
clearedowner bool
decisions map[int]struct{}
removeddecisions map[int]struct{}
cleareddecisions bool
events map[int]struct{}
removedevents map[int]struct{}
clearedevents bool
metas map[int]struct{}
removedmetas map[int]struct{}
clearedmetas bool
done bool
oldValue func(context.Context) (*Alert, error)
predicates []predicate.Alert
}
var _ ent.Mutation = (*AlertMutation)(nil)
// alertOption allows management of the mutation configuration using functional options.
type alertOption func(*AlertMutation)
// newAlertMutation creates new mutation for the Alert entity.
func newAlertMutation(c config, op Op, opts ...alertOption) *AlertMutation {
m := &AlertMutation{
config: c,
op: op,
typ: TypeAlert,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withAlertID sets the ID field of the mutation.
func withAlertID(id int) alertOption {
return func(m *AlertMutation) {
var (
err error
once sync.Once
value *Alert
)
m.oldValue = func(ctx context.Context) (*Alert, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().Alert.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withAlert sets the old Alert of the mutation.
func withAlert(node *Alert) alertOption {
return func(m *AlertMutation) {
m.oldValue = func(context.Context) (*Alert, error) {
return node, nil
}
m.id = &node.ID
}
}
// Client returns a new `ent.Client` from the mutation. If the mutation was
// executed in a transaction (ent.Tx), a transactional client is returned.
func (m AlertMutation) Client() *Client {
client := &Client{config: m.config}
client.init()
return client
}
// Tx returns an `ent.Tx` for mutations that were executed in transactions;
// it returns an error otherwise.
func (m AlertMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, errors.New("ent: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
return tx, nil
}
// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *AlertMutation) ID() (id int, exists bool) {
if m.id == nil {
return
}
return *m.id, true
}
// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *AlertMutation) IDs(ctx context.Context) ([]int, error) {
switch {
case m.op.Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []int{id}, nil
}
fallthrough
case m.op.Is(OpUpdate | OpDelete):
return m.Client().Alert.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetCreatedAt sets the "created_at" field.
func (m *AlertMutation) SetCreatedAt(t time.Time) {
m.created_at = &t
}
// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *AlertMutation) CreatedAt() (r time.Time, exists bool) {
v := m.created_at
if v == nil {
return
}
return *v, true
}
// OldCreatedAt returns the old "created_at" field's value of the Alert entity.
// If the Alert object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AlertMutation) OldCreatedAt(ctx context.Context) (v *time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCreatedAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
}
return oldValue.CreatedAt, nil
}
// ClearCreatedAt clears the value of the "created_at" field.
func (m *AlertMutation) ClearCreatedAt() {
m.created_at = nil
m.clearedFields[alert.FieldCreatedAt] = struct{}{}
}
// CreatedAtCleared returns if the "created_at" field was cleared in this mutation.
func (m *AlertMutation) CreatedAtCleared() bool {
_, ok := m.clearedFields[alert.FieldCreatedAt]
return ok
}
// ResetCreatedAt resets all changes to the "created_at" field.
func (m *AlertMutation) ResetCreatedAt() {
m.created_at = nil
delete(m.clearedFields, alert.FieldCreatedAt)
}
// SetUpdatedAt sets the "updated_at" field.
func (m *AlertMutation) SetUpdatedAt(t time.Time) {
m.updated_at = &t
}
// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *AlertMutation) UpdatedAt() (r time.Time, exists bool) {
v := m.updated_at
if v == nil {
return
}
return *v, true
}
// OldUpdatedAt returns the old "updated_at" field's value of the Alert entity.
// If the Alert object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AlertMutation) OldUpdatedAt(ctx context.Context) (v *time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
}
return oldValue.UpdatedAt, nil
}
// ClearUpdatedAt clears the value of the "updated_at" field.
func (m *AlertMutation) ClearUpdatedAt() {
m.updated_at = nil
m.clearedFields[alert.FieldUpdatedAt] = struct{}{}
}
// UpdatedAtCleared returns if the "updated_at" field was cleared in this mutation.
func (m *AlertMutation) UpdatedAtCleared() bool {
_, ok := m.clearedFields[alert.FieldUpdatedAt]
return ok
}
// ResetUpdatedAt resets all changes to the "updated_at" field.
func (m *AlertMutation) ResetUpdatedAt() {
m.updated_at = nil
delete(m.clearedFields, alert.FieldUpdatedAt)
}
// SetScenario sets the "scenario" field.
func (m *AlertMutation) SetScenario(s string) {
m.scenario = &s
}
// Scenario returns the value of the "scenario" field in the mutation.
func (m *AlertMutation) Scenario() (r string, exists bool) {
v := m.scenario
if v == nil {
return
}
return *v, true
}
// OldScenario returns the old "scenario" field's value of the Alert entity.
// If the Alert object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AlertMutation) OldScenario(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldScenario is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldScenario requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldScenario: %w", err)
}
return oldValue.Scenario, nil
}
// ResetScenario resets all changes to the "scenario" field.
func (m *AlertMutation) ResetScenario() {
m.scenario = nil
}
// SetBucketId sets the "bucketId" field.
func (m *AlertMutation) SetBucketId(s string) {
m.bucketId = &s
}
// BucketId returns the value of the "bucketId" field in the mutation.
func (m *AlertMutation) BucketId() (r string, exists bool) {
v := m.bucketId
if v == nil {
return
}
return *v, true
}
// OldBucketId returns the old "bucketId" field's value of the Alert entity.
// If the Alert object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AlertMutation) OldBucketId(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldBucketId is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldBucketId requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldBucketId: %w", err)
}
return oldValue.BucketId, nil
}
// ClearBucketId clears the value of the "bucketId" field.
func (m *AlertMutation) ClearBucketId() {
m.bucketId = nil
m.clearedFields[alert.FieldBucketId] = struct{}{}
}
// BucketIdCleared returns if the "bucketId" field was cleared in this mutation.
func (m *AlertMutation) BucketIdCleared() bool {
_, ok := m.clearedFields[alert.FieldBucketId]
return ok
}
// ResetBucketId resets all changes to the "bucketId" field.
func (m *AlertMutation) ResetBucketId() {
m.bucketId = nil
delete(m.clearedFields, alert.FieldBucketId)
}
// SetMessage sets the "message" field.
func (m *AlertMutation) SetMessage(s string) {
m.message = &s
}
// Message returns the value of the "message" field in the mutation.
func (m *AlertMutation) Message() (r string, exists bool) {
v := m.message
if v == nil {
return
}
return *v, true
}
// OldMessage returns the old "message" field's value of the Alert entity.
// If the Alert object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AlertMutation) OldMessage(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldMessage is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldMessage requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldMessage: %w", err)
}
return oldValue.Message, nil
}
// ClearMessage clears the value of the "message" field.
func (m *AlertMutation) ClearMessage() {
m.message = nil
m.clearedFields[alert.FieldMessage] = struct{}{}
}
// MessageCleared returns if the "message" field was cleared in this mutation.
func (m *AlertMutation) MessageCleared() bool {
_, ok := m.clearedFields[alert.FieldMessage]
return ok
}
// ResetMessage resets all changes to the "message" field.
func (m *AlertMutation) ResetMessage() {
m.message = nil
delete(m.clearedFields, alert.FieldMessage)
}
// SetEventsCount sets the "eventsCount" field.
func (m *AlertMutation) SetEventsCount(i int32) {
m.eventsCount = &i
m.addeventsCount = nil
}
// EventsCount returns the value of the "eventsCount" field in the mutation.
func (m *AlertMutation) EventsCount() (r int32, exists bool) {
v := m.eventsCount
if v == nil {
return
}
return *v, true
}
// OldEventsCount returns the old "eventsCount" field's value of the Alert entity.
// If the Alert object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AlertMutation) OldEventsCount(ctx context.Context) (v int32, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldEventsCount is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldEventsCount requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldEventsCount: %w", err)
}
return oldValue.EventsCount, nil
}
// AddEventsCount adds i to the "eventsCount" field.
func (m *AlertMutation) AddEventsCount(i int32) {
if m.addeventsCount != nil {
*m.addeventsCount += i
} else {
m.addeventsCount = &i
}
}
// AddedEventsCount returns the value that was added to the "eventsCount" field in this mutation.
func (m *AlertMutation) AddedEventsCount() (r int32, exists bool) {
v := m.addeventsCount
if v == nil {
return
}
return *v, true
}
// ClearEventsCount clears the value of the "eventsCount" field.
func (m *AlertMutation) ClearEventsCount() {
m.eventsCount = nil
m.addeventsCount = nil
m.clearedFields[alert.FieldEventsCount] = struct{}{}
}
// EventsCountCleared returns if the "eventsCount" field was cleared in this mutation.
func (m *AlertMutation) EventsCountCleared() bool {
_, ok := m.clearedFields[alert.FieldEventsCount]
return ok
}
// ResetEventsCount resets all changes to the "eventsCount" field.
func (m *AlertMutation) ResetEventsCount() {
m.eventsCount = nil
m.addeventsCount = nil
delete(m.clearedFields, alert.FieldEventsCount)
}
// SetStartedAt sets the "startedAt" field.
func (m *AlertMutation) SetStartedAt(t time.Time) {
m.startedAt = &t
}
// StartedAt returns the value of the "startedAt" field in the mutation.
func (m *AlertMutation) StartedAt() (r time.Time, exists bool) {
v := m.startedAt
if v == nil {
return
}
return *v, true
}
// OldStartedAt returns the old "startedAt" field's value of the Alert entity.
// If the Alert object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AlertMutation) OldStartedAt(ctx context.Context) (v time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldStartedAt is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldStartedAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldStartedAt: %w", err)
}
return oldValue.StartedAt, nil
}
// ClearStartedAt clears the value of the "startedAt" field.
func (m *AlertMutation) ClearStartedAt() {
m.startedAt = nil
m.clearedFields[alert.FieldStartedAt] = struct{}{}
}
// StartedAtCleared returns if the "startedAt" field was cleared in this mutation.
func (m *AlertMutation) StartedAtCleared() bool {
_, ok := m.clearedFields[alert.FieldStartedAt]
return ok
}
// ResetStartedAt resets all changes to the "startedAt" field.
func (m *AlertMutation) ResetStartedAt() {
m.startedAt = nil
delete(m.clearedFields, alert.FieldStartedAt)
}
// SetStoppedAt sets the "stoppedAt" field.
func (m *AlertMutation) SetStoppedAt(t time.Time) {
m.stoppedAt = &t
}
// StoppedAt returns the value of the "stoppedAt" field in the mutation.
func (m *AlertMutation) StoppedAt() (r time.Time, exists bool) {
v := m.stoppedAt
if v == nil {
return
}
return *v, true
}
// OldStoppedAt returns the old "stoppedAt" field's value of the Alert entity.
// If the Alert object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AlertMutation) OldStoppedAt(ctx context.Context) (v time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldStoppedAt is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldStoppedAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldStoppedAt: %w", err)
}
return oldValue.StoppedAt, nil
}
// ClearStoppedAt clears the value of the "stoppedAt" field.
func (m *AlertMutation) ClearStoppedAt() {
m.stoppedAt = nil
m.clearedFields[alert.FieldStoppedAt] = struct{}{}
}
// StoppedAtCleared returns if the "stoppedAt" field was cleared in this mutation.
func (m *AlertMutation) StoppedAtCleared() bool {
_, ok := m.clearedFields[alert.FieldStoppedAt]
return ok
}
// ResetStoppedAt resets all changes to the "stoppedAt" field.
func (m *AlertMutation) ResetStoppedAt() {
m.stoppedAt = nil
delete(m.clearedFields, alert.FieldStoppedAt)
}
// SetSourceIp sets the "sourceIp" field.
func (m *AlertMutation) SetSourceIp(s string) {
m.sourceIp = &s
}
// SourceIp returns the value of the "sourceIp" field in the mutation.
func (m *AlertMutation) SourceIp() (r string, exists bool) {
v := m.sourceIp
if v == nil {
return
}
return *v, true
}
// OldSourceIp returns the old "sourceIp" field's value of the Alert entity.
// If the Alert object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AlertMutation) OldSourceIp(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldSourceIp is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldSourceIp requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldSourceIp: %w", err)
}
return oldValue.SourceIp, nil
}
// ClearSourceIp clears the value of the "sourceIp" field.
func (m *AlertMutation) ClearSourceIp() {
m.sourceIp = nil
m.clearedFields[alert.FieldSourceIp] = struct{}{}
}
// SourceIpCleared returns if the "sourceIp" field was cleared in this mutation.
func (m *AlertMutation) SourceIpCleared() bool {
_, ok := m.clearedFields[alert.FieldSourceIp]
return ok
}
// ResetSourceIp resets all changes to the "sourceIp" field.
func (m *AlertMutation) ResetSourceIp() {
m.sourceIp = nil
delete(m.clearedFields, alert.FieldSourceIp)
}
// SetSourceRange sets the "sourceRange" field.
func (m *AlertMutation) SetSourceRange(s string) {
m.sourceRange = &s
}
// SourceRange returns the value of the "sourceRange" field in the mutation.
func (m *AlertMutation) SourceRange() (r string, exists bool) {
v := m.sourceRange
if v == nil {
return
}
return *v, true
}
// OldSourceRange returns the old "sourceRange" field's value of the Alert entity.
// If the Alert object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AlertMutation) OldSourceRange(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldSourceRange is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldSourceRange requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldSourceRange: %w", err)
}
return oldValue.SourceRange, nil
}
// ClearSourceRange clears the value of the "sourceRange" field.
func (m *AlertMutation) ClearSourceRange() {
m.sourceRange = nil
m.clearedFields[alert.FieldSourceRange] = struct{}{}
}
// SourceRangeCleared returns if the "sourceRange" field was cleared in this mutation.
func (m *AlertMutation) SourceRangeCleared() bool {
_, ok := m.clearedFields[alert.FieldSourceRange]
return ok
}
// ResetSourceRange resets all changes to the "sourceRange" field.
func (m *AlertMutation) ResetSourceRange() {
m.sourceRange = nil
delete(m.clearedFields, alert.FieldSourceRange)
}
// SetSourceAsNumber sets the "sourceAsNumber" field.
func (m *AlertMutation) SetSourceAsNumber(s string) {
m.sourceAsNumber = &s
}
// SourceAsNumber returns the value of the "sourceAsNumber" field in the mutation.
func (m *AlertMutation) SourceAsNumber() (r string, exists bool) {
v := m.sourceAsNumber
if v == nil {
return
}
return *v, true
}
// OldSourceAsNumber returns the old "sourceAsNumber" field's value of the Alert entity.
// If the Alert object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AlertMutation) OldSourceAsNumber(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldSourceAsNumber is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldSourceAsNumber requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldSourceAsNumber: %w", err)
}
return oldValue.SourceAsNumber, nil
}
// ClearSourceAsNumber clears the value of the "sourceAsNumber" field.
func (m *AlertMutation) ClearSourceAsNumber() {
m.sourceAsNumber = nil
m.clearedFields[alert.FieldSourceAsNumber] = struct{}{}
}
// SourceAsNumberCleared returns if the "sourceAsNumber" field was cleared in this mutation.
func (m *AlertMutation) SourceAsNumberCleared() bool {
_, ok := m.clearedFields[alert.FieldSourceAsNumber]
return ok
}
// ResetSourceAsNumber resets all changes to the "sourceAsNumber" field.
func (m *AlertMutation) ResetSourceAsNumber() {
m.sourceAsNumber = nil
delete(m.clearedFields, alert.FieldSourceAsNumber)
}
// SetSourceAsName sets the "sourceAsName" field.
func (m *AlertMutation) SetSourceAsName(s string) {
m.sourceAsName = &s
}
// SourceAsName returns the value of the "sourceAsName" field in the mutation.
func (m *AlertMutation) SourceAsName() (r string, exists bool) {
v := m.sourceAsName
if v == nil {
return
}
return *v, true
}
// OldSourceAsName returns the old "sourceAsName" field's value of the Alert entity.
// If the Alert object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AlertMutation) OldSourceAsName(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldSourceAsName is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldSourceAsName requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldSourceAsName: %w", err)
}
return oldValue.SourceAsName, nil
}
// ClearSourceAsName clears the value of the "sourceAsName" field.
func (m *AlertMutation) ClearSourceAsName() {
m.sourceAsName = nil
m.clearedFields[alert.FieldSourceAsName] = struct{}{}
}
// SourceAsNameCleared returns if the "sourceAsName" field was cleared in this mutation.
func (m *AlertMutation) SourceAsNameCleared() bool {
_, ok := m.clearedFields[alert.FieldSourceAsName]
return ok
}
// ResetSourceAsName resets all changes to the "sourceAsName" field.
func (m *AlertMutation) ResetSourceAsName() {
m.sourceAsName = nil
delete(m.clearedFields, alert.FieldSourceAsName)
}
// SetSourceCountry sets the "sourceCountry" field.
func (m *AlertMutation) SetSourceCountry(s string) {
m.sourceCountry = &s
}
// SourceCountry returns the value of the "sourceCountry" field in the mutation.
func (m *AlertMutation) SourceCountry() (r string, exists bool) {
v := m.sourceCountry
if v == nil {
return
}
return *v, true
}
// OldSourceCountry returns the old "sourceCountry" field's value of the Alert entity.
// If the Alert object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AlertMutation) OldSourceCountry(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldSourceCountry is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldSourceCountry requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldSourceCountry: %w", err)
}
return oldValue.SourceCountry, nil
}
// ClearSourceCountry clears the value of the "sourceCountry" field.
func (m *AlertMutation) ClearSourceCountry() {
m.sourceCountry = nil
m.clearedFields[alert.FieldSourceCountry] = struct{}{}
}
// SourceCountryCleared returns if the "sourceCountry" field was cleared in this mutation.
func (m *AlertMutation) SourceCountryCleared() bool {
_, ok := m.clearedFields[alert.FieldSourceCountry]
return ok
}
// ResetSourceCountry resets all changes to the "sourceCountry" field.
func (m *AlertMutation) ResetSourceCountry() {
m.sourceCountry = nil
delete(m.clearedFields, alert.FieldSourceCountry)
}
// SetSourceLatitude sets the "sourceLatitude" field.
func (m *AlertMutation) SetSourceLatitude(f float32) {
m.sourceLatitude = &f
m.addsourceLatitude = nil
}
// SourceLatitude returns the value of the "sourceLatitude" field in the mutation.
func (m *AlertMutation) SourceLatitude() (r float32, exists bool) {
v := m.sourceLatitude
if v == nil {
return
}
return *v, true
}
// OldSourceLatitude returns the old "sourceLatitude" field's value of the Alert entity.
// If the Alert object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AlertMutation) OldSourceLatitude(ctx context.Context) (v float32, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldSourceLatitude is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldSourceLatitude requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldSourceLatitude: %w", err)
}
return oldValue.SourceLatitude, nil
}
// AddSourceLatitude adds f to the "sourceLatitude" field.
func (m *AlertMutation) AddSourceLatitude(f float32) {
if m.addsourceLatitude != nil {
*m.addsourceLatitude += f
} else {
m.addsourceLatitude = &f
}
}
// AddedSourceLatitude returns the value that was added to the "sourceLatitude" field in this mutation.
func (m *AlertMutation) AddedSourceLatitude() (r float32, exists bool) {
v := m.addsourceLatitude
if v == nil {
return
}
return *v, true
}
// ClearSourceLatitude clears the value of the "sourceLatitude" field.
func (m *AlertMutation) ClearSourceLatitude() {
m.sourceLatitude = nil
m.addsourceLatitude = nil
m.clearedFields[alert.FieldSourceLatitude] = struct{}{}
}
// SourceLatitudeCleared returns if the "sourceLatitude" field was cleared in this mutation.
func (m *AlertMutation) SourceLatitudeCleared() bool {
_, ok := m.clearedFields[alert.FieldSourceLatitude]
return ok
}
// ResetSourceLatitude resets all changes to the "sourceLatitude" field.
func (m *AlertMutation) ResetSourceLatitude() {
m.sourceLatitude = nil
m.addsourceLatitude = nil
delete(m.clearedFields, alert.FieldSourceLatitude)
}
// SetSourceLongitude sets the "sourceLongitude" field.
func (m *AlertMutation) SetSourceLongitude(f float32) {
m.sourceLongitude = &f
m.addsourceLongitude = nil
}
// SourceLongitude returns the value of the "sourceLongitude" field in the mutation.
func (m *AlertMutation) SourceLongitude() (r float32, exists bool) {
v := m.sourceLongitude
if v == nil {
return
}
return *v, true
}
// OldSourceLongitude returns the old "sourceLongitude" field's value of the Alert entity.
// If the Alert object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AlertMutation) OldSourceLongitude(ctx context.Context) (v float32, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldSourceLongitude is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldSourceLongitude requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldSourceLongitude: %w", err)
}
return oldValue.SourceLongitude, nil
}
// AddSourceLongitude adds f to the "sourceLongitude" field.
func (m *AlertMutation) AddSourceLongitude(f float32) {
if m.addsourceLongitude != nil {
*m.addsourceLongitude += f
} else {
m.addsourceLongitude = &f
}
}
// AddedSourceLongitude returns the value that was added to the "sourceLongitude" field in this mutation.
func (m *AlertMutation) AddedSourceLongitude() (r float32, exists bool) {
v := m.addsourceLongitude
if v == nil {
return
}
return *v, true
}
// ClearSourceLongitude clears the value of the "sourceLongitude" field.
func (m *AlertMutation) ClearSourceLongitude() {
m.sourceLongitude = nil
m.addsourceLongitude = nil
m.clearedFields[alert.FieldSourceLongitude] = struct{}{}
}
// SourceLongitudeCleared returns if the "sourceLongitude" field was cleared in this mutation.
func (m *AlertMutation) SourceLongitudeCleared() bool {
_, ok := m.clearedFields[alert.FieldSourceLongitude]
return ok
}
// ResetSourceLongitude resets all changes to the "sourceLongitude" field.
func (m *AlertMutation) ResetSourceLongitude() {
m.sourceLongitude = nil
m.addsourceLongitude = nil
delete(m.clearedFields, alert.FieldSourceLongitude)
}
// SetSourceScope sets the "sourceScope" field.
func (m *AlertMutation) SetSourceScope(s string) {
m.sourceScope = &s
}
// SourceScope returns the value of the "sourceScope" field in the mutation.
func (m *AlertMutation) SourceScope() (r string, exists bool) {
v := m.sourceScope
if v == nil {
return
}
return *v, true
}
// OldSourceScope returns the old "sourceScope" field's value of the Alert entity.
// If the Alert object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AlertMutation) OldSourceScope(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldSourceScope is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldSourceScope requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldSourceScope: %w", err)
}
return oldValue.SourceScope, nil