Search in sources :

Example 1 with NodesReloadSecureSettingsRequest

use of org.opensearch.action.admin.cluster.node.reload.NodesReloadSecureSettingsRequest in project OpenSearch by opensearch-project.

the class RestReloadSecureSettingsAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
    final String[] nodesIds = Strings.splitStringByCommaToArray(request.param("nodeId"));
    final NodesReloadSecureSettingsRequestBuilder nodesRequestBuilder = client.admin().cluster().prepareReloadSecureSettings().setTimeout(request.param("timeout")).setNodesIds(nodesIds);
    request.withContentOrSourceParamParserOrNull(parser -> {
        if (parser != null) {
            final NodesReloadSecureSettingsRequest nodesRequest = PARSER.parse(parser, null);
            nodesRequestBuilder.setSecureStorePassword(nodesRequest.getSecureSettingsPassword());
        }
    });
    return channel -> nodesRequestBuilder.execute(new RestBuilderListener<NodesReloadSecureSettingsResponse>(channel) {

        @Override
        public RestResponse buildResponse(NodesReloadSecureSettingsResponse response, XContentBuilder builder) throws Exception {
            builder.startObject();
            RestActions.buildNodesHeader(builder, channel.request(), response);
            builder.field("cluster_name", response.getClusterName().value());
            response.toXContent(builder, channel.request());
            builder.endObject();
            nodesRequestBuilder.request().closePassword();
            return new BytesRestResponse(RestStatus.OK, builder);
        }
    });
}
Also used : POST(org.opensearch.rest.RestRequest.Method.POST) NodesReloadSecureSettingsRequestBuilder(org.opensearch.action.admin.cluster.node.reload.NodesReloadSecureSettingsRequestBuilder) NodeClient(org.opensearch.client.node.NodeClient) Collections.unmodifiableList(java.util.Collections.unmodifiableList) RestRequest(org.opensearch.rest.RestRequest) Set(java.util.Set) IOException(java.io.IOException) ParseField(org.opensearch.common.ParseField) RestStatus(org.opensearch.rest.RestStatus) BytesRestResponse(org.opensearch.rest.BytesRestResponse) RestResponse(org.opensearch.rest.RestResponse) Strings(org.opensearch.common.Strings) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) RestBuilderListener(org.opensearch.rest.action.RestBuilderListener) List(java.util.List) RestActions(org.opensearch.rest.action.RestActions) SecureString(org.opensearch.common.settings.SecureString) NodesReloadSecureSettingsRequest(org.opensearch.action.admin.cluster.node.reload.NodesReloadSecureSettingsRequest) Arrays.asList(java.util.Arrays.asList) RestRequestFilter(org.opensearch.rest.RestRequestFilter) NodesReloadSecureSettingsResponse(org.opensearch.action.admin.cluster.node.reload.NodesReloadSecureSettingsResponse) ObjectParser(org.opensearch.common.xcontent.ObjectParser) BaseRestHandler(org.opensearch.rest.BaseRestHandler) Collections(java.util.Collections) BytesRestResponse(org.opensearch.rest.BytesRestResponse) RestResponse(org.opensearch.rest.RestResponse) NodesReloadSecureSettingsRequest(org.opensearch.action.admin.cluster.node.reload.NodesReloadSecureSettingsRequest) BytesRestResponse(org.opensearch.rest.BytesRestResponse) SecureString(org.opensearch.common.settings.SecureString) NodesReloadSecureSettingsRequestBuilder(org.opensearch.action.admin.cluster.node.reload.NodesReloadSecureSettingsRequestBuilder) NodesReloadSecureSettingsResponse(org.opensearch.action.admin.cluster.node.reload.NodesReloadSecureSettingsResponse) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) IOException(java.io.IOException)

Example 2 with NodesReloadSecureSettingsRequest

use of org.opensearch.action.admin.cluster.node.reload.NodesReloadSecureSettingsRequest in project OpenSearch by opensearch-project.

the class RestReloadSecureSettingsActionTests method testParserWithoutPassword.

public void testParserWithoutPassword() throws Exception {
    final String request = "{" + "}";
    try (XContentParser parser = XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, request)) {
        NodesReloadSecureSettingsRequest reloadSecureSettingsRequest = RestReloadSecureSettingsAction.PARSER.parse(parser, null);
        assertThat(reloadSecureSettingsRequest.getSecureSettingsPassword(), nullValue());
    }
}
Also used : NodesReloadSecureSettingsRequest(org.opensearch.action.admin.cluster.node.reload.NodesReloadSecureSettingsRequest) XContentParser(org.opensearch.common.xcontent.XContentParser)

Example 3 with NodesReloadSecureSettingsRequest

use of org.opensearch.action.admin.cluster.node.reload.NodesReloadSecureSettingsRequest in project OpenSearch by opensearch-project.

the class RestReloadSecureSettingsActionTests method testParserWithPassword.

public void testParserWithPassword() throws Exception {
    final String request = "{" + "\"secure_settings_password\": \"secure_settings_password_string\"" + "}";
    try (XContentParser parser = XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, request)) {
        NodesReloadSecureSettingsRequest reloadSecureSettingsRequest = RestReloadSecureSettingsAction.PARSER.parse(parser, null);
        assertEquals("secure_settings_password_string", reloadSecureSettingsRequest.getSecureSettingsPassword().toString());
    }
}
Also used : NodesReloadSecureSettingsRequest(org.opensearch.action.admin.cluster.node.reload.NodesReloadSecureSettingsRequest) XContentParser(org.opensearch.common.xcontent.XContentParser)

Aggregations

NodesReloadSecureSettingsRequest (org.opensearch.action.admin.cluster.node.reload.NodesReloadSecureSettingsRequest)3 XContentParser (org.opensearch.common.xcontent.XContentParser)2 IOException (java.io.IOException)1 Arrays.asList (java.util.Arrays.asList)1 Collections (java.util.Collections)1 Collections.unmodifiableList (java.util.Collections.unmodifiableList)1 List (java.util.List)1 Set (java.util.Set)1 NodesReloadSecureSettingsRequestBuilder (org.opensearch.action.admin.cluster.node.reload.NodesReloadSecureSettingsRequestBuilder)1 NodesReloadSecureSettingsResponse (org.opensearch.action.admin.cluster.node.reload.NodesReloadSecureSettingsResponse)1 NodeClient (org.opensearch.client.node.NodeClient)1 ParseField (org.opensearch.common.ParseField)1 Strings (org.opensearch.common.Strings)1 SecureString (org.opensearch.common.settings.SecureString)1 ObjectParser (org.opensearch.common.xcontent.ObjectParser)1 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)1 BaseRestHandler (org.opensearch.rest.BaseRestHandler)1 BytesRestResponse (org.opensearch.rest.BytesRestResponse)1 RestRequest (org.opensearch.rest.RestRequest)1 POST (org.opensearch.rest.RestRequest.Method.POST)1