This repository has been archived by the owner on Jan 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.go
66 lines (53 loc) · 1.57 KB
/
test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"context"
"crypto/tls"
"fmt"
"log"
"net/http"
"strings"
"github.com/bmc-toolbox/redgopher/openapi"
)
func main() {
var user, pass string
user = "foo"
pass = "bar"
ip := "127.0.0.1"
//Since BMCs have shitty certs
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
// declare behaviour on redirects
checkRedirect := func(req *http.Request, via []*http.Request) error {
if len(via) >= 5 {
log.Printf("Too many redirects - %d\n", len(via))
}
// Sensitive headers are not forwarded by default
req.SetBasicAuth(user, pass)
return nil
}
cfg := &openapi.Configuration{
BasePath: fmt.Sprintf("https://%s", ip),
HTTPClient: &http.Client{Transport: tr, CheckRedirect: checkRedirect},
UserAgent: "redgopher",
}
client := openapi.NewAPIClient(cfg)
ctx := context.Background()
basicAuth := openapi.BasicAuth{UserName: user, Password: pass}
ctx = context.WithValue(ctx, openapi.ContextBasicAuth, basicAuth)
// here we get the manager we will need to use later
m, _, err := client.DefaultApi.RedfishV1ManagersGet(ctx)
if err != nil {
log.Fatal(err)
}
log.Printf("response: %+v", m)
// for the manager we will use only the last part of the id
manager := strings.Split(m.Members[0].OdataId, "/")[strings.Count(m.Members[0].OdataId, "/")]
fmt.Printf("manager: %s\n", manager)
// here we use the manager as argument to retrieve the required data
l, _, err := client.DefaultApi.RedfishV1ManagersManagerIdNetworkProtocolGet(ctx, manager)
if err != nil {
log.Fatal(err)
}
log.Printf("response: %+v", l)
}