github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/internal/runners/cve/open.go (about)

     1  package cve
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/ActiveState/cli/internal/errs"
     7  	"github.com/ActiveState/cli/internal/locale"
     8  	"github.com/ActiveState/cli/internal/output"
     9  	"github.com/skratchdot/open-golang/open"
    10  )
    11  
    12  const cveURLPrefix = "https://nvd.nist.gov/vuln/detail/"
    13  
    14  type Open struct {
    15  	out output.Outputer
    16  }
    17  
    18  type OpenParams struct {
    19  	ID string
    20  }
    21  
    22  func NewOpen(prime primeable) *Open {
    23  	return &Open{
    24  		out: prime.Output(),
    25  	}
    26  }
    27  
    28  func (o *Open) Run(params OpenParams) error {
    29  	cveURL := fmt.Sprintf("%s%s", cveURLPrefix, params.ID)
    30  	err := open.Run(cveURL)
    31  	if err != nil {
    32  		return errs.AddTips(
    33  			locale.WrapError(err, "cve_open_url_err", "Could not open CVE detail URL: {{.V0}}", cveURL),
    34  			locale.Tr("browser_fallback", "vulnerability details", cveURL),
    35  		)
    36  	}
    37  	o.out.Print(locale.Tl("cve_open_url", "Vulnerability detail URL: [ACTIONABLE]{{.V0}}[/RESET]", cveURL))
    38  
    39  	return nil
    40  }