Refactored flags and added xnames to add endpoint to hms-smd

This commit is contained in:
David J. Allen 2023-09-05 14:26:53 -06:00
parent de07b119b5
commit 2edb9fdbb0
18 changed files with 270 additions and 175 deletions

View file

@ -42,7 +42,7 @@ func ScanForAssets() error {
func QueryScannedPorts() error {
// Perform scan and collect from dora server
url := makeEndpointUrl("/scanned_ports")
_, body, err := api.MakeRequest(url, "GET", nil)
_, body, err := api.MakeRequest(url, "GET", nil, nil)
if err != nil {
return fmt.Errorf("could not discover assets: %v", err)
}

View file

@ -22,7 +22,7 @@ func makeEndpointUrl(endpoint string) string {
func GetRedfishEndpoints() error {
url := makeEndpointUrl("/Inventory/RedfishEndpoints")
_, body, err := api.MakeRequest(url, "GET", nil)
_, body, err := api.MakeRequest(url, "GET", nil, nil)
if err != nil {
return fmt.Errorf("could not get endpoint: %v", err)
}
@ -33,7 +33,7 @@ func GetRedfishEndpoints() error {
func GetComponentEndpoint(xname string) error {
url := makeEndpointUrl("/Inventory/ComponentsEndpoints/" + xname)
res, body, err := api.MakeRequest(url, "GET", nil)
res, body, err := api.MakeRequest(url, "GET", nil, nil)
if err != nil {
return fmt.Errorf("could not get endpoint: %v", err)
}
@ -42,7 +42,7 @@ func GetComponentEndpoint(xname string) error {
return nil
}
func AddRedfishEndpoint(data []byte) error {
func AddRedfishEndpoint(data []byte, headers map[string]string) error {
if data == nil {
return fmt.Errorf("could not add redfish endpoint: no data found")
}
@ -51,7 +51,7 @@ func AddRedfishEndpoint(data []byte) error {
// _ = ep
// Add redfish endpoint via POST `/hsm/v2/Inventory/RedfishEndpoints` endpoint
url := makeEndpointUrl("/Inventory/RedfishEndpoints")
res, body, _ := api.MakeRequest(url, "POST", data)
res, body, _ := api.MakeRequest(url, "POST", data, headers)
fmt.Println("smd url: ", url)
fmt.Println("res: ", res)
fmt.Println("body: ", string(body))

View file

@ -8,10 +8,13 @@ import (
)
func MakeRequest(url string, httpMethod string, body []byte) (*http.Response, []byte, error) {
func MakeRequest(url string, httpMethod string, body []byte, headers map[string]string) (*http.Response, []byte, error) {
// url := getSmdEndpointUrl(endpoint)
req, _ := http.NewRequest(httpMethod, url, bytes.NewBuffer(body))
req.Header.Add("User-Agent", "magellan")
for k, v := range headers {
req.Header.Add(k, v)
}
res, err := http.DefaultClient.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("could not make request: %v", err)