mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 03:27:03 -07:00
Renamed vars and switched to use zerolog
This commit is contained in:
parent
606a7b47cc
commit
b27e6b6a73
7 changed files with 68 additions and 103 deletions
|
|
@ -6,10 +6,10 @@ import (
|
|||
|
||||
magellan "github.com/OpenCHAMI/magellan/internal"
|
||||
"github.com/OpenCHAMI/magellan/internal/db/sqlite"
|
||||
"github.com/OpenCHAMI/magellan/internal/log"
|
||||
"github.com/OpenCHAMI/magellan/pkg/smd"
|
||||
"github.com/OpenCHAMI/magellan/internal/util"
|
||||
"github.com/OpenCHAMI/magellan/pkg/client"
|
||||
"github.com/cznic/mathutil"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
|
@ -30,36 +30,32 @@ var collectCmd = &cobra.Command{
|
|||
" magellan collect --cache ./assets.db --output ./logs --timeout 30 --cacert cecert.pem\n" +
|
||||
" magellan collect --host smd.example.com --port 27779 --username username --password password",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
// make application logger
|
||||
l := log.NewLogger(logrus.New(), logrus.DebugLevel)
|
||||
|
||||
// get probe states stored in db from scan
|
||||
probeStates, err := sqlite.GetProbeResults(cachePath)
|
||||
scannedResults, err := sqlite.GetScannedResults(cachePath)
|
||||
if err != nil {
|
||||
l.Log.Errorf("failed toget states: %v", err)
|
||||
log.Error().Err(err).Msgf("failed to get scanned results from cache")
|
||||
}
|
||||
|
||||
// try to load access token either from env var, file, or config if var not set
|
||||
if accessToken == "" {
|
||||
var err error
|
||||
accessToken, err = LoadAccessToken()
|
||||
accessToken, err = util.LoadAccessToken(tokenPath)
|
||||
if err != nil {
|
||||
l.Log.Errorf("failed to load access token: %v", err)
|
||||
log.Error().Err(err).Msgf("failed to load access token")
|
||||
}
|
||||
}
|
||||
|
||||
if verbose {
|
||||
fmt.Printf("access token: %v\n", accessToken)
|
||||
log.Debug().Str("Access Token", accessToken)
|
||||
}
|
||||
|
||||
//
|
||||
if concurrency <= 0 {
|
||||
concurrency = mathutil.Clamp(len(probeStates), 1, 255)
|
||||
concurrency = mathutil.Clamp(len(scannedResults), 1, 255)
|
||||
}
|
||||
q := &magellan.QueryParams{
|
||||
Username: username,
|
||||
Password: password,
|
||||
Protocol: protocol,
|
||||
Timeout: timeout,
|
||||
Concurrency: concurrency,
|
||||
Verbose: verbose,
|
||||
|
|
@ -68,23 +64,21 @@ var collectCmd = &cobra.Command{
|
|||
ForceUpdate: forceUpdate,
|
||||
AccessToken: accessToken,
|
||||
}
|
||||
err = magellan.CollectAll(&probeStates, l, q)
|
||||
err = magellan.CollectInventory(&scannedResults, q)
|
||||
if err != nil {
|
||||
l.Log.Errorf("failed to collect data: %v", err)
|
||||
log.Error().Err(err).Msgf("failed to collect data")
|
||||
}
|
||||
|
||||
// add necessary headers for final request (like token)
|
||||
headers := make(map[string]string)
|
||||
if q.AccessToken != "" {
|
||||
headers["Authorization"] = "Bearer " + q.AccessToken
|
||||
}
|
||||
header := util.HTTPHeader{}
|
||||
header.Authorization(q.AccessToken)
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
currentUser, _ = user.Current()
|
||||
collectCmd.PersistentFlags().StringVar(&smd.Host, "host", smd.Host, "set the host to the SMD API")
|
||||
collectCmd.PersistentFlags().IntVarP(&smd.Port, "port", "p", smd.Port, "set the port to the SMD API")
|
||||
collectCmd.PersistentFlags().StringVar(&client.Host, "host", client.Host, "set the host to the SMD API")
|
||||
collectCmd.PersistentFlags().IntVarP(&client.Port, "port", "p", client.Port, "set the port to the SMD API")
|
||||
collectCmd.PersistentFlags().StringVar(&username, "username", "", "set the BMC user")
|
||||
collectCmd.PersistentFlags().StringVar(&password, "password", "", "set the BMC password")
|
||||
collectCmd.PersistentFlags().StringVar(&protocol, "protocol", "https", "set the protocol used to query")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue