Skip to content

Commit 9692465

Browse files
committed
🚧 good progress with status - golang scans need work - need to figure out how to parse the versions correctly
1 parent f65c598 commit 9692465

File tree

8 files changed

+70
-11
lines changed

8 files changed

+70
-11
lines changed

‎pkg/cmd/offline/offline.go

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"github.com/vulncheck-oss/cli/pkg/cmd/offline/cpe"
66
"github.com/vulncheck-oss/cli/pkg/cmd/offline/ipintel"
77
"github.com/vulncheck-oss/cli/pkg/cmd/offline/purl"
8+
"github.com/vulncheck-oss/cli/pkg/cmd/offline/status"
89
"github.com/vulncheck-oss/cli/pkg/cmd/offline/sync"
910
)
1011

@@ -24,6 +25,7 @@ func Command() *cobra.Command {
2425
cmd.AddCommand(ipintel.AliasCommands()...)
2526
cmd.AddCommand(purl.Command())
2627
cmd.AddCommand(cpe.Command())
28+
cmd.AddCommand(status.Command())
2729

2830
return cmd
2931
}

‎pkg/cmd/offline/status/status.go

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package status
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
"github.com/vulncheck-oss/cli/pkg/cache"
6+
"github.com/vulncheck-oss/cli/pkg/i18n"
7+
"github.com/vulncheck-oss/cli/pkg/ui"
8+
)
9+
10+
func Command() *cobra.Command {
11+
cmd := &cobra.Command{
12+
Use: "status",
13+
Short: i18n.C.OfflineStatusShort,
14+
Long: i18n.C.OfflineStatusLong,
15+
RunE: func(cmd *cobra.Command, args []string) error {
16+
indices, err := cache.Indices()
17+
if err != nil {
18+
return err
19+
}
20+
21+
// Format and display the indices using the table UI
22+
if err := ui.CacheResults(indices.Indices); err != nil {
23+
return err
24+
}
25+
26+
return nil
27+
},
28+
}
29+
return cmd
30+
}

‎pkg/cmd/scan/scan.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ import (
1616
)
1717

1818
type Options struct {
19-
File bool
20-
FileName string
21-
SbomFile string
22-
SbomInput string
23-
OfflinePurl bool
19+
File bool
20+
FileName string
21+
SbomFile string
22+
SbomInput string
23+
Offline bool
2424
}
2525

2626
func Command() *cobra.Command {
@@ -93,7 +93,7 @@ func Command() *cobra.Command {
9393
},
9494
}...)
9595

96-
if opts.OfflinePurl {
96+
if opts.Offline {
9797
tasks = append(tasks, taskin.Tasks{
9898
{
9999
Title: i18n.C.ScanScanPurlStartOffline,
@@ -221,7 +221,7 @@ func Command() *cobra.Command {
221221
cmd.Flags().StringVarP(&opts.FileName, "file-name", "n", "output.json", i18n.C.FlagSpecifyFile)
222222
cmd.Flags().StringVarP(&opts.SbomFile, "sbom-output-file", "o", "", i18n.C.FlagSpecifySbomFile)
223223
cmd.Flags().StringVarP(&opts.SbomInput, "sbom-input-file", "i", "", i18n.C.FlagSpecifySbomFile)
224-
cmd.Flags().BoolVar(&opts.OfflinePurl, "offline-purl", false, "Use offline PURL functionality to find CVEs")
224+
cmd.Flags().BoolVar(&opts.Offline, "offline", false, "Use offline mode to find CVEs - requires indices to be cached")
225225

226226
return cmd
227227

‎pkg/db/purl.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"encoding/json"
66
"fmt"
77
_ "github.com/mattn/go-sqlite3"
8-
"github.com/octoper/go-ray"
98
"github.com/package-url/packageurl-go"
109
"github.com/vulncheck-oss/sdk-go"
1110
"strings"
@@ -29,8 +28,10 @@ func PURLSearch(indexName string, instance packageurl.PackageURL) ([]PurlEntry,
2928
}
3029

3130
tableName := strings.ReplaceAll(indexName, "-", "_")
32-
schema := GetSchema(indexName)
33-
ray.Ray(schema.Name, instance)
31+
/*
32+
schema := GetSchema(indexName)
33+
ray.Ray(schema.Name, instance)
34+
*/
3435
query := fmt.Sprintf("SELECT name, version, purl, cves, vulnerabilities FROM `%s` WHERE purl LIKE ?", tableName)
3536

3637
rows, err := db.Query(query, "%"+instance.String()+"%")

‎pkg/db/schema.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ var Schemas = []Schema{
5151
{
5252
Name: "purl PM",
5353
Indices: []string{
54-
"cargo", "npm", "gem", "pypi", "maven", "nuget", "composer", "hackage", "cran", "pub", "conan", "swift", "go", "dub", "elixir", "julia", "luarocks", "opam", "r", "vcpkg",
54+
"cargo", "golang", "npm", "gem", "pypi", "maven", "nuget", "composer", "hackage", "cran", "pub", "conan", "swift", "go", "dub", "elixir", "julia", "luarocks", "opam", "r", "vcpkg",
5555
},
5656
Columns: []Column{
5757
{Name: "name", Type: "TEXT", Index: false, NotNull: true},

‎pkg/i18n/i18n.go

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ type Copy struct {
1919
AuthLogoutErrorFailed string
2020
AuthLogoutErrorInvalidToken string
2121

22+
OfflineStatusShort string
23+
OfflineStatusLong string
24+
2225
AuthLoginToken string
2326
AuthLoginWeb string
2427

@@ -256,6 +259,9 @@ var En = Copy{
256259

257260
ErrorUnauthorized: "Error: Unauthorized, Try authenticating with: vulncheck auth login",
258261
ErrorNoToken: "No token found. Please run `vulncheck auth login` to authenticate or populate the environment variable `VC_TOKEN`.",
262+
263+
OfflineStatusShort: "Check the status of the offline database",
264+
OfflineStatusLong: "Check the status of the offline database",
259265
}
260266

261267
func Init() {

‎pkg/ui/table.go

+16
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package ui
33
import (
44
"fmt"
55
"github.com/package-url/packageurl-go"
6+
"github.com/vulncheck-oss/cli/pkg/cache"
7+
"github.com/vulncheck-oss/cli/pkg/utils"
68
"os"
79
"strings"
810

@@ -267,6 +269,20 @@ func ScanResults(results []models.ScanResultVulnerabilities) error {
267269
return nil
268270
}
269271

272+
func CacheResults(results []cache.IndexInfo) error {
273+
t := ltable.New().
274+
BorderStyle(lipgloss.NewStyle().Foreground(lipgloss.Color("#6667ab"))).
275+
Headers("Index", "Last Sync", "Size").
276+
Width(TermWidth())
277+
278+
for _, result := range results {
279+
t.Row(result.Name, utils.GetDateHuman(result.LastSync), utils.GetSizeHuman(result.Size))
280+
}
281+
282+
fmt.Println(t)
283+
return nil
284+
}
285+
270286
func SingleColumnResults(results []string, title string) error {
271287
t := ltable.New().
272288
BorderStyle(lipgloss.NewStyle().Foreground(lipgloss.Color("#6667ab"))).

‎pkg/utils/utils.go

+4
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,7 @@ func GetDirectorySize(path string) (uint64, error) {
128128
func GetSizeHuman(size uint64) string {
129129
return humanize.Bytes(size)
130130
}
131+
132+
func GetDateHuman(date time.Time) string {
133+
return humanize.Time(date)
134+
}

0 commit comments

Comments
 (0)