mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 03:27:03 -07:00
Changed the wording of error messages slightly
This commit is contained in:
parent
cc7bad8b94
commit
0403b2bcbc
11 changed files with 31 additions and 32 deletions
|
|
@ -45,13 +45,13 @@ func QueryScannedPorts() error {
|
|||
url := makeEndpointUrl("/scanned_ports")
|
||||
_, body, err := util.MakeRequest(nil, url, "GET", nil, nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not discover assets: %v", err)
|
||||
return fmt.Errorf("failed todiscover assets: %v", err)
|
||||
}
|
||||
|
||||
// get data from JSON
|
||||
var res map[string]any
|
||||
if err := json.Unmarshal(body, &res); err != nil {
|
||||
return fmt.Errorf("could not unmarshal response body: %v", err)
|
||||
return fmt.Errorf("failed tounmarshal response body: %v", err)
|
||||
}
|
||||
data := res["data"]
|
||||
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ func (c *Client) GetRedfishEndpoints(headers map[string]string, opts ...Option)
|
|||
url := makeEndpointUrl("/Inventory/RedfishEndpoints")
|
||||
_, body, err := c.MakeRequest(url, "GET", nil, headers)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not get endpoint: %v", err)
|
||||
return fmt.Errorf("failed toget endpoint: %v", err)
|
||||
}
|
||||
// fmt.Println(res)
|
||||
fmt.Println(string(body))
|
||||
|
|
@ -90,7 +90,7 @@ func (c *Client) GetComponentEndpoint(xname string) error {
|
|||
url := makeEndpointUrl("/Inventory/ComponentsEndpoints/" + xname)
|
||||
res, body, err := c.MakeRequest(url, "GET", nil, nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not get endpoint: %v", err)
|
||||
return fmt.Errorf("failed toget endpoint: %v", err)
|
||||
}
|
||||
fmt.Println(res)
|
||||
fmt.Println(string(body))
|
||||
|
|
@ -99,7 +99,7 @@ func (c *Client) GetComponentEndpoint(xname string) error {
|
|||
|
||||
func (c *Client) AddRedfishEndpoint(data []byte, headers map[string]string) error {
|
||||
if data == nil {
|
||||
return fmt.Errorf("could not add redfish endpoint: no data found")
|
||||
return fmt.Errorf("failed toadd redfish endpoint: no data found")
|
||||
}
|
||||
|
||||
// Add redfish endpoint via POST `/hsm/v2/Inventory/RedfishEndpoints` endpoint
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ func LoadConfig(path string) error {
|
|||
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
|
||||
return fmt.Errorf("config file not found: %w", err)
|
||||
} else {
|
||||
return fmt.Errorf("could not load config file: %w", err)
|
||||
return fmt.Errorf("failed toload config file: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ func CreateProbeResultsIfNotExists(path string) (*sqlx.DB, error) {
|
|||
// TODO: it may help with debugging to check for file permissions here first
|
||||
db, err := sqlx.Open("sqlite3", path)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not open database: %v", err)
|
||||
return nil, fmt.Errorf("failed toopen database: %v", err)
|
||||
}
|
||||
db.MustExec(schema)
|
||||
return db, nil
|
||||
|
|
@ -45,12 +45,12 @@ func InsertProbeResults(path string, states *[]magellan.ScannedResult) error {
|
|||
VALUES (:host, :port, :protocol, :state);`
|
||||
_, err := tx.NamedExec(sql, &state)
|
||||
if err != nil {
|
||||
fmt.Printf("could not execute transaction: %v\n", err)
|
||||
fmt.Printf("failed toexecute transaction: %v\n", err)
|
||||
}
|
||||
}
|
||||
err = tx.Commit()
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not commit transaction: %v", err)
|
||||
return fmt.Errorf("failed tocommit transaction: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
@ -61,20 +61,20 @@ func DeleteProbeResults(path string, results *[]magellan.ScannedResult) error {
|
|||
}
|
||||
db, err := sqlx.Open("sqlite3", path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not open database: %v", err)
|
||||
return fmt.Errorf("failed toopen database: %v", err)
|
||||
}
|
||||
tx := db.MustBegin()
|
||||
for _, state := range *results {
|
||||
sql := `DELETE FROM magellan_scanned_ports WHERE host = :host, port = :port;`
|
||||
_, err := tx.NamedExec(sql, &state)
|
||||
if err != nil {
|
||||
fmt.Printf("could not execute transaction: %v\n", err)
|
||||
fmt.Printf("failed toexecute transaction: %v\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
err = tx.Commit()
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not commit transaction: %v", err)
|
||||
return fmt.Errorf("failed tocommit transaction: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
@ -82,13 +82,13 @@ func DeleteProbeResults(path string, results *[]magellan.ScannedResult) error {
|
|||
func GetProbeResults(path string) ([]magellan.ScannedResult, error) {
|
||||
db, err := sqlx.Open("sqlite3", path)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not open database: %v", err)
|
||||
return nil, fmt.Errorf("failed toopen database: %v", err)
|
||||
}
|
||||
|
||||
results := []magellan.ScannedResult{}
|
||||
err = db.Select(&results, "SELECT * FROM magellan_scanned_ports ORDER BY host ASC, port ASC;")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not retrieve probes: %v", err)
|
||||
return nil, fmt.Errorf("failed toretrieve probes: %v", err)
|
||||
}
|
||||
return results, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ func UpdateFirmware(client *bmclib.Client, l *log.Logger, q *UpdateParams) error
|
|||
err := client.Open(ctx)
|
||||
if err != nil {
|
||||
ctxCancel()
|
||||
return fmt.Errorf("could not connect to bmc: %v", err)
|
||||
return fmt.Errorf("failed toconnect to bmc: %v", err)
|
||||
}
|
||||
|
||||
defer client.Close(ctx)
|
||||
|
|
@ -47,7 +47,7 @@ func UpdateFirmware(client *bmclib.Client, l *log.Logger, q *UpdateParams) error
|
|||
file, err := os.Open(q.FirmwarePath)
|
||||
if err != nil {
|
||||
ctxCancel()
|
||||
return fmt.Errorf("could not open firmware path: %v", err)
|
||||
return fmt.Errorf("failed toopen firmware path: %v", err)
|
||||
}
|
||||
|
||||
defer file.Close()
|
||||
|
|
@ -55,7 +55,7 @@ func UpdateFirmware(client *bmclib.Client, l *log.Logger, q *UpdateParams) error
|
|||
taskId, err := client.FirmwareInstall(ctx, q.Component, constants.FirmwareApplyOnReset, true, file)
|
||||
if err != nil {
|
||||
ctxCancel()
|
||||
return fmt.Errorf("could not install firmware: %v", err)
|
||||
return fmt.Errorf("failed toinstall firmware: %v", err)
|
||||
}
|
||||
|
||||
for {
|
||||
|
|
@ -137,7 +137,7 @@ func UpdateFirmwareRemote(q *UpdateParams) error {
|
|||
}
|
||||
data, err := json.Marshal(b)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not marshal data: %v", err)
|
||||
return fmt.Errorf("failed tomarshal data: %v", err)
|
||||
}
|
||||
res, body, err := util.MakeRequest(nil, url, "POST", data, headers)
|
||||
if err != nil {
|
||||
|
|
@ -180,7 +180,7 @@ func GetUpdateStatus(q *UpdateParams) error {
|
|||
// // load file from disk
|
||||
// file, err := os.ReadFile(q.FirmwarePath)
|
||||
// if err != nil {
|
||||
// return fmt.Errorf("could not read file: %v", err)
|
||||
// return fmt.Errorf("failed toread file: %v", err)
|
||||
// }
|
||||
|
||||
// switch q.TransferProtocol {
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ func MakeRequest(client *http.Client, url string, httpMethod string, body []byte
|
|||
}
|
||||
req, err := http.NewRequest(httpMethod, url, bytes.NewBuffer(body))
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("could not create new HTTP request: %v", err)
|
||||
return nil, nil, fmt.Errorf("failed tocreate new HTTP request: %v", err)
|
||||
}
|
||||
req.Header.Add("User-Agent", "magellan")
|
||||
for k, v := range headers {
|
||||
|
|
@ -57,12 +57,12 @@ func MakeRequest(client *http.Client, url string, httpMethod string, body []byte
|
|||
}
|
||||
res, err := client.Do(req)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("could not make request: %v", err)
|
||||
return nil, nil, fmt.Errorf("failed tomake request: %v", err)
|
||||
}
|
||||
b, err := io.ReadAll(res.Body)
|
||||
res.Body.Close()
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("could not read response body: %v", err)
|
||||
return nil, nil, fmt.Errorf("failed toread response body: %v", err)
|
||||
}
|
||||
return res, b, err
|
||||
}
|
||||
|
|
@ -76,7 +76,7 @@ func MakeOutputDirectory(path string) (string, error) {
|
|||
// check if path is valid and directory
|
||||
pathExists, err := PathExists(final)
|
||||
if err != nil {
|
||||
return final, fmt.Errorf("could not check for existing path: %v", err)
|
||||
return final, fmt.Errorf("failed tocheck for existing path: %v", err)
|
||||
}
|
||||
if pathExists {
|
||||
// make sure it is directory with 0o644 permissions
|
||||
|
|
@ -86,7 +86,7 @@ func MakeOutputDirectory(path string) (string, error) {
|
|||
// create directory with data + time
|
||||
err = os.MkdirAll(final, 0766)
|
||||
if err != nil {
|
||||
return final, fmt.Errorf("could not make directory: %v", err)
|
||||
return final, fmt.Errorf("failed tomake directory: %v", err)
|
||||
}
|
||||
return final, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue