-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(opensearch): port security plugin endpoints to v2 (#312)
- Loading branch information
1 parent
0c302a3
commit ba9f3d4
Showing
2 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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) | ||
} |