Fixed formatting via gofmt

Signed-off-by: David J. Allen <davidallendj@gmail.com>
This commit is contained in:
David Allen 2023-09-15 08:32:41 -06:00
parent ac9556a526
commit b3368e5264
11 changed files with 94 additions and 103 deletions

View file

@ -10,9 +10,8 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
var collectCmd = &cobra.Command{ var collectCmd = &cobra.Command{
Use: "collect", Use: "collect",
Short: "Query information about BMC", Short: "Query information about BMC",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
// make application logger // make application logger
@ -28,14 +27,14 @@ var collectCmd = &cobra.Command{
threads = mathutil.Clamp(len(probeStates), 1, 255) threads = mathutil.Clamp(len(probeStates), 1, 255)
} }
q := &magellan.QueryParams{ q := &magellan.QueryParams{
User: user, User: user,
Pass: pass, Pass: pass,
Drivers: drivers, Drivers: drivers,
Preferred: preferredDriver, Preferred: preferredDriver,
Timeout: timeout, Timeout: timeout,
Threads: threads, Threads: threads,
Verbose: verbose, Verbose: verbose,
WithSecureTLS: withSecureTLS, WithSecureTLS: withSecureTLS,
} }
magellan.CollectInfo(&probeStates, l, q) magellan.CollectInfo(&probeStates, l, q)
@ -47,7 +46,7 @@ var collectCmd = &cobra.Command{
}, },
} }
func init(){ func init() {
collectCmd.PersistentFlags().StringSliceVar(&drivers, "driver", []string{"redfish"}, "set the driver(s) and fallback drivers to use") collectCmd.PersistentFlags().StringSliceVar(&drivers, "driver", []string{"redfish"}, "set the driver(s) and fallback drivers to use")
collectCmd.PersistentFlags().StringVar(&smd.Host, "host", smd.Host, "set the host to the smd API") collectCmd.PersistentFlags().StringVar(&smd.Host, "host", smd.Host, "set the host to the smd API")
collectCmd.PersistentFlags().IntVar(&smd.Port, "port", smd.Port, "set the port to the smd API") collectCmd.PersistentFlags().IntVar(&smd.Port, "port", smd.Port, "set the port to the smd API")

View file

@ -8,9 +8,8 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
var listCmd = &cobra.Command{ var listCmd = &cobra.Command{
Use: "list", Use: "list",
Short: "List information from scan", Short: "List information from scan",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
probeResults, err := sqlite.GetProbeResults(dbpath) probeResults, err := sqlite.GetProbeResults(dbpath)

View file

@ -8,19 +8,19 @@ import (
) )
var ( var (
timeout int timeout int
threads int threads int
ports []int ports []int
hosts []string hosts []string
withSecureTLS bool withSecureTLS bool
certPoolFile string certPoolFile string
user string user string
pass string pass string
dbpath string dbpath string
drivers []string drivers []string
preferredDriver string preferredDriver string
ipmitoolPath string ipmitoolPath string
verbose bool verbose bool
) )
// TODO: discover bmc's on network (dora) // TODO: discover bmc's on network (dora)

View file

@ -9,23 +9,23 @@ import (
) )
const ( const (
Host = "http://localhost" Host = "http://localhost"
DbType = "sqlite3" DbType = "sqlite3"
DbPath = "../data/assets.db" DbPath = "../data/assets.db"
BaseEndpoint = "/v1" BaseEndpoint = "/v1"
Port = 8000 Port = 8000
) )
type ScannedResult struct { type ScannedResult struct {
id string id string
site any site any
cidr string cidr string
ip string ip string
port int port int
protocol string protocol string
scanner string scanner string
state string state string
updated string updated string
} }
func makeEndpointUrl(endpoint string) string { func makeEndpointUrl(endpoint string) string {

View file

@ -10,12 +10,11 @@ import (
) )
var ( var (
Host = "http://localhost" Host = "http://localhost"
BaseEndpoint = "/hsm/v2" BaseEndpoint = "/hsm/v2"
Port = 27779 Port = 27779
) )
func makeEndpointUrl(endpoint string) string { func makeEndpointUrl(endpoint string) string {
return Host + ":" + fmt.Sprint(Port) + BaseEndpoint + endpoint return Host + ":" + fmt.Sprint(Port) + BaseEndpoint + endpoint
} }

View file

@ -7,7 +7,6 @@ import (
"net/http" "net/http"
) )
func MakeRequest(url string, httpMethod string, body []byte, headers map[string]string) (*http.Response, []byte, error) { func MakeRequest(url string, httpMethod string, body []byte, headers map[string]string) (*http.Response, []byte, error) {
// url := getSmdEndpointUrl(endpoint) // url := getSmdEndpointUrl(endpoint)
req, _ := http.NewRequest(httpMethod, url, bytes.NewBuffer(body)) req, _ := http.NewRequest(httpMethod, url, bytes.NewBuffer(body))

View file

@ -23,9 +23,9 @@ import (
) )
const ( const (
IPMI_PORT = 623 IPMI_PORT = 623
SSH_PORT = 22 SSH_PORT = 22
HTTPS_PORT = 443 HTTPS_PORT = 443
) )
type BMCProbeResult struct { type BMCProbeResult struct {
@ -42,13 +42,13 @@ type QueryParams struct {
User string User string
Pass string Pass string
Drivers []string Drivers []string
Threads int Threads int
Preferred string Preferred string
Timeout int Timeout int
WithSecureTLS bool WithSecureTLS bool
CertPoolFile string CertPoolFile string
Verbose bool Verbose bool
IpmitoolPath string IpmitoolPath string
} }
func NewClient(l *Logger, q *QueryParams) (*bmclib.Client, error) { func NewClient(l *Logger, q *QueryParams) (*bmclib.Client, error) {
@ -116,15 +116,15 @@ func CollectInfo(probeStates *[]BMCProbeResult, l *Logger, q *QueryParams) error
// generate custom xnames for bmcs // generate custom xnames for bmcs
node := xnames.Node{ node := xnames.Node{
Cabinet: 1000, Cabinet: 1000,
Chassis: 1, Chassis: 1,
ComputeModule: 7, ComputeModule: 7,
NodeBMC: -1, NodeBMC: -1,
} }
found := make([]string, 0, len(*probeStates)) found := make([]string, 0, len(*probeStates))
done := make(chan struct{}, q.Threads+1) done := make(chan struct{}, q.Threads+1)
chanProbeState := make(chan BMCProbeResult, q.Threads+1) chanProbeState := make(chan BMCProbeResult, q.Threads+1)
// collect bmc information asynchronously // collect bmc information asynchronously
var wg sync.WaitGroup var wg sync.WaitGroup
@ -132,7 +132,7 @@ func CollectInfo(probeStates *[]BMCProbeResult, l *Logger, q *QueryParams) error
for i := 0; i < q.Threads; i++ { for i := 0; i < q.Threads; i++ {
go func() { go func() {
for { for {
ps, ok := <- chanProbeState ps, ok := <-chanProbeState
if !ok { if !ok {
wg.Done() wg.Done()
return return
@ -171,15 +171,15 @@ func CollectInfo(probeStates *[]BMCProbeResult, l *Logger, q *QueryParams) error
headers["Content-Type"] = "application/json" headers["Content-Type"] = "application/json"
data := make(map[string]any) data := make(map[string]any)
data["ID"] = fmt.Sprintf("%v", node.String()[:len(node.String())-2]) data["ID"] = fmt.Sprintf("%v", node.String()[:len(node.String())-2])
data["Type"] = "" data["Type"] = ""
data["Name"] = "" data["Name"] = ""
data["FQDN"] = ps.Host data["FQDN"] = ps.Host
data["User"] = q.User data["User"] = q.User
data["Password"] = q.Pass data["Password"] = q.Pass
data["RediscoverOnUpdate"] = false data["RediscoverOnUpdate"] = false
data["Inventory"] = inventory data["Inventory"] = inventory
data["Chassis"] = chassis data["Chassis"] = chassis
b, err := json.MarshalIndent(data, "", " ") b, err := json.MarshalIndent(data, "", " ")
if err != nil { if err != nil {
@ -222,7 +222,7 @@ func CollectInfo(probeStates *[]BMCProbeResult, l *Logger, q *QueryParams) error
for _, ps := range *probeStates { for _, ps := range *probeStates {
// skip if found info from host // skip if found info from host
foundHost := slices.Index(found, ps.Host) foundHost := slices.Index(found, ps.Host)
if !ps.State || foundHost >= 0{ if !ps.State || foundHost >= 0 {
continue continue
} }
chanProbeState <- ps chanProbeState <- ps
@ -388,11 +388,11 @@ func QueryBios(client *bmclib.Client, l *Logger, q *QueryParams) ([]byte, error)
func QueryEthernetInterfaces(client *bmclib.Client, l *Logger, q *QueryParams) ([]byte, error) { func QueryEthernetInterfaces(client *bmclib.Client, l *Logger, q *QueryParams) ([]byte, error) {
config := gofish.ClientConfig{ config := gofish.ClientConfig{
Endpoint: fmt.Sprintf("https://%s:%d", q.Host, q.Port), Endpoint: fmt.Sprintf("https://%s:%d", q.Host, q.Port),
Username: q.User, Username: q.User,
Password: q.Pass, Password: q.Pass,
Insecure: !q.WithSecureTLS, Insecure: !q.WithSecureTLS,
TLSHandshakeTimeout: q.Timeout, TLSHandshakeTimeout: q.Timeout,
} }
c, err := gofish.Connect(config) c, err := gofish.Connect(config)
if err != nil { if err != nil {
@ -417,12 +417,12 @@ func QueryChassis(q *QueryParams) ([]byte, error) {
url += fmt.Sprintf("%s:%s@", q.User, q.Pass) url += fmt.Sprintf("%s:%s@", q.User, q.Pass)
} }
url += fmt.Sprintf("%s:%d", q.Host, q.Port) url += fmt.Sprintf("%s:%d", q.Host, q.Port)
config := gofish.ClientConfig { config := gofish.ClientConfig{
Endpoint: url, Endpoint: url,
Username: q.User, Username: q.User,
Password: q.Pass, Password: q.Pass,
Insecure: !q.WithSecureTLS, Insecure: !q.WithSecureTLS,
TLSHandshakeTimeout: q.Timeout, TLSHandshakeTimeout: q.Timeout,
} }
c, err := gofish.Connect(config) c, err := gofish.Connect(config)
if err != nil { if err != nil {

View file

@ -4,23 +4,19 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
type Logger struct { type Logger struct {
Log *logrus.Logger Log *logrus.Logger
Path string Path string
} }
func NewLogger(l *logrus.Logger, level logrus.Level) *Logger { func NewLogger(l *logrus.Logger, level logrus.Level) *Logger {
l.SetLevel(level) l.SetLevel(level)
return &Logger{ return &Logger{
Log: logrus.New(), Log: logrus.New(),
Path: "", Path: "",
} }
} }
func (l *Logger) WriteFile(path string) {
func (l *Logger)WriteFile(path string) {
} }

View file

@ -7,7 +7,6 @@ import (
"time" "time"
) )
func rawConnect(host string, ports []int, timeout int, keepOpenOnly bool) []BMCProbeResult { func rawConnect(host string, ports []int, timeout int, keepOpenOnly bool) []BMCProbeResult {
results := []BMCProbeResult{} results := []BMCProbeResult{}
for _, p := range ports { for _, p := range ports {
@ -52,9 +51,9 @@ func GenerateHosts(subnet string, begin uint8, end uint8) []string {
} }
func ScanForAssets(hosts []string, ports []int, threads int, timeout int) []BMCProbeResult { func ScanForAssets(hosts []string, ports []int, threads int, timeout int) []BMCProbeResult {
results := make([]BMCProbeResult, 0, len(hosts)) results := make([]BMCProbeResult, 0, len(hosts))
done := make(chan struct{}, threads+1) done := make(chan struct{}, threads+1)
chanHost := make(chan string, threads+1) chanHost := make(chan string, threads+1)
// chanPort := make(chan int, threads+1) // chanPort := make(chan int, threads+1)
var wg sync.WaitGroup var wg sync.WaitGroup