mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 03:27:03 -07:00
Add support for storage command and crawler output
Partially addresses issue #3 by adding a simple `magellan list devices` command to list storage devices. To close the issue, this PR still requires including storage device information in the `crawler`'s output. Reviewed-on: towk/magellan-ng#5
This commit is contained in:
parent
d236649b05
commit
b2111ddcb2
20 changed files with 450 additions and 18 deletions
34
cmd/list.go
34
cmd/list.go
|
|
@ -1,13 +1,16 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/davidallendj/magellan/internal/cache/sqlite"
|
||||
urlx "github.com/davidallendj/magellan/internal/urlx"
|
||||
magellan "github.com/davidallendj/magellan/pkg"
|
||||
"github.com/davidallendj/magellan/pkg/crawler"
|
||||
"github.com/davidallendj/magellan/pkg/secrets"
|
||||
"github.com/rs/zerolog/log"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
|
|
@ -34,15 +37,17 @@ var ListCmd = &cobra.Command{
|
|||
"See the 'scan' command on how to perform a scan.",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
// check if we just want to show cache-related info and exit
|
||||
if showCache {
|
||||
fmt.Printf("cache: %s\n", cachePath)
|
||||
return
|
||||
if showCacheInfo {
|
||||
magellan.PrintMapFormat(map[string]any{
|
||||
"path": cachePath,
|
||||
}, format)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
// load the assets found from scan
|
||||
scannedResults, err := sqlite.GetScannedAssets(cachePath)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("failed to get scanned assets")
|
||||
log.Error().Err(err).Str("path", cachePath).Msg("failed to get scanned assets from cache")
|
||||
}
|
||||
switch strings.ToLower(listOutputFormat) {
|
||||
case FORMAT_JSON:
|
||||
|
|
@ -65,6 +70,25 @@ var ListCmd = &cobra.Command{
|
|||
log.Error().Msg("unrecognized format")
|
||||
os.Exit(1)
|
||||
}
|
||||
args[0], err = urlx.Sanitize(args[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to sanitize URI: %w", err)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
store := secrets.NewStaticStore(listUsername, listPassword)
|
||||
drives, err := magellan.ListDrives(&crawler.CrawlerConfig{
|
||||
URI: args[0],
|
||||
CredentialStore: store, //initSecretsStore(args[0]),
|
||||
Insecure: insecure,
|
||||
UseDefault: false,
|
||||
})
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("failed to get drives")
|
||||
os.Exit(1)
|
||||
}
|
||||
magellan.PrintDrives(drives)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue