github.com/aiven/aiven-go-client@v1.36.0/opensearch_security_plugin.go (about)

     1  // Package aiven provides a client for using the Aiven API.
     2  package aiven
     3  
     4  type (
     5  	// OpenSearchSecurityPluginHandler is the handler that interacts with the OpenSearch Security Plugin API.
     6  	OpenSearchSecurityPluginHandler struct {
     7  		// client is the API client to use.
     8  		client *Client
     9  	}
    10  
    11  	// OpenSearchSecurityPluginConfigurationStatusResponse is the response when getting the status of the OpenSearch
    12  	// Security Plugin.
    13  	OpenSearchSecurityPluginConfigurationStatusResponse struct {
    14  		APIResponse
    15  
    16  		// SecurityPluginAdminEnabled is true if the admin user is defined in the OpenSearch Security Plugin.
    17  		SecurityPluginAdminEnabled bool `json:"security_plugin_admin_enabled"`
    18  		// SecurityPluginAvailable is true if the OpenSearch Security Plugin is available.
    19  		SecurityPluginAvailable bool `json:"security_plugin_available"`
    20  		// SecurityPluginEnabled is true if the OpenSearch Security Plugin is enabled.
    21  		SecurityPluginEnabled bool `json:"security_plugin_enabled"`
    22  	}
    23  
    24  	// OpenSearchSecurityPluginEnableRequest is the request to enable the OpenSearch Security Plugin.
    25  	OpenSearchSecurityPluginEnableRequest struct {
    26  		// AdminPassword is the admin password.
    27  		AdminPassword string `json:"admin_password"`
    28  	}
    29  
    30  	// OpenSearchSecurityPluginUpdatePasswordRequest is the request to update the password of the admin user.
    31  	OpenSearchSecurityPluginUpdatePasswordRequest struct {
    32  		// AdminPassword is the current admin password.
    33  		AdminPassword string `json:"admin_password"`
    34  		// NewPassword is the new admin password.
    35  		NewPassword string `json:"new_password"`
    36  	}
    37  )
    38  
    39  // Get gets the status of the OpenSearch Security Plugin.
    40  func (h *OpenSearchSecurityPluginHandler) Get(
    41  	project string,
    42  	service string,
    43  ) (*OpenSearchSecurityPluginConfigurationStatusResponse, error) {
    44  	path := buildPath("project", project, "service", service, "opensearch", "security")
    45  
    46  	bts, err := h.client.doGetRequest(path, nil)
    47  	if err != nil {
    48  		return nil, err
    49  	}
    50  
    51  	var r OpenSearchSecurityPluginConfigurationStatusResponse
    52  
    53  	return &r, checkAPIResponse(bts, &r)
    54  }
    55  
    56  // Enable enables the OpenSearch Security Plugin and sets the password of the admin user.
    57  func (h *OpenSearchSecurityPluginHandler) Enable(
    58  	project string,
    59  	service string,
    60  	req OpenSearchSecurityPluginEnableRequest,
    61  ) (*OpenSearchSecurityPluginConfigurationStatusResponse, error) {
    62  	path := buildPath("project", project, "service", service, "opensearch", "security", "admin")
    63  
    64  	bts, err := h.client.doPostRequest(path, req)
    65  	if err != nil {
    66  		return nil, err
    67  	}
    68  
    69  	var r OpenSearchSecurityPluginConfigurationStatusResponse
    70  
    71  	return &r, checkAPIResponse(bts, &r)
    72  }
    73  
    74  // UpdatePassword updates the password of the admin user.
    75  func (h *OpenSearchSecurityPluginHandler) UpdatePassword(
    76  	project string,
    77  	service string,
    78  	req OpenSearchSecurityPluginUpdatePasswordRequest,
    79  ) (*OpenSearchSecurityPluginConfigurationStatusResponse, error) {
    80  	path := buildPath("project", project, "service", service, "opensearch", "security", "admin")
    81  
    82  	bts, err := h.client.doPutRequest(path, req)
    83  	if err != nil {
    84  		return nil, err
    85  	}
    86  
    87  	var r OpenSearchSecurityPluginConfigurationStatusResponse
    88  
    89  	return &r, checkAPIResponse(bts, &r)
    90  }