Skip to content

Commit 34375e4

Browse files
tatianabTatiana Bradley
authored andcommitted
internal/cveclient, cmd/cve: tweak output of CVE publish
Modify cve publish to: 1) support the new MITRE web test instance, which displays test CVE records 2) print out a link to the existing CVE record if it exists 3) not print out the full published CVE record Also moves the logic for computing the web link to the cveclient instead of the reports package. Change-Id: I04b0ef8b93650b834908b29b7a2fa10eb41bf12a Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/459597 Reviewed-by: Julie Qiu <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Tatiana Bradley <[email protected]> Run-TryBot: Tatiana Bradley <[email protected]>
1 parent 10819e1 commit 34375e4

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

cmd/cve/main.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"github.com/google/go-cmp/cmp"
2323
"golang.org/x/vulndb/internal/cveclient"
2424
"golang.org/x/vulndb/internal/cveschema5"
25-
"golang.org/x/vulndb/internal/report"
2625
)
2726

2827
var (
@@ -322,10 +321,11 @@ func publish(c *cveclient.Client, filename string) (err error) {
322321
if err != nil {
323322
return err
324323
}
324+
fmt.Printf("%s is published at %s\n", cveID, c.GetWebURL(cveID))
325325
if diff := cmp.Diff(existing.Containers, *toPublish); diff != "" {
326-
fmt.Printf("publish would update record for %s (-existing, +new):\n%s\n", cveID, diff)
326+
fmt.Printf("publish would update record with diff (-existing, +new):\n%s\n", diff)
327327
} else {
328-
fmt.Printf("updating record for %s would have no effect, skipping\n", cveID)
328+
fmt.Println("updating record would have no effect, skipping")
329329
return nil
330330
}
331331
publish = c.UpdateRecord
@@ -346,12 +346,12 @@ func publish(c *cveclient.Client, filename string) (err error) {
346346
return nil
347347
}
348348

349-
published, err := publish(cveID, toPublish)
349+
_, err = publish(cveID, toPublish)
350350
if err != nil {
351351
return err
352352
}
353353

354-
fmt.Printf("successfully %sd record for %s:\n\n%v\n\nlink: %s%s\n", action, cveID, toJSON(published), report.MITREPrefix, cveID)
354+
fmt.Printf("successfully %sd record for %s at %s\n", action, cveID, c.GetWebURL(cveID))
355355

356356
return nil
357357
}

internal/cveclient/cveclient.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ const (
2727
TestEndpoint = "https://cveawg-test.mitre.org"
2828
// DevEndpoint is the dev endpoint
2929
DevEndpoint = "https://cveawg-dev.mitre.org"
30+
31+
// WebURL is the URL to view production CVE records on the web.
32+
WebURL = "https://www.cve.org"
33+
// TestWebURL is the URL to view test CVE records on the web.
34+
TestWebURL = "https://test.cve.org"
3035
)
3136

3237
// Client is a MITRE CVE Services API client.
@@ -35,6 +40,16 @@ type Client struct {
3540
c *http.Client
3641
}
3742

43+
// GetWebURL returns the URL that can be used to view a published
44+
// CVE record on the web.
45+
func (c *Client) GetWebURL(cveID string) string {
46+
baseURL := WebURL
47+
if c.Config.Endpoint == TestEndpoint {
48+
baseURL = TestWebURL
49+
}
50+
return fmt.Sprintf("%s/CVERecord?id=%s", baseURL, cveID)
51+
}
52+
3853
// Config contains client configuration data.
3954
type Config struct {
4055
// Endpoint is the endpoint to access when making API calls. Required.

internal/report/report.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ func (r *Report) GetAliases() []string {
216216

217217
const (
218218
NISTPrefix = "https://nvd.nist.gov/vuln/detail/"
219-
MITREPrefix = "https://www.cve.org/CVERecord?id="
220219
ghsaURLPrefix = "https://github.com/advisories/"
221220
goURLPrefix = "https://pkg.go.dev/vuln/"
222221
)

0 commit comments

Comments
 (0)