forked from snyk/driftctl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alert.go
87 lines (66 loc) · 1.57 KB
/
alert.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
package alerter
import (
"encoding/json"
"fmt"
"github.com/snyk/driftctl/enumeration/resource"
)
type Alerts map[string][]Alert
type Alert interface {
Message() string
ShouldIgnoreResource() bool
Resource() *resource.Resource
}
type UnsupportedResourcetypeAlert struct {
Typ string
}
func NewUnsupportedResourcetypeAlert(typ string) *UnsupportedResourcetypeAlert {
return &UnsupportedResourcetypeAlert{Typ: typ}
}
func (f *UnsupportedResourcetypeAlert) Message() string {
return fmt.Sprintf("%s is not supported...", f.Typ)
}
func (f *UnsupportedResourcetypeAlert) ShouldIgnoreResource() bool {
return false
}
func (f *UnsupportedResourcetypeAlert) Resource() *resource.Resource {
return nil
}
type FakeAlert struct {
Msg string
IgnoreResource bool
}
func (f *FakeAlert) Message() string {
return f.Msg
}
func (f *FakeAlert) ShouldIgnoreResource() bool {
return f.IgnoreResource
}
func (f *FakeAlert) Resource() *resource.Resource {
return nil
}
type SerializableAlert struct {
Alert
}
type SerializedAlert struct {
Msg string `json:"message"`
}
func (u *SerializedAlert) Message() string {
return u.Msg
}
func (u *SerializedAlert) ShouldIgnoreResource() bool {
return false
}
func (s *SerializedAlert) Resource() *resource.Resource {
return nil
}
func (s *SerializableAlert) UnmarshalJSON(bytes []byte) error {
var res SerializedAlert
if err := json.Unmarshal(bytes, &res); err != nil {
return err
}
s.Alert = &res
return nil
}
func (s *SerializableAlert) MarshalJSON() ([]byte, error) {
return json.Marshal(SerializedAlert{Msg: s.Message()})
}