This repository has been archived by the owner on May 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexploitationservice.go
80 lines (63 loc) · 1.77 KB
/
exploitationservice.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package goitop
import (
"fmt"
)
type ExploitationService struct {
Name string
ID string
}
func (c *Client) GetExploitationService(name string) (string, error) {
payload := map[string]interface{}{
"operation": "core/get",
"class": "ExploitationService",
"key": map[string]string{
"name": name,
},
"output_fields": "id",
}
result, err := Request(c, payload)
if err != nil {
return "", err
}
if result.Code != 0 {
return "", fmt.Errorf("Get exploitation service request failed with code %d: %s", result.Code, result.Message)
}
if len(result.Objects) > 1 {
return "", fmt.Errorf("Too many objects in get exploitation service response")
}
if len(result.Objects) < 1 {
return "", fmt.Errorf("Exploitation service not found")
}
var firstObject APIObject
for _, object := range result.Objects {
firstObject = object
break
}
return firstObject.Fields["id"].(string), nil
}
func (c *Client) GetAllExploitationService() ([]ExploitationService, error) {
payload := map[string]interface{}{
"operation": "core/get",
"class": "ExploitationService",
"key": "SELECT ExploitationService",
"output_fields": "id,name",
}
result, err := Request(c, payload)
if err != nil {
return []ExploitationService{}, err
}
if result.Code != 0 {
return []ExploitationService{}, fmt.Errorf("Get all exploitation service request failed with code %d: %s", result.Code, result.Message)
}
if len(result.Objects) < 1 {
return []ExploitationService{}, fmt.Errorf("No exploitation service found")
}
var services []ExploitationService
for _, object := range result.Objects {
services = append(services, ExploitationService{
Name: object.Fields["name"].(string),
ID: object.Fields["id"].(string),
})
}
return services, nil
}