-
Notifications
You must be signed in to change notification settings - Fork 0
/
infra_detail.go
55 lines (52 loc) · 1.93 KB
/
infra_detail.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
package client // import "github.com/BryanKMorrow/aqua-sdk-go/client"
import (
"crypto/tls"
"encoding/json"
"fmt"
"github.com/BryanKMorrow/aqua-sdk-go/types/infrastructure"
"github.com/parnurzeal/gorequest"
"log"
)
// GetDetailName - gets a single infrastructure asset by name
// Path v2/infrastructure/<type>/<name> (type can be cluster or node
// Return - infrastructure.Detail response struct
func (cli *Client) GetDetailName(infraType, name string) infrastructure.Detail {
var response infrastructure.Detail
request := gorequest.New().TLSClientConfig(&tls.Config{InsecureSkipVerify: true})
request.Set("Authorization", "Bearer "+cli.token)
apiPath := fmt.Sprintf("/api/v2/infrastructure/%s/%s", infraType, name)
events, body, errs := request.Clone().Get(cli.url + apiPath).End()
if errs != nil {
log.Println(events.StatusCode)
}
if events.StatusCode == 200 {
err := json.Unmarshal([]byte(body), &response)
if err != nil {
log.Printf("Error calling func GetDetailName from %s%s, %v ", cli.url, apiPath, err)
//json: Unmarshal(non-pointer main.Request)
}
}
return response
}
// GetDetailID - gets a single infrastructure asset by ID
// Path v2/infrastructure/<id>
// Return - infrastructure.Detail response struct
// NOTE - may only work for Nodes, not Clusters??
func (cli *Client) GetDetailID(ID string) infrastructure.Detail {
var response = infrastructure.Detail{}
request := gorequest.New().TLSClientConfig(&tls.Config{InsecureSkipVerify: true})
request.Set("Authorization", "Bearer "+cli.token)
apiPath := fmt.Sprintf("/api/v2/infrastructure/%s", ID)
events, body, errs := request.Clone().Get(cli.url + apiPath).End()
if errs != nil {
log.Println(events.StatusCode)
}
if events.StatusCode == 200 {
err := json.Unmarshal([]byte(body), &response)
if err != nil {
log.Printf("Error calling func GetDetailID from %s%s, %v ", cli.url, apiPath, err)
//json: Unmarshal(non-pointer main.Request)
}
}
return response
}