use of org.opensearch.client.node.NodeClient in project security by opensearch-project.
the class SecuritySSLInfoAction method prepareRequest.
@Override
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
return new RestChannelConsumer() {
final Boolean showDn = request.paramAsBoolean("show_dn", Boolean.FALSE);
@Override
public void accept(RestChannel channel) throws Exception {
XContentBuilder builder = channel.newBuilder();
BytesRestResponse response = null;
try {
SSLInfo sslInfo = SSLRequestHelper.getSSLInfo(settings, configPath, request, principalExtractor);
X509Certificate[] certs = sslInfo == null ? null : sslInfo.getX509Certs();
X509Certificate[] localCerts = sslInfo == null ? null : sslInfo.getLocalCertificates();
builder.startObject();
builder.field("principal", sslInfo == null ? null : sslInfo.getPrincipal());
builder.field("peer_certificates", certs != null && certs.length > 0 ? certs.length + "" : "0");
if (showDn == Boolean.TRUE) {
builder.field("peer_certificates_list", certs == null ? null : Arrays.stream(certs).map(c -> c.getSubjectDN().getName()).collect(Collectors.toList()));
builder.field("local_certificates_list", localCerts == null ? null : Arrays.stream(localCerts).map(c -> c.getSubjectDN().getName()).collect(Collectors.toList()));
}
builder.field("ssl_protocol", sslInfo == null ? null : sslInfo.getProtocol());
builder.field("ssl_cipher", sslInfo == null ? null : sslInfo.getCipher());
builder.field("ssl_openssl_available", OpenSsl.isAvailable());
builder.field("ssl_openssl_version", OpenSsl.version());
builder.field("ssl_openssl_version_string", OpenSsl.versionString());
Throwable openSslUnavailCause = OpenSsl.unavailabilityCause();
builder.field("ssl_openssl_non_available_cause", openSslUnavailCause == null ? "" : openSslUnavailCause.toString());
builder.field("ssl_openssl_supports_key_manager_factory", OpenSsl.supportsKeyManagerFactory());
builder.field("ssl_openssl_supports_hostname_validation", OpenSsl.supportsHostnameValidation());
builder.field("ssl_provider_http", sks.getHTTPProviderName());
builder.field("ssl_provider_transport_server", sks.getTransportServerProviderName());
builder.field("ssl_provider_transport_client", sks.getTransportClientProviderName());
builder.endObject();
response = new BytesRestResponse(RestStatus.OK, builder);
} catch (final Exception e1) {
log.error("Error handle request ", e1);
builder = channel.newBuilder();
builder.startObject();
builder.field("error", e1.toString());
builder.endObject();
response = new BytesRestResponse(RestStatus.INTERNAL_SERVER_ERROR, builder);
} finally {
if (builder != null) {
builder.close();
}
}
channel.sendResponse(response);
}
};
}
use of org.opensearch.client.node.NodeClient in project OpenSearch by opensearch-project.
the class RestPutIndexTemplateAction method prepareRequest.
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
PutIndexTemplateRequest putRequest = new PutIndexTemplateRequest(request.param("name"));
if (request.hasParam("template")) {
deprecationLogger.deprecate("put_index_template_deprecated_parameter", "Deprecated parameter [template] used, replaced by [index_patterns]");
putRequest.patterns(Collections.singletonList(request.param("template")));
} else {
putRequest.patterns(Arrays.asList(request.paramAsStringArray("index_patterns", Strings.EMPTY_ARRAY)));
}
putRequest.order(request.paramAsInt("order", putRequest.order()));
putRequest.masterNodeTimeout(request.paramAsTime("master_timeout", putRequest.masterNodeTimeout()));
putRequest.create(request.paramAsBoolean("create", false));
putRequest.cause(request.param("cause", ""));
Map<String, Object> sourceAsMap = XContentHelper.convertToMap(request.requiredContent(), false, request.getXContentType()).v2();
sourceAsMap = RestCreateIndexAction.prepareMappings(sourceAsMap);
putRequest.source(sourceAsMap);
return channel -> client.admin().indices().putTemplate(putRequest, new RestToXContentListener<>(channel));
}
use of org.opensearch.client.node.NodeClient in project OpenSearch by opensearch-project.
the class RestRecoveryAction method prepareRequest.
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
final RecoveryRequest recoveryRequest = new RecoveryRequest(Strings.splitStringByCommaToArray(request.param("index")));
recoveryRequest.detailed(request.paramAsBoolean("detailed", false));
recoveryRequest.activeOnly(request.paramAsBoolean("active_only", false));
recoveryRequest.indicesOptions(IndicesOptions.fromRequest(request, recoveryRequest.indicesOptions()));
return channel -> client.admin().indices().recoveries(recoveryRequest, new RestToXContentListener<>(channel));
}
use of org.opensearch.client.node.NodeClient in project OpenSearch by opensearch-project.
the class RestForceMergeAction method prepareRequest.
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
final ForceMergeRequest mergeRequest = new ForceMergeRequest(Strings.splitStringByCommaToArray(request.param("index")));
mergeRequest.indicesOptions(IndicesOptions.fromRequest(request, mergeRequest.indicesOptions()));
mergeRequest.maxNumSegments(request.paramAsInt("max_num_segments", mergeRequest.maxNumSegments()));
mergeRequest.onlyExpungeDeletes(request.paramAsBoolean("only_expunge_deletes", mergeRequest.onlyExpungeDeletes()));
mergeRequest.flush(request.paramAsBoolean("flush", mergeRequest.flush()));
if (mergeRequest.onlyExpungeDeletes() && mergeRequest.maxNumSegments() != ForceMergeRequest.Defaults.MAX_NUM_SEGMENTS) {
deprecationLogger.deprecate("force_merge_expunge_deletes_and_max_num_segments_deprecation", "setting only_expunge_deletes and max_num_segments at the same time is deprecated and will be rejected in a future version");
}
return channel -> client.admin().indices().forceMerge(mergeRequest, new RestToXContentListener<>(channel));
}
use of org.opensearch.client.node.NodeClient in project OpenSearch by opensearch-project.
the class RestGetIndexTemplateAction method prepareRequest.
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
final String[] names = Strings.splitStringByCommaToArray(request.param("name"));
final GetIndexTemplatesRequest getIndexTemplatesRequest = new GetIndexTemplatesRequest(names);
getIndexTemplatesRequest.local(request.paramAsBoolean("local", getIndexTemplatesRequest.local()));
getIndexTemplatesRequest.masterNodeTimeout(request.paramAsTime("master_timeout", getIndexTemplatesRequest.masterNodeTimeout()));
final boolean implicitAll = getIndexTemplatesRequest.names().length == 0;
return channel -> client.admin().indices().getTemplates(getIndexTemplatesRequest, new RestToXContentListener<GetIndexTemplatesResponse>(channel) {
@Override
protected RestStatus getStatus(final GetIndexTemplatesResponse response) {
final boolean templateExists = response.getIndexTemplates().isEmpty() == false;
return (templateExists || implicitAll) ? OK : NOT_FOUND;
}
});
}
Aggregations