Skip to content
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 @@ -598,12 +598,13 @@ public static List<Map<String, String>> reverseTransform(String connName,
return result;
}

private static Set<String> keysWithVariableValues(Map<String, String> rawConfig, Pattern pattern) {
// Visible for testing
static Set<String> keysWithVariableValues(Map<String, String> rawConfig, Pattern pattern) {
Set<String> keys = new HashSet<>();
for (Map.Entry<String, String> config : rawConfig.entrySet()) {
if (config.getValue() != null) {
Matcher matcher = pattern.matcher(config.getValue());
if (matcher.matches()) {
if (matcher.find()) {
keys.add(config.getKey());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.common.config.ConfigDef;
import org.apache.kafka.common.config.ConfigException;
import org.apache.kafka.common.config.ConfigTransformer;
import org.apache.kafka.common.config.SaslConfigs;
import org.apache.kafka.common.security.oauthbearer.internals.unsecured.OAuthBearerUnsecuredLoginCallbackHandler;
import org.apache.kafka.connect.connector.ConnectRecord;
Expand Down Expand Up @@ -62,6 +63,7 @@
import java.util.Set;
import java.util.stream.Collectors;

import static org.apache.kafka.connect.runtime.AbstractHerder.keysWithVariableValues;
import static org.powermock.api.easymock.PowerMock.verifyAll;
import static org.powermock.api.easymock.PowerMock.replayAll;
import static org.easymock.EasyMock.strictMock;
Expand Down Expand Up @@ -474,6 +476,32 @@ public void testReverseTransformConfigs() {
assertFalse(reverseTransformed.get(0).containsKey(TEST_KEY3));
}

@Test
public void testConfigProviderRegex() {
testConfigProviderRegex("\"${::}\"");
testConfigProviderRegex("${::}");
testConfigProviderRegex("\"${:/a:somevar}\"");
testConfigProviderRegex("\"${file::somevar}\"");
testConfigProviderRegex("${file:/a/b/c:}");
testConfigProviderRegex("${file:/tmp/somefile.txt:somevar}");
testConfigProviderRegex("\"${file:/tmp/somefile.txt:somevar}\"");
testConfigProviderRegex("plain.PlainLoginModule required username=\"${file:/tmp/somefile.txt:somevar}\"");
testConfigProviderRegex("plain.PlainLoginModule required username=${file:/tmp/somefile.txt:somevar}");
Comment thread
rhauch marked this conversation as resolved.
testConfigProviderRegex("plain.PlainLoginModule required username=${file:/tmp/somefile.txt:somevar} not null");
testConfigProviderRegex("plain.PlainLoginModule required username=${file:/tmp/somefile.txt:somevar} password=${file:/tmp/somefile.txt:othervar}");
testConfigProviderRegex("plain.PlainLoginModule required username", false);
}

private void testConfigProviderRegex(String rawConnConfig) {
testConfigProviderRegex(rawConnConfig, true);
}

private void testConfigProviderRegex(String rawConnConfig, boolean expected) {
Set<String> keys = keysWithVariableValues(Collections.singletonMap("key", rawConnConfig), ConfigTransformer.DEFAULT_PATTERN);
boolean actual = keys != null && !keys.isEmpty() && keys.contains("key");
assertEquals(String.format("%s should have matched regex", rawConnConfig), expected, actual);
}

private AbstractHerder createConfigValidationHerder(Class<? extends Connector> connectorClass,
ConnectorClientConfigOverridePolicy connectorClientConfigOverridePolicy) {

Expand Down
2 changes: 1 addition & 1 deletion tests/kafkatest/tests/connect/connect_rest_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ConnectRestApiTest(KafkaTest):
INPUT_FILE2 = "/mnt/connect.input2"
OUTPUT_FILE = "/mnt/connect.output"

TOPIC = "${file:%s:topic.external}" % ConnectServiceBase.EXTERNAL_CONFIGS_FILE
TOPIC = "topic-${file:%s:topic.external}" % ConnectServiceBase.EXTERNAL_CONFIGS_FILE
TOPIC_TEST = "test"

DEFAULT_BATCH_SIZE = "2000"
Expand Down