@@ -14,9 +14,16 @@ import (
14
14
"github.com/aquasecurity/trivy/pkg/version/app"
15
15
)
16
16
17
+ // flexibleTime is a custom time type that can handle
18
+ // different date formats in JSON. It implements the
19
+ // UnmarshalJSON method to parse the date string into a time.Time object.
20
+ type flexibleTime struct {
21
+ time.Time
22
+ }
23
+
17
24
type versionInfo struct {
18
- LatestVersion string `json:"latest_version"`
19
- LatestDate time. Time `json:"latest_date"`
25
+ LatestVersion string `json:"latest_version"`
26
+ LatestDate flexibleTime `json:"latest_date"`
20
27
}
21
28
22
29
type announcement struct {
@@ -48,7 +55,7 @@ type VersionChecker struct {
48
55
// to the NewVersionChecker function.
49
56
func NewVersionChecker (opts ... Option ) * VersionChecker {
50
57
v := & VersionChecker {
51
- updatesApi : "https://check.trivy.cloud /updates" ,
58
+ updatesApi : "https://check.trivy.dev /updates" ,
52
59
currentVersion : app .Version (),
53
60
}
54
61
@@ -73,6 +80,7 @@ func (v *VersionChecker) RunUpdateCheck(ctx context.Context, args []string) {
73
80
}
74
81
75
82
go func () {
83
+ logger .Debug ("Running version check" )
76
84
args = getFlags (args )
77
85
client := & http.Client {
78
86
Timeout : 3 * time .Second ,
@@ -109,6 +117,7 @@ func (v *VersionChecker) RunUpdateCheck(ctx context.Context, args []string) {
109
117
if ! v .skipUpdateCheck && ! v .quiet {
110
118
v .responseReceived = true
111
119
}
120
+ logger .Debug ("Version check completed" , log .String ("latest_version" , v .latestVersion .Trivy .LatestVersion ))
112
121
v .done = true
113
122
}()
114
123
}
@@ -120,6 +129,8 @@ func (v *VersionChecker) PrintNotices(output io.Writer) {
120
129
return
121
130
}
122
131
132
+ logger := log .WithPrefix ("notification" )
133
+ logger .Debug ("Printing notices" )
123
134
var notices []string
124
135
125
136
notices = append (notices , v .Warnings ()... )
@@ -175,3 +186,29 @@ func getFlags(args []string) []string {
175
186
}
176
187
return flags
177
188
}
189
+
190
+ func (fd * flexibleTime ) UnmarshalJSON (b []byte ) error {
191
+ s := strings .Trim (string (b ), `"` )
192
+ if s == "" {
193
+ return nil
194
+ }
195
+
196
+ // Try parsing with time component
197
+ layouts := []string {
198
+ time .RFC3339 ,
199
+ "2006-01-02" ,
200
+ time .RFC1123 ,
201
+ }
202
+
203
+ var err error
204
+ for _ , layout := range layouts {
205
+ var t time.Time
206
+ t , err = time .Parse (layout , s )
207
+ if err == nil {
208
+ fd .Time = t
209
+ return nil
210
+ }
211
+ }
212
+
213
+ return fmt .Errorf ("unable to parse date: %s" , s )
214
+ }
0 commit comments