/
events_structs.go
1066 lines (905 loc) · 28.1 KB
/
events_structs.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
package scalingo
import (
"encoding/json"
"fmt"
"strings"
"time"
"github.com/Scalingo/go-scalingo/debug"
)
type Event struct {
ID string `json:"id"`
AppID string `json:"app_id"`
CreatedAt time.Time `json:"created_at"`
User EventUser `json:"user"`
Type EventTypeName `json:"type"`
AppName string `json:"app_name"`
RawTypeData json.RawMessage `json:"type_data"`
TypeData map[string]interface{} `json:"-"`
}
func (ev *Event) GetEvent() *Event {
return ev
}
func (ev *Event) TypeDataPtr() interface{} {
return ev.TypeData
}
func (ev *Event) String() string {
return fmt.Sprintf("Unknown event %v on app %v", ev.Type, ev.AppName)
}
func (ev *Event) When() string {
return ev.CreatedAt.Format("Mon Jan 02 2006 15:04:05")
}
func (ev *Event) Who() string {
return fmt.Sprintf("%s (%s)", ev.User.Username, ev.User.Email)
}
func (ev *Event) PrintableType() string {
return strings.Title(strings.Replace(string(ev.Type), "_", " ", -1))
}
type DetailedEvent interface {
fmt.Stringer
GetEvent() *Event
PrintableType() string
When() string
Who() string
TypeDataPtr() interface{}
}
type Events []DetailedEvent
type EventUser struct {
Username string `json:"username"`
Email string `json:"email"`
ID string `json:"id"`
}
type EventTypeName string
const (
EventNewUser EventTypeName = "new_user"
EventNewApp EventTypeName = "new_app"
EventEditApp EventTypeName = "edit_app"
EventDeleteApp EventTypeName = "delete_app"
EventRenameApp EventTypeName = "rename_app"
EventTransferApp EventTypeName = "transfer_app"
EventRestart EventTypeName = "restart"
EventScale EventTypeName = "scale"
EventStopApp EventTypeName = "stop_app"
EventCrash EventTypeName = "crash"
EventDeployment EventTypeName = "deployment"
EventLinkSCM EventTypeName = "link_scm"
EventUnlinkSCM EventTypeName = "unlink_scm"
EventNewIntegration EventTypeName = "new_integration"
EventDeleteIntegration EventTypeName = "delete_integration"
EventAuthorizeGithub EventTypeName = "authorize_github"
EventRevokeGithub EventTypeName = "revoke_github"
EventRun EventTypeName = "run"
EventNewDomain EventTypeName = "new_domain"
EventEditDomain EventTypeName = "edit_domain"
EventDeleteDomain EventTypeName = "delete_domain"
EventNewAddon EventTypeName = "new_addon"
EventUpgradeAddon EventTypeName = "upgrade_addon"
EventUpgradeDatabase EventTypeName = "upgrade_database"
EventDeleteAddon EventTypeName = "delete_addon"
EventResumeAddon EventTypeName = "resume_addon"
EventSuspendAddon EventTypeName = "suspend_addon"
EventNewCollaborator EventTypeName = "new_collaborator"
EventAcceptCollaborator EventTypeName = "accept_collaborator"
EventDeleteCollaborator EventTypeName = "delete_collaborator"
EventNewVariable EventTypeName = "new_variable"
EventEditVariable EventTypeName = "edit_variable"
EventEditVariables EventTypeName = "edit_variables"
EventDeleteVariable EventTypeName = "delete_variable"
EventAddCredit EventTypeName = "add_credit"
EventAddPaymentMethod EventTypeName = "add_payment_method"
EventAddVoucher EventTypeName = "add_voucher"
EventNewKey EventTypeName = "new_key"
EventDeleteKey EventTypeName = "delete_key"
EventPaymentAttempt EventTypeName = "payment_attempt"
EventNewAlert EventTypeName = "new_alert"
EventAlert EventTypeName = "alert"
EventDeleteAlert EventTypeName = "delete_alert"
EventNewAutoscaler EventTypeName = "new_autoscaler"
EventDeleteAutoscaler EventTypeName = "delete_autoscaler"
EventAddonUpdated EventTypeName = "addon_updated"
EventStartRegionMigration EventTypeName = "start_region_migration"
EventNewLogDrain EventTypeName = "new_log_drain"
EventDeleteLogDrain EventTypeName = "delete_log_drain"
EventNewAddonLogDrain EventTypeName = "new_addon_log_drain"
EventDeleteAddonLogDrain EventTypeName = "delete_addon_log_drain"
// EventLinkGithub and EventUnlinkGithub events are kept for
// retro-compatibility. They are replaced by SCM events.
EventLinkGithub EventTypeName = "link_github"
EventUnlinkGithub EventTypeName = "unlink_github"
)
type EventNewUserType struct {
Event
TypeData EventNewUserTypeData `json:"type_data"`
}
func (ev *EventNewUserType) String() string {
return fmt.Sprintf("You joined Scalingo. Hooray!")
}
type EventNewUserTypeData struct {
}
type EventNewAppType struct {
Event
TypeData EventNewAppTypeData `json:"type_data"`
}
func (ev *EventNewAppType) String() string {
return fmt.Sprintf("the application has been created")
}
type EventNewAppTypeData struct {
GitSource string `json:"git_source"`
}
type EventEditAppType struct {
Event
TypeData EventEditAppTypeData `json:"type_data"`
}
type EventEditAppTypeData struct {
ForceHTTPS *bool `json:"force_https"`
}
func (ev *EventEditAppType) String() string {
base := "application settings have been updated"
if ev.TypeData.ForceHTTPS != nil {
if *ev.TypeData.ForceHTTPS {
base += ", Force HTTPS has been enabled"
} else {
base += ", Force HTTPS has been disabled"
}
}
return base
}
type EventDeleteAppType struct {
Event
}
func (ev *EventDeleteAppType) String() string {
return fmt.Sprintf("the application has been deleted")
}
type EventRenameAppType struct {
Event
TypeData EventRenameAppTypeData `json:"type_data"`
}
func (ev *EventRenameAppType) String() string {
return fmt.Sprintf(
"the application has been renamed from '%s' to '%s'",
ev.TypeData.OldName, ev.TypeData.NewName,
)
}
type EventRenameAppTypeData struct {
OldName string `json:"old_name"`
NewName string `json:"new_name"`
}
type EventTransferAppType struct {
Event
TypeData EventTransferAppTypeData `json:"type_data"`
}
func (ev *EventTransferAppType) String() string {
return fmt.Sprintf(
"the application has been transfered to %s (%s)",
ev.TypeData.NewOwner.Username, ev.TypeData.NewOwner.Email,
)
}
type EventTransferAppTypeData struct {
OldOwner EventUser `json:"old_owner"`
NewOwner EventUser `json:"new_owner"`
}
type EventRestartType struct {
Event
TypeData EventRestartTypeData `json:"type_data"`
}
func (ev *EventRestartType) String() string {
if len(ev.TypeData.Scope) != 0 {
return fmt.Sprintf("containers %v have been restarted", ev.TypeData.Scope)
}
return fmt.Sprintf("containers have been restarted")
}
func (ev *EventRestartType) Who() string {
if ev.TypeData.AddonName != "" {
return fmt.Sprintf("Addon %s", ev.TypeData.AddonName)
} else {
return ev.Event.Who()
}
}
type EventRestartTypeData struct {
Scope []string `json:"scope"`
AddonName string `json:"addon_name"`
}
type EventStopAppType struct {
Event
TypeData EventStopAppTypeData `json:"type_data"`
}
func (ev *EventStopAppType) String() string {
return fmt.Sprintf("app has been stopped (reason: %s)", ev.TypeData.Reason)
}
type EventStopAppTypeData struct {
Reason string `json:"reason"`
}
func (ev *EventScaleType) String() string {
return fmt.Sprintf(
"containers have been scaled from %s, to %s",
ev.TypeData.containersString(ev.TypeData.PreviousContainers),
ev.TypeData.containersString(ev.TypeData.Containers),
)
}
type EventScaleType struct {
Event
TypeData EventScaleTypeData `json:"type_data"`
}
type EventScaleTypeData struct {
PreviousContainers map[string]string `json:"previous_containers"`
Containers map[string]string `json:"containers"`
}
func (e *EventScaleTypeData) containersString(containers map[string]string) string {
types := []string{}
for name, amountAndSize := range containers {
types = append(types, fmt.Sprintf("%s:%s", name, amountAndSize))
}
return "[" + strings.Join(types, ", ") + "]"
}
type EventCrashType struct {
Event
TypeData EventCrashTypeData `json:"type_data"`
}
func (ev *EventCrashType) String() string {
msg := fmt.Sprintf("container '%v' has crashed", ev.TypeData.ContainerType)
if ev.TypeData.CrashLogs != "" {
msg += fmt.Sprintf(" (logs on %s)", ev.TypeData.LogsUrl)
}
return msg
}
type EventCrashTypeData struct {
ContainerType string `json:"container_type"`
CrashLogs string `json:"crash_logs"`
LogsUrl string `json:"logs_url"`
}
type EventDeploymentType struct {
Event
TypeData EventDeploymentTypeData `json:"type_data"`
}
func (ev *EventDeploymentType) String() string {
return fmt.Sprintf("deployment of %s (%s)", ev.TypeData.GitRef, ev.TypeData.Status)
}
type EventDeploymentTypeData struct {
DeploymentID string `json:"deployment_id"`
Puser string `json:"pusher"`
GitRef string `json:"git_ref"`
Status string `json:"status"`
Duration int `json:"duration"`
}
type EventLinkGithubType struct {
Event
TypeData EventLinkGithubTypeData `json:"type_data"`
}
func (ev *EventLinkGithubType) String() string {
return fmt.Sprintf("app has been linked to Github repository '%s'", ev.TypeData.RepoName)
}
type EventLinkGithubTypeData struct {
RepoName string `json:"repo_name"`
LinkerUsername string `json:"linker_username"`
GithubSource string `json:"github_source"`
}
type EventUnlinkGithubType struct {
Event
TypeData EventUnlinkGithubTypeData `json:"type_data"`
}
func (ev *EventUnlinkGithubType) String() string {
return fmt.Sprintf("app has been unlinked from Github repository '%s'", ev.TypeData.RepoName)
}
type EventUnlinkGithubTypeData struct {
RepoName string `json:"repo_name"`
UnlinkerUsername string `json:"unlinker_username"`
GithubSource string `json:"github_source"`
}
type EventLinkSCMType struct {
Event
TypeData EventLinkSCMTypeData `json:"type_data"`
}
func (ev *EventLinkSCMType) String() string {
return fmt.Sprintf("app has been linked to repository '%s'", ev.TypeData.RepoName)
}
type EventLinkSCMTypeData struct {
RepoName string `json:"repo_name"`
LinkerUsername string `json:"linker_username"`
Source string `json:"source"`
}
type EventUnlinkSCMType struct {
Event
TypeData EventUnlinkSCMTypeData `json:"type_data"`
}
func (ev *EventUnlinkSCMType) String() string {
return fmt.Sprintf("app has been unlinked from repository '%s'", ev.TypeData.RepoName)
}
type EventUnlinkSCMTypeData struct {
RepoName string `json:"repo_name"`
UnlinkerUsername string `json:"unlinker_username"`
Source string `json:"source"`
}
type EventRunType struct {
Event
TypeData EventRunTypeData `json:"type_data"`
}
func (ev *EventRunType) String() string {
return fmt.Sprintf("one-off container with command '%s'", ev.TypeData.Command)
}
type EventRunTypeData struct {
Command string `json:"command"`
AuditLogID string `json:"audit_log_id"`
}
type EventNewDomainType struct {
Event
TypeData EventNewDomainTypeData `json:"type_data"`
}
func (ev *EventNewDomainType) String() string {
return fmt.Sprintf("'%s' has been associated", ev.TypeData.Hostname)
}
type EventNewDomainTypeData struct {
Hostname string `json:"hostname"`
SSL bool `json:"ssl"`
}
type EventEditDomainType struct {
Event
TypeData EventEditDomainTypeData `json:"type_data"`
}
func (ev *EventEditDomainType) String() string {
t := ev.TypeData
res := fmt.Sprintf("'%s' modified", t.Hostname)
if !t.SSL && t.OldSSL {
res += ", TLS certificate has been removed"
} else if !t.SSL && t.OldSSL {
res += ", TLS certificate has been added"
} else if t.SSL && t.OldSSL {
res += ", TLS certificate has been changed"
}
return res
}
type EventEditDomainTypeData struct {
Hostname string `json:"hostname"`
SSL bool `json:"ssl"`
OldSSL bool `json:"old_ssl"`
}
type EventDeleteDomainType struct {
Event
TypeData EventDeleteDomainTypeData `json:"type_data"`
}
func (ev *EventDeleteDomainType) String() string {
return fmt.Sprintf("'%s' has been disassociated", ev.TypeData.Hostname)
}
type EventDeleteDomainTypeData struct {
Hostname string `json:"hostname"`
}
type EventAddon struct {
AddonProviderName string `json:"addon_provider_name"`
PlanName string `json:"plan_name"`
ResourceID string `json:"resource_id"`
}
type EventNewAddonType struct {
Event
TypeData EventNewAddonTypeData `json:"type_data"`
}
func (ev *EventNewAddonType) String() string {
return fmt.Sprintf(
"'%s' (%s) has been added (plan '%s')",
ev.TypeData.ResourceID, ev.TypeData.AddonProviderName, ev.TypeData.PlanName,
)
}
type EventNewAddonTypeData struct {
EventAddon
}
type EventUpgradeAddonType struct {
Event
TypeData EventUpgradeAddonTypeData `json:"type_data"`
}
func (ev *EventUpgradeAddonType) String() string {
return fmt.Sprintf(
"'%s' (%s) plan has been changed from '%s' to '%s'",
ev.TypeData.ResourceID, ev.TypeData.AddonProviderName, ev.TypeData.OldPlanName, ev.TypeData.NewPlanName,
)
}
type EventUpgradeAddonTypeData struct {
EventAddon
OldPlanName string `json:"old_plan_name"`
NewPlanName string `json:"new_plan_name"`
}
type EventDeleteAddonType struct {
Event
TypeData EventDeleteAddonTypeData `json:"type_data"`
}
func (ev *EventDeleteAddonType) String() string {
return fmt.Sprintf(
"'%s' (%s) plan has been deleted",
ev.TypeData.ResourceID, ev.TypeData.AddonProviderName,
)
}
type EventResumeAddonType struct {
Event
TypeData EventResumeAddonTypeData `json:"type_data"`
}
func (ev *EventResumeAddonType) String() string {
return fmt.Sprintf(
"'%s' (%s) has been resumed",
ev.TypeData.ResourceID, ev.TypeData.AddonProviderName,
)
}
type EventResumeAddonTypeData struct {
EventAddon
}
type EventSuspendAddonType struct {
Event
TypeData EventSuspendAddonTypeData `json:"type_data"`
}
func (ev *EventSuspendAddonType) String() string {
return fmt.Sprintf(
"'%s' (%s) has been suspended (reason: %s)",
ev.TypeData.ResourceID, ev.TypeData.AddonProviderName, ev.TypeData.Reason,
)
}
type EventSuspendAddonTypeData struct {
EventAddon
Reason string `json:"reason"`
}
type EventDeleteAddonTypeData struct {
EventAddon
}
type EventCollaborator struct {
EventUser
Inviter EventUser `json:"inviter"`
}
type EventNewCollaboratorType struct {
Event
TypeData EventNewCollaboratorTypeData `json:"type_data"`
}
func (ev *EventNewCollaboratorType) String() string {
return fmt.Sprintf(
"'%s' has been invited",
ev.TypeData.Collaborator.Email,
)
}
type EventNewCollaboratorTypeData struct {
Collaborator EventCollaborator `json:"collaborator"`
}
type EventAcceptCollaboratorType struct {
Event
TypeData EventAcceptCollaboratorTypeData `json:"type_data"`
}
func (ev *EventAcceptCollaboratorType) String() string {
return fmt.Sprintf(
"'%s' (%s) has accepted the collaboration",
ev.TypeData.Collaborator.Username,
ev.TypeData.Collaborator.Email,
)
}
// Inviter is filled there
type EventAcceptCollaboratorTypeData struct {
Collaborator EventCollaborator `json:"collaborator"`
}
type EventDeleteCollaboratorType struct {
Event
TypeData EventDeleteCollaboratorTypeData `json:"type_data"`
}
func (ev *EventDeleteCollaboratorType) String() string {
return fmt.Sprintf(
"'%s' (%s) is not a collaborator anymore",
ev.TypeData.Collaborator.Username,
ev.TypeData.Collaborator.Email,
)
}
type EventDeleteCollaboratorTypeData struct {
Collaborator EventCollaborator `json:"collaborator"`
}
type EventUpgradeDatabaseType struct {
Event
TypeData EventUpgradeDatabaseTypeData `json:"type_data"`
}
type EventUpgradeDatabaseTypeData struct {
AddonName string `json:"addon_name"`
OldVersion string `json:"old_version"`
NewVersion string `json:"new_version"`
}
func (ev *EventUpgradeDatabaseType) String() string {
return fmt.Sprintf(
"'%s' upgraded from v%s to v%s",
ev.TypeData.AddonName, ev.TypeData.OldVersion, ev.TypeData.NewVersion,
)
}
func (ev *EventUpgradeDatabaseType) Who() string {
if ev.TypeData.AddonName != "" {
return fmt.Sprintf("Addon %s", ev.TypeData.AddonName)
} else {
return ev.Event.Who()
}
}
type EventVariable struct {
Name string `json:"name"`
Value string `json:"value"`
}
type EventNewVariableType struct {
Event
TypeData EventNewVariableTypeData `json:"type_data"`
}
func (ev *EventNewVariableType) String() string {
return fmt.Sprintf("'%s' added to the environment", ev.TypeData.Name)
}
func (ev *EventNewVariableType) Who() string {
if ev.TypeData.AddonName != "" {
return fmt.Sprintf("Addon %s", ev.TypeData.AddonName)
} else {
return ev.Event.Who()
}
}
type EventNewVariableTypeData struct {
AddonName string `json:"addon_name"`
EventVariable
}
type EventVariables []EventVariable
func (evs EventVariables) Names() string {
names := []string{}
for _, e := range evs {
names = append(names, e.Name)
}
return strings.Join(names, ", ")
}
type EventEditVariableType struct {
Event
TypeData EventEditVariableTypeData `json:"type_data"`
}
func (ev *EventEditVariableType) String() string {
return fmt.Sprintf("'%s' modified", ev.TypeData.Name)
}
type EventEditVariableTypeData struct {
EventVariable
OldValue string `json:"old_value"`
AddonName string `json:"addon_name"`
}
type EventEditVariablesType struct {
Event
TypeData EventEditVariablesTypeData `json:"type_data"`
}
func (ev *EventEditVariablesType) String() string {
res := "environment changes:"
if len(ev.TypeData.NewVars) > 0 {
res += fmt.Sprintf(" %s added", ev.TypeData.NewVars.Names())
}
if len(ev.TypeData.UpdatedVars) > 0 {
res += fmt.Sprintf(" %s modified", ev.TypeData.UpdatedVars.Names())
}
if len(ev.TypeData.DeletedVars) > 0 {
res += fmt.Sprintf(" %s removed", ev.TypeData.DeletedVars.Names())
}
return res
}
func (ev *EventEditVariableType) Who() string {
if ev.TypeData.AddonName != "" {
return fmt.Sprintf("Addon %s", ev.TypeData.AddonName)
} else {
return ev.Event.Who()
}
}
type EventEditVariablesTypeData struct {
NewVars EventVariables `json:"new_vars"`
UpdatedVars EventVariables `json:"updated_vars"`
DeletedVars EventVariables `json:"deleted_vars"`
}
type EventDeleteVariableType struct {
Event
TypeData EventDeleteVariableTypeData `json:"type_data"`
}
func (ev *EventDeleteVariableType) String() string {
return fmt.Sprintf("'%s' removed from environment", ev.TypeData.Name)
}
type EventDeleteVariableTypeData struct {
EventVariable
}
type EventPaymentAttemptTypeData struct {
Amount float32 `json:"amount"`
PaymentMethod string `json:"payment_method"`
Status string `json:"status"`
}
type EventPaymentAttemptType struct {
Event
TypeData EventPaymentAttemptTypeData `json:"type_data"`
}
func (ev *EventPaymentAttemptType) String() string {
res := "Payment attempt of "
res += fmt.Sprintf("%0.2f€", ev.TypeData.Amount)
res += " with your "
if ev.TypeData.PaymentMethod == "credit" {
res += "credits"
} else {
res += "card"
}
if ev.TypeData.Status == "new" {
res += " (pending)"
} else if ev.TypeData.Status == "paid" {
res += " (success)"
} else {
res += " (fail)"
}
return res
}
type EventNewAlertTypeData struct {
ContainerType string `json:"container_type"`
Metric string `json:"metric"`
Limit float64 `json:"limit"`
LimitText string `json:"limit_text"`
SendWhenBelow bool `json:"send_when_below"`
}
type EventNewAlertType struct {
Event
TypeData EventNewAlertTypeData `json:"type_data"`
}
func (ev *EventNewAlertType) String() string {
d := ev.TypeData
return fmt.Sprintf("Alert created about %s on container %s (limit: %s)", d.Metric, d.ContainerType, d.LimitText)
}
type EventAlertTypeData struct {
SenderName string `json:"sender_name"`
Metric string `json:"metric"`
Limit float64 `json:"limit"`
LimitText string `json:"limit_text"`
Value float64 `json:"value"`
ValueText string `json:"value_text"`
Activated bool `json:"activated"`
SendWhenBelow bool `json:"send_when_below"`
RawLimit float64 `json:"raw_limit"`
RawValue float64 `json:"raw_value"`
}
type EventAlertType struct {
Event
TypeData EventAlertTypeData `json:"type_data"`
}
func (ev *EventAlertType) String() string {
d := ev.TypeData
var res string
if d.SendWhenBelow {
res = "Low"
} else {
res = "High"
}
res += fmt.Sprintf(" %s usage on container %s ", d.Metric, d.SenderName)
if ev.TypeData.Activated {
res += "triggered"
} else {
res += "resolved"
}
res += fmt.Sprintf(" (value: %s, limit: %s)", d.ValueText, d.LimitText)
return res
}
type EventDeleteAlertTypeData struct {
ContainerType string `json:"container_type"`
Metric string `json:"metric"`
}
type EventDeleteAlertType struct {
Event
TypeData EventDeleteAlertTypeData `json:"type_data"`
}
func (ev *EventDeleteAlertType) String() string {
d := ev.TypeData
return fmt.Sprintf("Alert deleted about %s on container %s", d.Metric, d.ContainerType)
}
type EventNewAutoscalerTypeData struct {
ContainerType string `json:"container_type"`
MinContainers int `json:"min_containers"`
MaxContainers int `json:"max_containers"`
Metric string `json:"metric"`
Target float64 `json:"target"`
TargetText string `json:"target_text"`
}
type EventNewAutoscalerType struct {
Event
TypeData EventNewAutoscalerTypeData `json:"type_data"`
}
func (ev *EventNewAutoscalerType) String() string {
d := ev.TypeData
return fmt.Sprintf("Autoscaler created about %s on container %s (target: %s)", d.Metric, d.ContainerType, d.TargetText)
}
type EventDeleteAutoscalerTypeData struct {
ContainerType string `json:"container_type"`
Metric string `json:"metric"`
}
type EventDeleteAutoscalerType struct {
Event
TypeData EventDeleteAutoscalerTypeData `json:"type_data"`
}
func (ev *EventDeleteAutoscalerType) String() string {
d := ev.TypeData
return fmt.Sprintf("Alert deleted about %s on container %s", d.Metric, d.ContainerType)
}
type EventAddonUpdatedTypeData struct {
AddonID string `json:"addon_id"`
AddonPlanName string `json:"addon_plan_name"`
AddonResourceID string `json:"addon_resource_id"`
AddonProviderID string `json:"addon_provider_id"`
AddonProviderName string `json:"addon_provider_name"`
// Status has only two items when is updated, the old value and the new value, in this order
Status []AddonStatus `json:"status"`
// AttributesChanged contain names of changed attributes
AttributesChanged []string `json:"attributes_changed"`
}
type EventAddonUpdatedType struct {
Event
TypeData EventAddonUpdatedTypeData `json:"type_data"`
}
func (ev *EventAddonUpdatedType) String() string {
d := ev.TypeData
return fmt.Sprintf(
"Addon %s %s updated, status %v -> %v",
d.AddonProviderName, d.AddonResourceID, d.Status[0], d.Status[1],
)
}
type EventStartRegionMigrationTypeData struct {
MigrationID string `json:"migration_id"`
Destination string `json:"destination"`
Source string `json:"source"`
DstAppName string `json:"dst_app_name"`
}
type EventStartRegionMigrationType struct {
Event
TypeData EventStartRegionMigrationTypeData `json:"type_data"`
}
func (ev *EventStartRegionMigrationType) String() string {
return fmt.Sprintf("Application region migration started from %s to %s/%s", ev.TypeData.Source, ev.TypeData.Destination, ev.TypeData.DstAppName)
}
// New log drain
type EventNewLogDrainTypeData struct {
URL string `json:"url"`
}
type EventNewLogDrainType struct {
Event
TypeData EventNewLogDrainTypeData `json:"type_data"`
}
func (ev *EventNewLogDrainType) String() string {
return fmt.Sprintf("Log drain added on %s app", ev.AppName)
}
// Delete log drain
type EventDeleteLogDrainTypeData struct {
URL string `json:"url"`
}
type EventDeleteLogDrainType struct {
Event
TypeData EventDeleteLogDrainTypeData `json:"type_data"`
}
func (ev *EventDeleteLogDrainType) String() string {
return fmt.Sprintf("Log drain deleted on %s app", ev.AppName)
}
// New addon log drain
type EventNewAddonLogDrainTypeData struct {
URL string `json:"url"`
AddonUUID string `json:"addon_uuid"`
AddonName string `json:"addon_name"`
}
type EventNewAddonLogDrainType struct {
Event
TypeData EventNewAddonLogDrainTypeData `json:"type_data"`
}
func (ev *EventNewAddonLogDrainType) String() string {
return fmt.Sprintf("Log drain added for %s addon on %s app", ev.TypeData.AddonName, ev.AppName)
}
// Delete addon log drain
type EventDeleteAddonLogDrainTypeData struct {
URL string `json:"url"`
AddonUUID string `json:"addon_uuid"`
AddonName string `json:"addon_name"`
}
type EventDeleteAddonLogDrainType struct {
Event
TypeData EventDeleteAddonLogDrainTypeData `json:"type_data"`
}
func (ev *EventDeleteAddonLogDrainType) String() string {
return fmt.Sprintf("Log drain deleted on %s addon for %s app", ev.TypeData.AddonName, ev.AppName)
}
func (pev *Event) Specialize() DetailedEvent {
var e DetailedEvent
ev := *pev
switch ev.Type {
case EventNewUser:
e = &EventNewUserType{Event: ev}
case EventNewApp:
e = &EventNewAppType{Event: ev}
case EventEditApp:
e = &EventEditAppType{Event: ev}
case EventDeleteApp:
e = &EventDeleteAppType{Event: ev}
case EventRenameApp:
e = &EventRenameAppType{Event: ev}
case EventTransferApp:
e = &EventTransferAppType{Event: ev}
case EventRestart:
e = &EventRestartType{Event: ev}
case EventStopApp:
e = &EventStopAppType{Event: ev}
case EventScale:
e = &EventScaleType{Event: ev}
case EventCrash:
e = &EventCrashType{Event: ev}
case EventLinkSCM:
e = &EventLinkSCMType{Event: ev}
case EventUnlinkSCM:
e = &EventUnlinkSCMType{Event: ev}
case EventNewIntegration:
e = &EventNewIntegrationType{Event: ev}
case EventDeleteIntegration:
e = &EventDeleteIntegrationType{Event: ev}
case EventAuthorizeGithub:
e = &EventAuthorizeGithubType{Event: ev}
case EventRevokeGithub:
e = &EventRevokeGithubType{Event: ev}
case EventDeployment:
e = &EventDeploymentType{Event: ev}
case EventRun:
e = &EventRunType{Event: ev}
case EventNewDomain:
e = &EventNewDomainType{Event: ev}
case EventEditDomain:
e = &EventEditDomainType{Event: ev}
case EventDeleteDomain:
e = &EventDeleteDomainType{Event: ev}
case EventNewAddon:
e = &EventNewAddonType{Event: ev}
case EventUpgradeAddon:
e = &EventUpgradeAddonType{Event: ev}
case EventUpgradeDatabase:
e = &EventUpgradeDatabaseType{Event: ev}
case EventDeleteAddon:
e = &EventDeleteAddonType{Event: ev}
case EventResumeAddon:
e = &EventResumeAddonType{Event: ev}