Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Disable mandatory field validation if validation is disabled #424

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading