This repository has been archived by the owner on Jun 1, 2023. It is now read-only.
/
endpoint.go
124 lines (120 loc) · 3.17 KB
/
endpoint.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
115
116
117
118
119
120
121
122
123
124
package endpoint
import (
"fmt"
"net/url"
"path"
)
func urlJoin(ep *url.URL, arg string) (*url.URL, error) {
return ep.Parse(path.Join(ep.Path, arg))
}
// Endpoints represents each API's endpoint URLs.
type Endpoints struct {
alarmCallbacks *url.URL
alerts *url.URL
alertConditions *url.URL
collectorConfigurations *url.URL
dashboards *url.URL
enabledStreams *url.URL
indexSets *url.URL
indexSetStats *url.URL
inputs *url.URL
pipelineRules *url.URL
roles *url.URL
streams *url.URL
users *url.URL
ldapSetting string
ldapGroups string
ldapGroupRoleMapping string
}
// NewEndpoints returns a new Endpoints.
func NewEndpoints(endpoint string) (*Endpoints, error) {
if endpoint == "" {
return nil, fmt.Errorf("endpoint is required")
}
ep, err := url.Parse(endpoint)
if err != nil {
return nil, err
}
alarmCallbacks, err := urlJoin(ep, "alerts/callbacks")
if err != nil {
return nil, err
}
alertConditions, err := urlJoin(ep, "alerts/conditions")
if err != nil {
return nil, err
}
collectorConfigurations, err := urlJoin(ep, "plugins/org.graylog.plugins.collector/configurations")
if err != nil {
return nil, err
}
dashboards, err := urlJoin(ep, "dashboards")
if err != nil {
return nil, err
}
roles, err := urlJoin(ep, "roles")
if err != nil {
return nil, err
}
streams, err := urlJoin(ep, "streams")
if err != nil {
return nil, err
}
enabledStreams, err := urlJoin(streams, "enabled")
if err != nil {
return nil, err
}
alerts, err := urlJoin(ep, "streams/alerts")
if err != nil {
return nil, err
}
indexSets, err := urlJoin(ep, "system/indices/index_sets")
if err != nil {
return nil, err
}
indexSetStats, err := urlJoin(indexSets, "stats")
if err != nil {
return nil, err
}
inputs, err := urlJoin(ep, "system/inputs")
if err != nil {
return nil, err
}
ldapSetting, err := urlJoin(ep, "system/ldap/settings")
if err != nil {
return nil, err
}
ldapGroups, err := urlJoin(ep, "system/ldap/groups")
if err != nil {
return nil, err
}
ldapGroupRoleMapping, err := urlJoin(ep, "system/ldap/settings/groups")
if err != nil {
return nil, err
}
pipelineRules, err := urlJoin(ep, "plugins/org.graylog.plugins.pipelineprocessor/system/pipelines/rule")
if err != nil {
return nil, err
}
users, err := urlJoin(ep, "users")
if err != nil {
return nil, err
}
return &Endpoints{
alarmCallbacks: alarmCallbacks,
alerts: alerts,
alertConditions: alertConditions,
collectorConfigurations: collectorConfigurations,
dashboards: dashboards,
enabledStreams: enabledStreams,
indexSets: indexSets,
indexSetStats: indexSetStats,
inputs: inputs,
ldapGroups: ldapGroups.String(),
ldapGroupRoleMapping: ldapGroupRoleMapping.String(),
ldapSetting: ldapSetting.String(),
pipelineRules: pipelineRules,
roles: roles,
streams: streams,
users: users,
}, nil
}