-
Notifications
You must be signed in to change notification settings - Fork 4
/
tenant.go
114 lines (104 loc) · 3.26 KB
/
tenant.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package qradar
import (
"context"
"fmt"
"net/http"
)
// TenantService handles methods related to Tenants of the QRadar API.
type TenantService service
const (
tenantAPIPrefix = "api/config/access/tenant_management/tenants"
)
// Tenant represents QRadar's Tenant.
type Tenant struct {
ID *int `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
Deleted *bool `json:"deleted,omitempty"`
FlowRateLimit *int `json:"flow_rate_limit,omitempty"`
EventRateLimit *int `json:"event_rate_limit,omitempty"`
Description *string `json:"description,omitempty"`
}
// Get returns Tenants of the current QRadar installation.
func (c *TenantService) Get(ctx context.Context, fields, filter string, from, to int) ([]Tenant, error) {
req, err := c.client.requestHelp(http.MethodGet, tenantAPIPrefix, fields, filter, from, to, nil, nil)
if err != nil {
return nil, err
}
var result []Tenant
_, err = c.client.Do(ctx, req, &result)
if err != nil {
return nil, err
}
return result, nil
}
// Create creates Tenant in QRadar installation.
func (c *TenantService) Create(ctx context.Context, fields string, data interface{}) (*Tenant, error) {
req, err := c.client.requestHelp(http.MethodPost, tenantAPIPrefix, fields, "", 0, 0, nil, data)
if err != nil {
return nil, err
}
var result Tenant
_, err = c.client.Do(ctx, req, &result)
if err != nil {
return nil, err
}
return &result, nil
}
// GetByID returns Tenant of the current QRadar installation by ID.
func (c *TenantService) GetByID(ctx context.Context, fields string, id int) (*Tenant, error) {
req, err := c.client.requestHelp(http.MethodGet, tenantAPIPrefix, fields, "", 0, 0, &id, nil)
if err != nil {
return nil, err
}
var result Tenant
_, err = c.client.Do(ctx, req, &result)
if err != nil {
return nil, err
}
return &result, nil
}
// UpdateByID updates Tenant record in QRadar installation by ID.
func (c *TenantService) UpdateByID(ctx context.Context, fields string, id int, data interface{}) (*Tenant, error) {
req, err := c.client.requestHelp(http.MethodPost, tenantAPIPrefix, fields, "", 0, 0, &id, data)
if err != nil {
return nil, err
}
var result Tenant
_, err = c.client.Do(ctx, req, &result)
if err != nil {
return nil, err
}
return &result, nil
}
// DeleteByID deletes Tenant in QRadar installation by ID.
func (c *TenantService) DeleteByID(ctx context.Context, fields string, id int) (*Tenant, error) {
req, err := c.client.requestHelp(http.MethodDelete, tenantAPIPrefix, fields, "", 0, 0, &id, nil)
if err != nil {
return nil, err
}
var result Tenant
_, err = c.client.Do(ctx, req, &result)
if err != nil {
return nil, err
}
return &result, nil
}
// GetByName returns Tenant of the current QRadar installation by Name.
func (c *TenantService) GetByName(ctx context.Context, fields string, name string) (*Tenant, error) {
req, err := c.client.requestHelp(http.MethodGet, tenantAPIPrefix, fields, fmt.Sprintf("name=\"%s\"", name), 0, 0, nil, nil)
if err != nil {
return nil, err
}
var result []Tenant
_, err = c.client.Do(ctx, req, &result)
if err != nil {
return nil, err
}
if len(result) == 0 {
return nil, nil
}
if len(result) > 1 {
return nil, fmt.Errorf("found more elements than expected - %d", len(result))
}
return &result[0], nil
}