Skip to content

Commit b0d23ef

Browse files
committed
Added support for MarkLogic Cloud auth
Fairly simple matter of just adding two config options and passing them along to the existing class that collects inputs for constructing a client.
1 parent f1c62b0 commit b0d23ef

File tree

5 files changed

+48
-3
lines changed

5 files changed

+48
-3
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ Both digest and basic authentication require the following properties to be conf
105105
- `ml.connection.username` = the name of the MarkLogic user to authenticate as
106106
- `ml.connection.password` = the password of the MarkLogic user
107107

108+
### Configuring MarkLogic Cloud authentication
109+
110+
Cloud authentication requires the following properties to be configured:
111+
112+
- `ml.connection.basePath` = the base path in your MarkLogic Cloud instance that points to the REST API server you
113+
wish to connect to
114+
- `ml.connection.cloudApiKey` = the API key for authenticating with your MarkLogic Cloud instance
115+
116+
You should also set `ml.connection.port` to 443 for connecting to MarkLogic Cloud.
117+
108118
### Configuring certificate authentication
109119

110120
Certificate authentication requires the following properties to be configured:

build.gradle

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ repositories {
2020

2121
// For testing
2222
mavenLocal()
23+
maven {
24+
url "https://nexus.marklogic.com/repository/maven-snapshots/"
25+
}
26+
}
27+
28+
// Do not cache changing modules
29+
configurations.all {
30+
resolutionStrategy {
31+
cacheChangingModulesFor 0, 'seconds'
32+
}
2333
}
2434

2535
configurations {
@@ -37,11 +47,12 @@ dependencies {
3747
compileOnly "org.apache.kafka:connect-runtime:${kafkaVersion}"
3848
compileOnly "org.slf4j:slf4j-api:1.7.36"
3949

40-
implementation "com.marklogic:marklogic-client-api:6.0.0"
41-
implementation "com.marklogic:ml-javaclient-util:4.4.0"
50+
implementation ('com.marklogic:ml-javaclient-util:4.5-SNAPSHOT') {
51+
changing = true
52+
}
4253

4354
// Force DHF to use the latest version of ml-app-deployer, which minimizes security vulnerabilities
44-
implementation "com.marklogic:ml-app-deployer:4.4.0"
55+
implementation "com.marklogic:ml-app-deployer:4.5-SNAPSHOT"
4556

4657
implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-csv:2.14.1"
4758

src/main/java/com/marklogic/kafka/connect/DefaultDatabaseClientConfigBuilder.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public DatabaseClientConfig buildDatabaseClientConfig(Map<String, Object> parsed
4040

4141
clientConfig.setHost((String) parsedConfig.get(MarkLogicConfig.CONNECTION_HOST));
4242
clientConfig.setPort((Integer) parsedConfig.get(MarkLogicConfig.CONNECTION_PORT));
43+
clientConfig.setBasePath((String) parsedConfig.get(MarkLogicConfig.CONNECTION_BASE_PATH));
44+
4345
String securityContextType = ((String) parsedConfig.get(MarkLogicConfig.CONNECTION_SECURITY_CONTEXT_TYPE)).toUpperCase();
4446
clientConfig.setSecurityContextType(SecurityContextType.valueOf(securityContextType));
4547

@@ -75,6 +77,8 @@ public DatabaseClientConfig buildDatabaseClientConfig(Map<String, Object> parsed
7577
configureSimpleSsl(clientConfig);
7678
}
7779

80+
clientConfig.setCloudApiKey((String)parsedConfig.get(MarkLogicConfig.CONNECTION_CLOUD_API_KEY));
81+
7882
return clientConfig;
7983
}
8084

src/main/java/com/marklogic/kafka/connect/MarkLogicConfig.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
public class MarkLogicConfig extends AbstractConfig {
3232
public static final String CONNECTION_HOST = "ml.connection.host";
3333
public static final String CONNECTION_PORT = "ml.connection.port";
34+
public static final String CONNECTION_BASE_PATH = "ml.connection.basePath";
3435
public static final String CONNECTION_DATABASE = "ml.connection.database";
3536
public static final String CONNECTION_SECURITY_CONTEXT_TYPE = "ml.connection.securityContextType";
3637
public static final String CONNECTION_USERNAME = "ml.connection.username";
@@ -40,6 +41,7 @@ public class MarkLogicConfig extends AbstractConfig {
4041
public static final String CONNECTION_CERT_FILE = "ml.connection.certFile";
4142
public static final String CONNECTION_CERT_PASSWORD = "ml.connection.certPassword";
4243
public static final String CONNECTION_EXTERNAL_NAME = "ml.connection.externalName";
44+
public static final String CONNECTION_CLOUD_API_KEY = "ml.connection.cloudApiKey";
4345
public static final String ENABLE_CUSTOM_SSL = "ml.connection.enableCustomSsl";
4446
public static final String TLS_VERSION = "ml.connection.customSsl.tlsVersion";
4547
public static final String SSL_HOST_VERIFIER = "ml.connection.customSsl.hostNameVerifier";
@@ -58,6 +60,9 @@ public static void addDefinitions(ConfigDef configDef) {
5860
.define(CONNECTION_PORT, Type.INT, ConfigDef.NO_DEFAULT_VALUE, ConfigDef.Range.atLeast(0), Importance.HIGH,
5961
"Required; the port of a REST API app server to connect to; if using Bulk Data Services, can be a plain HTTP app server",
6062
GROUP, -1, ConfigDef.Width.MEDIUM, "Port")
63+
.define(CONNECTION_BASE_PATH, Type.STRING, null, Importance.MEDIUM,
64+
"Base path for all calls to MarkLogic; typically used when a reverse proxy is in front of MarkLogic",
65+
GROUP, -1, ConfigDef.Width.MEDIUM, "Base Path")
6166
.define(CONNECTION_SECURITY_CONTEXT_TYPE, Type.STRING, "DIGEST", CONNECTION_SECURITY_CONTEXT_TYPE_RV, Importance.HIGH,
6267
"Required; the authentication scheme used by the server defined by ml.connection.port; either 'DIGEST', 'BASIC', 'CERTIFICATE', 'KERBEROS', or 'NONE'",
6368
GROUP, -1, ConfigDef.Width.MEDIUM, "Security Context Type", CONNECTION_SECURITY_CONTEXT_TYPE_RV)
@@ -79,6 +84,9 @@ public static void addDefinitions(ConfigDef configDef) {
7984
.define(CONNECTION_EXTERNAL_NAME, Type.STRING, null, Importance.MEDIUM,
8085
"External name for 'KERBEROS' authentication",
8186
GROUP, -1, ConfigDef.Width.MEDIUM, "Kerberos External Name")
87+
.define(CONNECTION_CLOUD_API_KEY, Type.STRING, null, Importance.MEDIUM,
88+
"API key for connecting to MarkLogic Cloud. Should set port to 443 when connecting to MarkLogic Cloud.",
89+
GROUP, -1, ConfigDef.Width.MEDIUM, "Cloud API Key")
8290
.define(CONNECTION_TYPE, Type.STRING, "", CONNECTION_TYPE_RV, Importance.MEDIUM,
8391
"Set to 'GATEWAY' when the host identified by ml.connection.host is a load balancer. See https://docs.marklogic.com/guide/java/data-movement#id_26583 for more information.",
8492
GROUP, -1, ConfigDef.Width.MEDIUM, "Connection Type", CONNECTION_TYPE_RV)

src/test/java/com/marklogic/kafka/connect/BuildDatabaseClientConfigTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ void kerberosAuthentication() {
8383
assertEquals("some-name", clientConfig.getExternalName());
8484
}
8585

86+
@Test
87+
void cloudAuthentication() {
88+
config.put(MarkLogicSinkConfig.CONNECTION_SECURITY_CONTEXT_TYPE, "cloud");
89+
config.put(MarkLogicSinkConfig.CONNECTION_CLOUD_API_KEY, "my-key");
90+
config.put(MarkLogicSinkConfig.CONNECTION_BASE_PATH, "/my/path");
91+
92+
DatabaseClientConfig clientConfig = builder.buildDatabaseClientConfig(config);
93+
assertEquals(SecurityContextType.CLOUD, clientConfig.getSecurityContextType());
94+
assertEquals("my-key", clientConfig.getCloudApiKey());
95+
assertEquals("/my/path", clientConfig.getBasePath());
96+
}
97+
8698
@Test
8799
void digestAuthenticationAndSimpleSsl() {
88100
config.put(MarkLogicSinkConfig.CONNECTION_SECURITY_CONTEXT_TYPE, "digest");

0 commit comments

Comments
 (0)