Skip to content

Commit f54af46

Browse files
committed
MLE-25059 Defaulting port and auth type for cloud auth
1 parent a3f0d1e commit f54af46

File tree

4 files changed

+69
-8
lines changed

4 files changed

+69
-8
lines changed

docs/common-options.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,29 +183,27 @@ threads available on each host, and also write directly to a forest on the host
183183

184184
### Connecting to Progress Data Cloud
185185

186-
To connect to Progress Data Cloud (PDC), you must set at least the following options:
186+
To connect to Progress Data Cloud (PDC), if you are using Flux 2.0 or higher, you must set at least the following options:
187187

188188
{% tabs log %}
189189
{% tab log Unix %}
190190
```
191191
--host your-pdc-host-name \
192-
--port 443 \
193-
--auth-type cloud \
194192
--cloud-api-key your-key-goes-here \
195193
--base-path your-integration-endpoint
196194
```
197195
{% endtab %}
198196
{% tab log Windows %}
199197
```
200198
--host your-pdc-host-name ^
201-
--port 443 ^
202-
--auth-type cloud ^
203199
--cloud-api-key your-key-goes-here ^
204200
--base-path your-integration-endpoint
205201
```
206202
{% endtab %}
207203
{% endtabs %}
208204

205+
If you are using Flux 1.x, you must also include `--auth-type cloud`.
206+
209207
The value of `--cloud-api-key` is an API key that you have generated in your PDC tenancy. Please see the
210208
[PDC documentation on API keys](https://docs.progress.com/bundle/progress-data-cloud-use/page/topics/account-settings/manage-api-key.html)
211209
for more information.

flux-cli/src/main/java/com/marklogic/flux/impl/ConnectionParamsValidator.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public void validate(ConnectionInputs connectionInputs) {
2323
throw new FluxException(String.format("Must specify a MarkLogic host via %s or %s.",
2424
paramNames.host, paramNames.connectionString));
2525
}
26+
27+
setDefaultValuesIfCloudApiKeyIsSet(connectionInputs);
28+
2629
if (connectionInputs.port <= 0 && !AuthenticationType.CLOUD.equals(connectionInputs.authType)) {
2730
throw new FluxException(String.format("Must specify a MarkLogic app server port via %s or %s.",
2831
paramNames.port, paramNames.connectionString));
@@ -35,6 +38,18 @@ public void validate(ConnectionInputs connectionInputs) {
3538
}
3639
}
3740

41+
private void setDefaultValuesIfCloudApiKeyIsSet(ConnectionInputs connectionInputs) {
42+
final String cloudApiKey = connectionInputs.cloudApiKey;
43+
if (cloudApiKey != null && !cloudApiKey.trim().isEmpty()) {
44+
if (connectionInputs.port <= 0) {
45+
connectionInputs.port = 443;
46+
}
47+
if (connectionInputs.authType == null) {
48+
connectionInputs.authType = AuthenticationType.CLOUD;
49+
}
50+
}
51+
}
52+
3853
private void validateUsernameAndPassword(ConnectionInputs connectionInputs) {
3954
if (connectionInputs.username == null) {
4055
throw new FluxException(String.format("Must specify a MarkLogic user via %s when using 'BASIC' or 'DIGEST' authentication.",
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) 2024-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
3+
*/
4+
package com.marklogic.flux.impl;
5+
6+
import com.marklogic.flux.api.AuthenticationType;
7+
import org.junit.jupiter.api.Test;
8+
9+
import static org.junit.jupiter.api.Assertions.assertEquals;
10+
import static org.junit.jupiter.api.Assertions.assertNull;
11+
12+
class ConnectionParamsValidatorTest {
13+
14+
ConnectionParamsValidator validator = new ConnectionParamsValidator(false);
15+
ConnectionInputs inputs = new ConnectionParams();
16+
17+
@Test
18+
void cloudAuth() {
19+
inputs.host = "anyhost";
20+
inputs.cloudApiKey = "anything";
21+
22+
assertEquals(0, inputs.port);
23+
assertNull(inputs.authType);
24+
25+
validator.validate(inputs);
26+
27+
assertEquals(443, inputs.port, "If a cloud API key is specified, we can assume " +
28+
"that the port should be 443.");
29+
assertEquals(AuthenticationType.CLOUD, inputs.authType, "If a cloud API key is " +
30+
"specified, we can assume that the auth type should be CLOUD.");
31+
}
32+
33+
@Test
34+
void cloudAuthAndPortAlreadySet() {
35+
inputs.host = "anyhost";
36+
inputs.cloudApiKey = "anything";
37+
inputs.port = 8443;
38+
39+
validator.validate(inputs);
40+
41+
assertEquals(8443, inputs.port,
42+
"There may be a use case in the future where a port other than 443 " +
43+
"should be used. So we allow the user to override the default of 443 " +
44+
"when a cloud API key is specified.");
45+
assertEquals(AuthenticationType.CLOUD, inputs.authType);
46+
}
47+
}

flux-cli/src/test/java/com/marklogic/flux/impl/ValidateMarkLogicConnectionTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,16 @@ void connectionStringWithoutUserOrPassword() {
7171
}
7272

7373
@Test
74-
void cloudAuthDoesntRequirePort() {
74+
void cloudAuthDoesntRequirePortOrAuthType() {
7575
// The expected error message verifies that the user does not need to provide a port when auth-type=cloud.
7676
// Otherwise, the validation for a missing port would trigger and no connection attempt would be made.
77+
// Enhanced in 2.0.0 to not require authType either. We can assume that if the user specifies a cloud-api-key,
78+
// then port should be 443 and auth type should be cloud.
7779
assertStderrContains(
7880
"Unable to call token endpoint at https://localhost/token",
7981
"import-files",
8082
"--path", "src/test/resources/mixed-files",
81-
"--host", getDatabaseClient().getHost(),
82-
"--auth-type", "cloud",
83+
"--host", "localhost",
8384
"--cloud-api-key", "doesnt-matter-for-this-test"
8485
);
8586
}

0 commit comments

Comments
 (0)