Skip to content

Commit

Permalink
Fix: Disable mandatory field validation if validation is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
ludovic-boutros committed Mar 7, 2024
1 parent ba29847 commit 8f16817
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
*/
package com.splunk.kafka.connect;

import static com.splunk.kafka.connect.SplunkSinkConnectorConfig.KERBEROS_KEYTAB_PATH_CONF;
import static com.splunk.kafka.connect.SplunkSinkConnectorConfig.KERBEROS_USER_PRINCIPAL_CONF;

import java.util.function.Function;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -53,6 +50,8 @@
import com.splunk.hecclient.JsonEvent;
import com.splunk.hecclient.JsonEventBatch;

import static com.splunk.kafka.connect.SplunkSinkConnectorConfig.*;

public final class SplunkSinkConnector extends SinkConnector {
private static final Logger log = LoggerFactory.getLogger(SplunkSinkConnector.class);
private Map<String, String> taskConfig;
Expand Down Expand Up @@ -147,10 +146,10 @@ private static String[] split(String data, String sep) {


private void validateSplunkConfigurations(final Map<String, String> configs) throws ConfigException {
SplunkSinkConnectorConfig connectorConfig = new SplunkSinkConnectorConfig(configs);
if (connectorConfig.disableValidation) {
if (configs.containsKey(DISABLE_VALIDATION) && Boolean.parseBoolean(configs.get(DISABLE_VALIDATION))) {
return;
}
SplunkSinkConnectorConfig connectorConfig = new SplunkSinkConnectorConfig(configs);
String[] indexes = split(connectorConfig.indexes, ",");
if(indexes == null || indexes.length == 0) {
preparePayloadAndExecuteRequest(connectorConfig, "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,17 @@ public void testInvalidSplunkConfigurationsWithValidationDisabled() {
Assertions.assertDoesNotThrow(()->connector.validate(configs));
}

@Test
public void testInvalidSplunkConfigurationWithMandatoryFieldMissingWithValidationDisabled() {
final Map<String, String> configs = new HashMap<>();
SplunkSinkConnector connector = new SplunkSinkConnector();
configs.put("splunk.validation.disable", "true");
configs.put("topics", "b");
MockHecClientWrapper clientInstance = new MockHecClientWrapper();
clientInstance.client.setResponse(CloseableHttpClientMock.EXCEPTION);
Assertions.assertDoesNotThrow(()->connector.validate(configs));
}

@Test
public void testInvalidSplunkConfigurationsWithValidationEnabled() {
final Map<String, String> configs = new HashMap<>();
Expand Down

0 comments on commit 8f16817

Please sign in to comment.