forked from Tufin/oasdiff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
security_change.go
114 lines (87 loc) · 2.84 KB
/
security_change.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
package checker
import (
"fmt"
"strings"
"github.com/TwiN/go-color"
)
// SecurityChange represents a change in the Security Section (not to be confised with components/securitySchemes)
type SecurityChange struct {
Id string `json:"id,omitempty" yaml:"id,omitempty"`
Args []any `json:"-" yaml:"-"`
Comment string `json:"comment,omitempty" yaml:"comment,omitempty"`
Level Level `json:"level" yaml:"level"`
SourceFile string `json:"-" yaml:"-"`
SourceLine int `json:"-" yaml:"-"`
SourceLineEnd int `json:"-" yaml:"-"`
SourceColumn int `json:"-" yaml:"-"`
SourceColumnEnd int `json:"-" yaml:"-"`
}
func (c SecurityChange) GetSection() string {
return "security"
}
func (c SecurityChange) IsBreaking() bool {
return c.GetLevel().IsBreaking()
}
func (c SecurityChange) MatchIgnore(ignorePath, ignoreLine string, l Localizer) bool {
return strings.Contains(ignoreLine, strings.ToLower(c.GetUncolorizedText(l))) &&
strings.Contains(ignoreLine, "security")
}
func (c SecurityChange) GetId() string {
return c.Id
}
func (c SecurityChange) GetText(l Localizer) string {
return l(c.Id, colorizedValues(c.Args)...)
}
func (c SecurityChange) GetArgs() []any {
return c.Args
}
func (c SecurityChange) GetUncolorizedText(l Localizer) string {
return l(c.Id, quotedValues(c.Args)...)
}
func (c SecurityChange) GetComment(l Localizer) string {
return l(c.Comment)
}
func (c SecurityChange) GetLevel() Level {
return c.Level
}
func (r SecurityChange) GetOperation() string {
return ""
}
func (SecurityChange) GetOperationId() string {
return ""
}
func (SecurityChange) GetPath() string {
return ""
}
func (c SecurityChange) GetSource() string {
return ""
}
func (c SecurityChange) GetSourceFile() string {
return c.SourceFile
}
func (c SecurityChange) GetSourceLine() int {
return c.SourceLine
}
func (c SecurityChange) GetSourceLineEnd() int {
return c.SourceLineEnd
}
func (c SecurityChange) GetSourceColumn() int {
return c.SourceColumn
}
func (c SecurityChange) GetSourceColumnEnd() int {
return c.SourceColumnEnd
}
func (c SecurityChange) SingleLineError(l Localizer, colorMode ColorMode) string {
const format = "%s, %s security %s [%s]. %s"
if isColorEnabled(colorMode) {
return fmt.Sprintf(format, c.Level.PrettyString(), l("in"), c.GetText(l), color.InYellow(c.Id), c.GetComment(l))
}
return fmt.Sprintf(format, c.Level.String(), l("in"), c.GetUncolorizedText(l), c.Id, c.GetComment(l))
}
func (c SecurityChange) MultiLineError(l Localizer, colorMode ColorMode) string {
const format = "%s\t[%s] \t\n\t%s security\n\t\t%s%s"
if isColorEnabled(colorMode) {
return fmt.Sprintf(format, c.Level.PrettyString(), color.InYellow(c.Id), l("in"), c.GetText(l), multiLineComment(c.GetComment(l)))
}
return fmt.Sprintf(format, c.Level.String(), c.Id, l("in"), c.GetUncolorizedText(l), multiLineComment(c.GetComment(l)))
}