@@ -14,8 +14,8 @@ import (
14
14
15
15
type Service interface {
16
16
textdocument.DiagnosticsCollector
17
- Analyze (image string ) ([]Diagnostic , error )
18
- Hover (ctx context.Context , image string ) (* protocol.Hover , error )
17
+ Analyze (documentURI protocol. DocumentUri , image string ) ([]Diagnostic , error )
18
+ Hover (ctx context.Context , documentURI protocol. DocumentUri , image string ) (* protocol.Hover , error )
19
19
}
20
20
21
21
type ServiceImpl struct {
@@ -29,11 +29,21 @@ func NewService() Service {
29
29
}
30
30
}
31
31
32
- func (s * ServiceImpl ) Hover (ctx context.Context , image string ) (* protocol.Hover , error ) {
32
+ func (s * ServiceImpl ) Hover (ctx context.Context , documentURI protocol.DocumentUri , image string ) (* protocol.Hover , error ) {
33
+ config := configuration .Get (documentURI )
33
34
resp , err := s .manager .Get (& ScoutImageKey {Image : image })
34
35
if err == nil {
35
36
hovers := []string {}
36
37
for _ , info := range resp .Infos {
38
+ if ! config .Experimental .Scout .CriticalHighVulnerabilities && info .Kind == "critical_high_vulnerabilities" {
39
+ continue
40
+ }
41
+ if ! config .Experimental .Scout .RecommendedTag && info .Kind == "recommended_tag" {
42
+ continue
43
+ }
44
+ if ! config .Experimental .Scout .Vulnerabilites && info .Kind == "vulnerabilities" {
45
+ continue
46
+ }
37
47
hovers = append (hovers , info .Description .Markdown )
38
48
}
39
49
@@ -49,12 +59,34 @@ func (s *ServiceImpl) Hover(ctx context.Context, image string) (*protocol.Hover,
49
59
return nil , err
50
60
}
51
61
52
- func (s * ServiceImpl ) Analyze (image string ) ([]Diagnostic , error ) {
62
+ func (s * ServiceImpl ) Analyze (documentURI protocol.DocumentUri , image string ) ([]Diagnostic , error ) {
63
+ config := configuration .Get (documentURI )
64
+ if ! config .Experimental .VulnerabilityScanning {
65
+ return nil , nil
66
+ }
67
+
53
68
resp , err := s .manager .Get (& ScoutImageKey {Image : image })
54
69
if err != nil {
55
70
return nil , err
56
71
}
57
- return resp .Diagnostics , nil
72
+
73
+ diagnostics := make ([]Diagnostic , len (resp .Diagnostics ))
74
+ for _ , diagnostic := range resp .Diagnostics {
75
+ if ! config .Experimental .Scout .CriticalHighVulnerabilities && diagnostic .Kind == "critical_high_vulnerabilities" {
76
+ continue
77
+ }
78
+ if ! config .Experimental .Scout .NotPinnedDigest && diagnostic .Kind == "not_pinned_digest" {
79
+ continue
80
+ }
81
+ if ! config .Experimental .Scout .RecommendedTag && diagnostic .Kind == "recommended_tag" {
82
+ continue
83
+ }
84
+ if ! config .Experimental .Scout .Vulnerabilites && diagnostic .Kind == "vulnerabilities" {
85
+ continue
86
+ }
87
+ diagnostics = append (diagnostics , diagnostic )
88
+ }
89
+ return diagnostics , nil
58
90
}
59
91
60
92
func (s * ServiceImpl ) CalculateDiagnostics (ctx context.Context , source string , doc document.Document ) ([]protocol.Diagnostic , error ) {
@@ -80,6 +112,19 @@ func (s *ServiceImpl) CalculateDiagnostics(ctx context.Context, source string, d
80
112
}
81
113
82
114
for _ , diagnostic := range resp .Diagnostics {
115
+ if ! config .Experimental .Scout .CriticalHighVulnerabilities && diagnostic .Kind == "critical_high_vulnerabilities" {
116
+ continue
117
+ }
118
+ if ! config .Experimental .Scout .NotPinnedDigest && diagnostic .Kind == "not_pinned_digest" {
119
+ continue
120
+ }
121
+ if ! config .Experimental .Scout .RecommendedTag && diagnostic .Kind == "recommended_tag" {
122
+ continue
123
+ }
124
+ if ! config .Experimental .Scout .Vulnerabilites && diagnostic .Kind == "vulnerabilities" {
125
+ continue
126
+ }
127
+
83
128
namedEdits := []types.NamedEdit {}
84
129
for _ , edit := range resp .Edits {
85
130
if diagnostic .Kind == edit .Diagnostic {
0 commit comments