-
Notifications
You must be signed in to change notification settings - Fork 13
/
open.go
40 lines (32 loc) · 890 Bytes
/
open.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
package cve
import (
"fmt"
"github.com/ActiveState/cli/internal/errs"
"github.com/ActiveState/cli/internal/locale"
"github.com/ActiveState/cli/internal/output"
"github.com/skratchdot/open-golang/open"
)
const cveURLPrefix = "https://nvd.nist.gov/vuln/detail/"
type Open struct {
out output.Outputer
}
type OpenParams struct {
ID string
}
func NewOpen(prime primeable) *Open {
return &Open{
out: prime.Output(),
}
}
func (o *Open) Run(params OpenParams) error {
cveURL := fmt.Sprintf("%s%s", cveURLPrefix, params.ID)
err := open.Run(cveURL)
if err != nil {
return errs.AddTips(
locale.WrapError(err, "cve_open_url_err", "Could not open CVE detail URL: {{.V0}}", cveURL),
locale.Tr("browser_fallback", "vulnerability details", cveURL),
)
}
o.out.Print(locale.Tl("cve_open_url", "Vulnerability detail URL: [ACTIONABLE]{{.V0}}[/RESET]", cveURL))
return nil
}