From f4540ea4ce8d6ac951e9cd49ab4722c4eaf060e6 Mon Sep 17 00:00:00 2001 From: "David J. Allen" Date: Fri, 10 May 2024 14:54:34 -0600 Subject: [PATCH] Changed db.path flag to cache --- README.md | 10 +++++----- cmd/collect.go | 2 +- cmd/list.go | 2 +- cmd/root.go | 8 ++++---- cmd/scan.go | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 5e2aecc..912d90a 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ Available Commands: Flags: --access-token string set the access token -c, --config string set the config file path - --db.path string set the probe storage path (default "/tmp/magellan/magellan.db") + --cache string set the probe storage path (default "/tmp/magellan/magellan.db") -h, --help help for magellan --threads int set the number of threads (default -1) --timeout int set the timeout (default 30) @@ -101,7 +101,7 @@ There are three main commands to use with the tool: `scan`, `list`, and `collect --subnet 172.16.0.0 \ --subnet-mask 255.255.255.0 \ --format json \ - --db.path data/assets.db --port 443 + --cache data/assets.db --port 443 ``` This will scan the `172.16.0.0` subnet returning the host and port that return a response and store the results in a local cache with at the `data/assets.db` path. Additional flags can be set such as `--host` to add more hosts to scan not included on the subnet, `--timeout` to set how long to wait for a response from the BMC node, or `--concurrency` to set the number of requests to make concurrently. Setting the `--format=json` will format the output in JSON. Try using `./magellan help scan` for a complete set of options this subcommand. @@ -109,7 +109,7 @@ This will scan the `172.16.0.0` subnet returning the host and port that return a To inspect the cache, use the `list` command. Make sure to point to the same database used before: ```bash -./magellan list --db.path data/assets.db --format json +./magellan list --cache data/assets.db --format json ``` This will print a list of node info found and stored from the scan. Like the `scan` subcommand, the output format can be set using the `--format` flag. @@ -118,7 +118,7 @@ Finally, set the `MAGELLAN_ACCESS_TOKEN`run the `collect` command to query the n ```bash ./magellan collect \ - --db.path data/assets.db \ + --cache data/assets.db \ --timeout 5 \ --user admin \ --pass password \ @@ -130,7 +130,7 @@ Finally, set the `MAGELLAN_ACCESS_TOKEN`run the `collect` command to query the n This uses the info stored in cache to request information about each BMC node if possible. Like with the scan, the time to wait for a response can be set with the `--timeout` flag as well. This command also requires the `--user` and `--pass` flags to be set if access the Redfish service requires basic authentication. Additionally, it may be necessary to set the `--host` and `--port` flags for `magellan` to find the SMD API (not the root API endpoint "/hsm/v2"). The output of the `collect` can be saved by using the `--output` -Note: If the `db.path` flag is not set, `magellan` will use "/tmp/$USER/magellan.db" by default. +Note: If the `cache` flag is not set, `magellan` will use "/tmp/$USER/magellan.db" by default. ### Getting an Access Token (WIP) diff --git a/cmd/collect.go b/cmd/collect.go index 2065101..fc3454c 100644 --- a/cmd/collect.go +++ b/cmd/collect.go @@ -26,7 +26,7 @@ var collectCmd = &cobra.Command{ l := log.NewLogger(logrus.New(), logrus.DebugLevel) // get probe states stored in db from scan - probeStates, err := sqlite.GetProbeResults(dbpath) + probeStates, err := sqlite.GetProbeResults(cachePath) if err != nil { l.Log.Errorf("failed toget states: %v", err) } diff --git a/cmd/list.go b/cmd/list.go index 5c1a46c..845da29 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -15,7 +15,7 @@ var listCmd = &cobra.Command{ Use: "list", Short: "List information from scan", Run: func(cmd *cobra.Command, args []string) { - probeResults, err := sqlite.GetProbeResults(dbpath) + probeResults, err := sqlite.GetProbeResults(cachePath) if err != nil { logrus.Errorf("failed toget probe results: %v\n", err) } diff --git a/cmd/root.go b/cmd/root.go index 0e1697c..ef488bc 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -24,7 +24,7 @@ var ( cacertPath string username string password string - dbpath string + cachePath string outputPath string configPath string verbose bool @@ -83,13 +83,13 @@ func init() { rootCmd.PersistentFlags().StringVarP(&configPath, "config", "c", "", "set the config file path") rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "set output verbosity") rootCmd.PersistentFlags().StringVar(&accessToken, "access-token", "", "set the access token") - rootCmd.PersistentFlags().StringVar(&dbpath, "db.path", fmt.Sprintf("/tmp/%smagellan/magellan.db", currentUser.Username+"/"), "set the probe storage path") + rootCmd.PersistentFlags().StringVar(&cachePath, "cache", fmt.Sprintf("/tmp/%smagellan/magellan.db", currentUser.Username+"/"), "set the scanning result cache path") // bind viper config flags with cobra viper.BindPFlag("concurrency", rootCmd.Flags().Lookup("concurrency")) viper.BindPFlag("timeout", rootCmd.Flags().Lookup("timeout")) viper.BindPFlag("verbose", rootCmd.Flags().Lookup("verbose")) - viper.BindPFlag("db.path", rootCmd.Flags().Lookup("db.path")) + viper.BindPFlag("cache", rootCmd.Flags().Lookup("cache")) viper.BindPFlags(rootCmd.Flags()) } @@ -104,7 +104,7 @@ func SetDefaults() { viper.SetDefault("timeout", 30) viper.SetDefault("config", "") viper.SetDefault("verbose", false) - viper.SetDefault("db.path", "/tmp/magellan/magellan.db") + viper.SetDefault("cache", "/tmp/magellan/magellan.db") viper.SetDefault("scan.hosts", []string{}) viper.SetDefault("scan.ports", []int{}) viper.SetDefault("scan.subnets", []string{}) diff --git a/cmd/scan.go b/cmd/scan.go index 557d061..563629f 100644 --- a/cmd/scan.go +++ b/cmd/scan.go @@ -82,12 +82,12 @@ var scanCmd = &cobra.Command{ } // make the dbpath dir if needed - err := os.MkdirAll(path.Dir(dbpath), 0766) + err := os.MkdirAll(path.Dir(cachePath), 0766) if err != nil { fmt.Printf("failed tomake database directory: %v", err) } - sqlite.InsertProbeResults(dbpath, &probeStates) + sqlite.InsertProbeResults(cachePath, &probeStates) }, }