Skip to content

Commit

Permalink
Fix cti_api.uri SecureSetting
Browse files Browse the repository at this point in the history
  • Loading branch information
f-galland committed Jan 30, 2025
1 parent 55f1035 commit 2af159f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,12 @@
*/
package com.wazuh.contentmanager;

import com.wazuh.contentmanager.rest.GetHandler;
import org.opensearch.client.Client;
import org.opensearch.cluster.metadata.IndexNameExpressionResolver;
import org.opensearch.cluster.node.DiscoveryNode;
import org.opensearch.cluster.node.DiscoveryNodes;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.settings.ClusterSettings;
import org.opensearch.common.settings.IndexScopedSettings;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.settings.SettingsFilter;
import org.opensearch.common.settings.*;
import org.opensearch.core.common.io.stream.NamedWriteableRegistry;
import org.opensearch.core.xcontent.NamedXContentRegistry;
import org.opensearch.env.Environment;
Expand All @@ -45,6 +41,8 @@
import java.util.List;
import java.util.function.Supplier;

import com.wazuh.contentmanager.rest.GetHandler;

public class ContentManagerPlugin extends Plugin implements ActionPlugin, ClusterPlugin {

/** ClassConstructor * */
Expand All @@ -63,18 +61,8 @@ public Collection<Object> createComponents(
NamedWriteableRegistry namedWriteableRegistry,
IndexNameExpressionResolver indexNameExpressionResolver,
Supplier<RepositoriesService> repositoriesServiceSupplier) {
return super.createComponents(
client,
clusterService,
threadPool,
resourceWatcherService,
scriptService,
xContentRegistry,
environment,
nodeEnvironment,
namedWriteableRegistry,
indexNameExpressionResolver,
repositoriesServiceSupplier);
PluginSettings.getInstance(environment.settings());
return Collections.emptyList();
}

@Override
Expand All @@ -93,4 +81,9 @@ public List<RestHandler> getRestHandlers(
public void onNodeStarted(DiscoveryNode localNode) {
// ClusterPlugin.super.onNodeStarted(localNode);
}

@Override
public List<Setting<?>> getSettings() {
return List.of(PluginSettings.CTI_API_URI);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ private PluginSettings(@NonNull final Settings settings) {
* @return {@link PluginSettings#INSTANCE}
*/
public static PluginSettings getInstance(@NonNull final Settings settings) {
if (PluginSettings.INSTANCE == null) {
INSTANCE = new PluginSettings(settings);
if (INSTANCE == null) {
synchronized (PluginSettings.class) {
if (INSTANCE == null) {
INSTANCE = new PluginSettings(settings);
}
}
}
return INSTANCE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ public class GetHandler extends BaseRestHandler {

private static final Logger log = LogManager.getLogger(GetHandler.class);


public static final String GET_CONTENT_MANAGER_INIT_DETAILS =
"get_content_manager_init_details";

@Override
public List<Route> routes() {
return List.of(
new Route(GET, String.format(Locale.ROOT, "%s", "/_plugins/_content_manager/init")));
new Route(
GET, String.format(Locale.ROOT, "%s", "/_plugins/_content_manager/init")));
}

@Override
Expand All @@ -61,16 +61,16 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli
SimpleHttpResponse response;
switch (request.method()) {
case GET:
response = GetClient.getInstance()
.get(
URI.create(PluginSettings.getInstance().getUri()),
null,
new BasicHeader("authorization", "Bearer: API-TOKEN"));
response =
GetClient.getInstance()
.get(
URI.create(PluginSettings.getInstance().getUri()),
null,
new BasicHeader("authorization", "Bearer: API-TOKEN"));
log.debug(response.getBodyText());
return restChannel -> {
restChannel.sendResponse(
new BytesRestResponse(RestStatus.OK, response.getBodyText())
);
new BytesRestResponse(RestStatus.OK, response.getBodyText()));
};
default:
throw new IllegalArgumentException(
Expand Down

0 comments on commit 2af159f

Please sign in to comment.