-
Notifications
You must be signed in to change notification settings - Fork 28
/
opensearch_security_plugin.go
95 lines (77 loc) · 3.18 KB
/
opensearch_security_plugin.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
// Package aiven provides a client for using the Aiven API.
package aiven
import "context"
type (
// OpenSearchSecurityPluginHandler is the handler that interacts with the OpenSearch Security Plugin API.
OpenSearchSecurityPluginHandler struct {
// client is the API client to use.
client *Client
}
// OpenSearchSecurityPluginConfigurationStatusResponse is the response when getting the status of the OpenSearch
// Security Plugin.
OpenSearchSecurityPluginConfigurationStatusResponse struct {
APIResponse
// SecurityPluginAdminEnabled is true if the admin user is defined in the OpenSearch Security Plugin.
SecurityPluginAdminEnabled bool `json:"security_plugin_admin_enabled"`
// SecurityPluginAvailable is true if the OpenSearch Security Plugin is available.
SecurityPluginAvailable bool `json:"security_plugin_available"`
// SecurityPluginEnabled is true if the OpenSearch Security Plugin is enabled.
SecurityPluginEnabled bool `json:"security_plugin_enabled"`
}
// OpenSearchSecurityPluginEnableRequest is the request to enable the OpenSearch Security Plugin.
OpenSearchSecurityPluginEnableRequest struct {
// AdminPassword is the admin password.
AdminPassword string `json:"admin_password"`
}
// OpenSearchSecurityPluginUpdatePasswordRequest is the request to update the password of the admin user.
OpenSearchSecurityPluginUpdatePasswordRequest struct {
// AdminPassword is the current admin password.
AdminPassword string `json:"admin_password"`
// NewPassword is the new admin password.
NewPassword string `json:"new_password"`
}
)
// Get gets the status of the OpenSearch Security Plugin.
func (h *OpenSearchSecurityPluginHandler) Get(
ctx context.Context,
project string,
service string,
) (*OpenSearchSecurityPluginConfigurationStatusResponse, error) {
path := buildPath("project", project, "service", service, "opensearch", "security")
bts, err := h.client.doGetRequest(ctx, path, nil)
if err != nil {
return nil, err
}
var r OpenSearchSecurityPluginConfigurationStatusResponse
return &r, checkAPIResponse(bts, &r)
}
// Enable enables the OpenSearch Security Plugin and sets the password of the admin user.
func (h *OpenSearchSecurityPluginHandler) Enable(
ctx context.Context,
project string,
service string,
req OpenSearchSecurityPluginEnableRequest,
) (*OpenSearchSecurityPluginConfigurationStatusResponse, error) {
path := buildPath("project", project, "service", service, "opensearch", "security", "admin")
bts, err := h.client.doPostRequest(ctx, path, req)
if err != nil {
return nil, err
}
var r OpenSearchSecurityPluginConfigurationStatusResponse
return &r, checkAPIResponse(bts, &r)
}
// UpdatePassword updates the password of the admin user.
func (h *OpenSearchSecurityPluginHandler) UpdatePassword(
ctx context.Context,
project string,
service string,
req OpenSearchSecurityPluginUpdatePasswordRequest,
) (*OpenSearchSecurityPluginConfigurationStatusResponse, error) {
path := buildPath("project", project, "service", service, "opensearch", "security", "admin")
bts, err := h.client.doPutRequest(ctx, path, req)
if err != nil {
return nil, err
}
var r OpenSearchSecurityPluginConfigurationStatusResponse
return &r, checkAPIResponse(bts, &r)
}