Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit f2e445c

Browse files
authored
Merge pull request #471 from marklogic-community/feature/190-mlCloudBasepath
DEVEXP-190: Added mlCloudBasePath
2 parents b7a77dc + 128d7da commit f2e445c

File tree

6 files changed

+198
-45
lines changed

6 files changed

+198
-45
lines changed

src/main/java/com/marklogic/appdeployer/DefaultAppConfigFactory.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,16 @@ public void initialize() {
266266
config.setAppServicesTrustManagementAlgorithm(prop);
267267
});
268268

269+
propertyConsumerMap.put("mlCloudBasePath", (config, prop) -> {
270+
String defaultPath = prop + "/app-services";
271+
logger.info("App-Services base path: " + defaultPath);
272+
config.setAppServicesBasePath(defaultPath);
273+
});
269274
propertyConsumerMap.put("mlAppServicesBasePath", (config, prop) -> {
270-
logger.info("App-Services base path: " + prop);
271-
config.setAppServicesBasePath(prop);
275+
String cloudBasePath = getProperty("mlCloudBasePath");
276+
String appServicesPath = StringUtils.hasText(cloudBasePath) ? cloudBasePath + prop : prop;
277+
logger.info("App-Services base path: " + appServicesPath);
278+
config.setAppServicesBasePath(appServicesPath);
272279
});
273280

274281
/**
@@ -327,12 +334,16 @@ public void initialize() {
327334
config.setRestSamlToken(prop);
328335
});
329336
propertyConsumerMap.put("mlRestBasePath", (config, prop) -> {
330-
logger.info("REST base path: " + prop);
331-
config.setRestBasePath(prop);
337+
String cloudBasePath = getProperty("mlCloudBasePath");
338+
String restPath = StringUtils.hasText(cloudBasePath) ? cloudBasePath + prop : prop;
339+
logger.info("REST base path: " + restPath);
340+
config.setRestBasePath(restPath);
332341
});
333342
propertyConsumerMap.put("mlTestRestBasePath", (config, prop) -> {
334-
logger.info("Test REST base path: " + prop);
335-
config.setTestRestBasePath(prop);
343+
String cloudBasePath = getProperty("mlCloudBasePath");
344+
String testRestPath = StringUtils.hasText(cloudBasePath) ? cloudBasePath + prop : prop;
345+
logger.info("Test REST base path: " + testRestPath);
346+
config.setTestRestBasePath(testRestPath);
336347
});
337348

338349
// Need this to be after mlRestAuthentication and mlAppServicesAuthentication are processed so

src/main/java/com/marklogic/mgmt/DefaultManageConfigFactory.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,16 @@ public void initialize() {
100100
config.setSamlToken(prop);
101101
});
102102

103+
propertyConsumerMap.put("mlCloudBasePath", (config, prop) -> {
104+
String defaultManagePath = prop + "/manage";
105+
logger.info("Manage base path: " + defaultManagePath);
106+
config.setBasePath(defaultManagePath);
107+
});
103108
propertyConsumerMap.put("mlManageBasePath", (config, prop) -> {
104-
logger.info("Manage base path: " + prop);
105-
config.setBasePath(prop);
109+
String cloudBasePath = getProperty("mlCloudBasePath");
110+
String managePath = StringUtils.hasText(cloudBasePath) ? cloudBasePath + prop : prop;
111+
logger.info("Manage base path: " + managePath);
112+
config.setBasePath(managePath);
106113
});
107114

108115
propertyConsumerMap.put("mlManageScheme", (config, prop) -> {

src/main/java/com/marklogic/mgmt/admin/DefaultAdminConfigFactory.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.marklogic.appdeployer.util.JavaClientUtil;
44
import com.marklogic.mgmt.util.PropertySource;
55
import com.marklogic.mgmt.util.PropertySourceFactory;
6+
import org.springframework.util.StringUtils;
67

78
import java.util.LinkedHashMap;
89
import java.util.Map;
@@ -96,9 +97,16 @@ public void initialize() {
9697
config.setSamlToken(prop);
9798
});
9899

100+
propertyConsumerMap.put("mlCloudBasePath", (config, prop) -> {
101+
String defaultAdminPath = prop + "/admin";
102+
logger.info("Admin base path: " + defaultAdminPath);
103+
config.setBasePath(defaultAdminPath);
104+
});
99105
propertyConsumerMap.put("mlAdminBasePath", (config, prop) -> {
100-
logger.info("Admin base path: " + prop);
101-
config.setBasePath(prop);
106+
String cloudBasePath = getProperty("mlCloudBasePath");
107+
String adminPath = StringUtils.hasText(cloudBasePath) ? cloudBasePath + prop : prop;
108+
logger.info("Admin base path: " + adminPath);
109+
config.setBasePath(adminPath);
102110
});
103111

104112
propertyConsumerMap.put("mlAdminScheme", (config, prop) -> {

src/test/java/com/marklogic/appdeployer/DefaultAppConfigFactoryTest.java

Lines changed: 90 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import com.marklogic.client.DatabaseClientFactory;
55
import com.marklogic.client.ext.SecurityContextType;
66
import com.marklogic.client.ext.modulesloader.impl.PropertiesModuleManager;
7+
import com.marklogic.mgmt.DefaultManageConfigFactory;
8+
import com.marklogic.mgmt.ManageConfig;
79
import com.marklogic.mgmt.util.SimplePropertySource;
810
import org.junit.jupiter.api.Test;
911

@@ -566,9 +568,7 @@ public void mlConfigDir() {
566568

567569
@Test
568570
public void mlUsernameAndPassword() {
569-
sut = new DefaultAppConfigFactory(
570-
new SimplePropertySource("mlUsername", "customuser", "mlPassword", "custompassword"));
571-
AppConfig config = sut.newAppConfig();
571+
AppConfig config = configure("mlUsername", "customuser", "mlPassword", "custompassword");
572572

573573
assertEquals("customuser", config.getRestAdminUsername(),
574574
"When mlRestAdminUsername is not set, mlUsername should be used");
@@ -581,8 +581,7 @@ public void mlUsernameAndPassword() {
581581

582582
@Test
583583
public void dontModifySetOfDatabasesWithForestsOnOneHostIfItsBeenConfigured() {
584-
sut = new DefaultAppConfigFactory(new SimplePropertySource("mlAppName", "example", "mlDatabasesWithForestsOnOneHost", "db1,db2"));
585-
AppConfig config = sut.newAppConfig();
584+
AppConfig config = configure("mlAppName", "example", "mlDatabasesWithForestsOnOneHost", "db1,db2");
586585

587586
Set<String> set = config.getDatabasesWithForestsOnOneHost();
588587
assertEquals(2, set.size());
@@ -596,16 +595,16 @@ public void dontModifySetOfDatabasesWithForestsOnOneHostIfItsBeenConfigured() {
596595

597596
@Test
598597
public void appServicesSimpleSsl() {
599-
AppConfig config = new DefaultAppConfigFactory(new SimplePropertySource("mlAppServicesSimpleSsl", "true")).newAppConfig();
598+
AppConfig config = configure("mlAppServicesSimpleSsl", "true");
600599
assertEquals("TLSv1.2", config.getAppServicesSslContext().getProtocol());
601600

602-
config = new DefaultAppConfigFactory(new SimplePropertySource("mlAppServicesSimpleSsl", "TLSv1.2")).newAppConfig();
601+
config = configure("mlAppServicesSimpleSsl", "TLSv1.2");
603602
assertEquals("TLSv1.2", config.getAppServicesSslContext().getProtocol());
604603

605-
config = new DefaultAppConfigFactory(new SimplePropertySource("mlAppServicesSimpleSsl", "TLSv1.1")).newAppConfig();
604+
config = configure("mlAppServicesSimpleSsl", "TLSv1.1");
606605
assertEquals("TLSv1.1", config.getAppServicesSslContext().getProtocol());
607606

608-
config = new DefaultAppConfigFactory(new SimplePropertySource("mlAppServicesSimpleSsl", "false")).newAppConfig();
607+
config = configure("mlAppServicesSimpleSsl", "false");
609608
assertNull(config.getAppServicesSslContext());
610609

611610
config = new DefaultAppConfigFactory(new SimplePropertySource()).newAppConfig();
@@ -614,16 +613,16 @@ public void appServicesSimpleSsl() {
614613

615614
@Test
616615
public void restSimpleSsl() {
617-
AppConfig config = new DefaultAppConfigFactory(new SimplePropertySource("mlSimpleSsl", "true")).newAppConfig();
616+
AppConfig config = configure("mlSimpleSsl", "true");
618617
assertEquals("TLSv1.2", config.getRestSslContext().getProtocol());
619618

620-
config = new DefaultAppConfigFactory(new SimplePropertySource("mlSimpleSsl", "TLSv1.2")).newAppConfig();
619+
config = configure("mlSimpleSsl", "TLSv1.2");
621620
assertEquals("TLSv1.2", config.getRestSslContext().getProtocol());
622621

623-
config = new DefaultAppConfigFactory(new SimplePropertySource("mlSimpleSsl", "TLSv1.1")).newAppConfig();
622+
config = configure("mlSimpleSsl", "TLSv1.1");
624623
assertEquals("TLSv1.1", config.getRestSslContext().getProtocol());
625624

626-
config = new DefaultAppConfigFactory(new SimplePropertySource("mlSimpleSsl", "false")).newAppConfig();
625+
config = configure("mlSimpleSsl", "false");
627626
assertNull(config.getRestSslContext());
628627

629628
config = new DefaultAppConfigFactory(new SimplePropertySource()).newAppConfig();
@@ -632,11 +631,11 @@ public void restSimpleSsl() {
632631

633632
@Test
634633
public void restUseDefaultKeystore() {
635-
AppConfig config = new DefaultAppConfigFactory(new SimplePropertySource(
634+
AppConfig config = configure(
636635
"mlRestUseDefaultKeystore", "true",
637636
"mlRestSslProtocol", "SSLv3",
638637
"mlRestTrustManagementAlgorithm", "PKIX"
639-
)).newAppConfig();
638+
);
640639

641640
assertTrue(config.isRestUseDefaultKeystore());
642641
assertEquals("SSLv3", config.getRestSslProtocol());
@@ -645,11 +644,11 @@ public void restUseDefaultKeystore() {
645644

646645
@Test
647646
public void appServicesUseDefaultKeystore() {
648-
AppConfig config = new DefaultAppConfigFactory(new SimplePropertySource(
647+
AppConfig config = configure(
649648
"mlAppServicesUseDefaultKeystore", "true",
650649
"mlAppServicesSslProtocol", "SSLv3",
651650
"mlAppServicesTrustManagementAlgorithm", "PKIX"
652-
)).newAppConfig();
651+
);
653652

654653
assertTrue(config.isAppServicesUseDefaultKeystore());
655654
assertEquals("SSLv3", config.getAppServicesSslProtocol());
@@ -658,12 +657,12 @@ public void appServicesUseDefaultKeystore() {
658657

659658
@Test
660659
void cloudApiKeyAndBasePath() {
661-
AppConfig config = new DefaultAppConfigFactory(new SimplePropertySource(
660+
AppConfig config = configure(
662661
"mlCloudApiKey", "my-key",
663662
"mlRestBasePath", "/rest/path",
664663
"mlAppServicesBasePath", "/app/path",
665664
"mlTestRestBasePath", "/test/path"
666-
)).newAppConfig();
665+
);
667666

668667
assertEquals("my-key", config.getCloudApiKey());
669668
assertEquals("/rest/path", config.getRestBasePath());
@@ -673,10 +672,10 @@ void cloudApiKeyAndBasePath() {
673672

674673
@Test
675674
void sslHostnameVerifier() {
676-
AppConfig config = new DefaultAppConfigFactory(new SimplePropertySource(
675+
AppConfig config = configure(
677676
"mlRestSslHostnameVerifier", "any",
678677
"mlAppServicesSslHostnameVerifier", "COMmon"
679-
)).newAppConfig();
678+
);
680679

681680
assertEquals(DatabaseClientFactory.SSLHostnameVerifier.ANY, config.getRestSslHostnameVerifier());
682681
assertEquals(DatabaseClientFactory.SSLHostnameVerifier.COMMON, config.getAppServicesSslHostnameVerifier());
@@ -698,38 +697,38 @@ void sslHostnameVerifier() {
698697

699698
@Test
700699
void mlSslHostnameVerifier() {
701-
AppConfig config = new DefaultAppConfigFactory(new SimplePropertySource(
700+
AppConfig config = configure(
702701
"mlSslHostnameVerifier", "ANY"
703-
)).newAppConfig();
702+
);
704703

705704
assertEquals(DatabaseClientFactory.SSLHostnameVerifier.ANY, config.getRestSslHostnameVerifier());
706705
assertEquals(DatabaseClientFactory.SSLHostnameVerifier.ANY, config.getAppServicesSslHostnameVerifier());
707706

708-
config = new DefaultAppConfigFactory(new SimplePropertySource(
707+
config = configure(
709708
"mlSslHostnameVerifier", "ANY",
710709
"mlRestSslHostnameVerifier", "STRICT"
711-
)).newAppConfig();
710+
);
712711

713712
assertEquals(DatabaseClientFactory.SSLHostnameVerifier.STRICT, config.getRestSslHostnameVerifier());
714713
assertEquals(DatabaseClientFactory.SSLHostnameVerifier.ANY, config.getAppServicesSslHostnameVerifier());
715714

716-
config = new DefaultAppConfigFactory(new SimplePropertySource(
715+
config = configure(
717716
"mlSslHostnameVerifier", "ANY",
718717
"mlAppServicesSslHostnameVerifier", "STRICT"
719-
)).newAppConfig();
718+
);
720719

721720
assertEquals(DatabaseClientFactory.SSLHostnameVerifier.ANY, config.getRestSslHostnameVerifier());
722721
assertEquals(DatabaseClientFactory.SSLHostnameVerifier.STRICT, config.getAppServicesSslHostnameVerifier());
723722
}
724723

725724
@Test
726725
void samlTokens() {
727-
AppConfig config = new DefaultAppConfigFactory(new SimplePropertySource(
726+
AppConfig config = configure(
728727
"mlRestAuthentication", "saml",
729728
"mlRestSamlToken", "my-rest-token",
730729
"mlAppServicesAuthentication", "saml",
731730
"mlAppServicesSamlToken", "my-app-token"
732-
)).newAppConfig();
731+
);
733732

734733
assertEquals(SecurityContextType.SAML, config.getRestSecurityContextType());
735734
assertEquals("my-rest-token", config.getRestSamlToken());
@@ -749,33 +748,89 @@ void samlTokens() {
749748

750749
@Test
751750
void mlAuthentication() {
752-
AppConfig config = new DefaultAppConfigFactory(new SimplePropertySource(
751+
AppConfig config = configure(
753752
"mlAuthentication", "cloud"
754-
)).newAppConfig();
753+
);
755754

756755
assertEquals(SecurityContextType.CLOUD, config.getRestSecurityContextType());
757756
assertEquals(SecurityContextType.CLOUD, config.getAppServicesSecurityContextType());
758757
}
759758

760759
@Test
761760
void mlAuthenticationAndRestOverridden() {
762-
AppConfig config = new DefaultAppConfigFactory(new SimplePropertySource(
761+
AppConfig config = configure(
763762
"mlAuthentication", "cloud",
764763
"mlRestAuthentication", "basic"
765-
)).newAppConfig();
764+
);
766765

767766
assertEquals(SecurityContextType.BASIC, config.getRestSecurityContextType());
768767
assertEquals(SecurityContextType.CLOUD, config.getAppServicesSecurityContextType());
769768
}
770769

771770
@Test
772771
void mlAuthenticationAndAppServicesOverridden() {
773-
AppConfig config = new DefaultAppConfigFactory(new SimplePropertySource(
772+
AppConfig config = configure(
774773
"mlAuthentication", "cloud",
775774
"mlAppServicesAuthentication", "saml"
776-
)).newAppConfig();
775+
);
777776

778777
assertEquals(SecurityContextType.CLOUD, config.getRestSecurityContextType());
779778
assertEquals(SecurityContextType.SAML, config.getAppServicesSecurityContextType());
780779
}
780+
781+
@Test
782+
void mlAppServicesBasePath() {
783+
AppConfig config = configure(
784+
"mlAppServicesBasePath", "/my/custom/app-services/path"
785+
);
786+
assertEquals("/my/custom/app-services/path", config.getAppServicesBasePath(),
787+
"If a user only specifies mlAppServicesBasePath, then the assumption is that they're using a reverse proxy and " +
788+
"have defined their own custom path for the App-Services app server. They could be using ML Cloud, but " +
789+
"that's not likely as it would make more sense to still define mlCloudBasePath and then set " +
790+
"mlAppServicesBasePath to the custom App-Services part (as a user is not allowed to setup a base path in ML Cloud " +
791+
"that doesn't begin with their common base path).");
792+
}
793+
794+
@Test
795+
void mlCloudBasePath() {
796+
AppConfig config = configure(
797+
"mlCloudBasePath", "/my/domain"
798+
);
799+
assertEquals("/my/domain/app-services", config.getAppServicesBasePath(),
800+
"If a user only specifies mlCloudBasePath, then the assumption is that they're good to go with the default " +
801+
"App-Services base path setup in ML Cloud, and so they only need to define the 'cloud base path' that occurs " +
802+
"before '/app-services'");
803+
804+
String message = "mlCloudBasePath only sets default values for the Admin, Manage, and " +
805+
"App-Services servers; it's up to the user to define the base path for their custom REST server";
806+
assertNull(config.getRestBasePath(), message);
807+
assertNull(config.getTestRestBasePath(), message);
808+
}
809+
810+
@Test
811+
void mlCloudBasePathWithAppServicesBasePath() {
812+
AppConfig config = configure(
813+
"mlCloudBasePath", "/my/domain",
814+
"mlAppServicesBasePath", "/my-custom-app-services-path"
815+
);
816+
assertEquals("/my/domain/my-custom-app-services-path", config.getAppServicesBasePath(),
817+
"If a user specifies both mlCloudBasePath and mlAppServicesBasePath, then the assumption is that they've " +
818+
"changed the default App-Services base path but it still begins with the common base path defined by " +
819+
"mlCloudBasePath.");
820+
}
821+
822+
@Test
823+
void mlCloudBasePathAndMlRestBasePath() {
824+
AppConfig config = configure(
825+
"mlCloudBasePath", "/my/domain",
826+
"mlRestBasePath", "/my/rest/server",
827+
"mlTestRestBasePath", "/my/test/server"
828+
);
829+
assertEquals("/my/domain/my/rest/server", config.getRestBasePath());
830+
assertEquals("/my/domain/my/test/server", config.getTestRestBasePath());
831+
}
832+
833+
private AppConfig configure(String... properties) {
834+
return new DefaultAppConfigFactory(new SimplePropertySource(properties)).newAppConfig();
835+
}
781836
}

src/test/java/com/marklogic/mgmt/DefaultManageConfigFactoryTest.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,42 @@ void mlAuthentication() {
204204
assertEquals("basic", config.getSecurityContextType());
205205
}
206206

207+
@Test
208+
void mlManageBasePath() {
209+
ManageConfig config = configure(
210+
"mlManageBasePath", "/my/custom/manage/path"
211+
);
212+
assertEquals("/my/custom/manage/path", config.getBasePath(),
213+
"If a user only specifies mlManageBasePath, then the assumption is that they're using a reverse proxy and " +
214+
"have defined their own custom path for the Manage app server. They could be using ML Cloud, but " +
215+
"that's not likely as it would make more sense to still define mlCloudBasePath and then set " +
216+
"mlManageBasePath to the custom Manage part (as a user is not allowed to setup a base path in ML Cloud " +
217+
"that doesn't begin with their common base path).");
218+
}
219+
220+
@Test
221+
void mlCloudBasePath() {
222+
ManageConfig config = configure(
223+
"mlCloudBasePath", "/my/domain"
224+
);
225+
assertEquals("/my/domain/manage", config.getBasePath(),
226+
"If a user only specifies mlCloudBasePath, then the assumption is that they're good to go with the default " +
227+
"Manage base path setup in ML Cloud, and so they only need to define the 'cloud base path' that occurs " +
228+
"before '/manage'");
229+
}
230+
231+
@Test
232+
void mlCloudBasePathWithManageBasePath() {
233+
ManageConfig config = configure(
234+
"mlCloudBasePath", "/my/domain",
235+
"mlManageBasePath", "/my-custom-manage-path"
236+
);
237+
assertEquals("/my/domain/my-custom-manage-path", config.getBasePath(),
238+
"If a user specifies both mlCloudBasePath and mlManageBasePath, then the assumption is that they've " +
239+
"changed the default Manage base path but it still begins with the common base path defined by " +
240+
"mlCloudBasePath.");
241+
}
242+
207243
private ManageConfig configure(String... properties) {
208244
return new DefaultManageConfigFactory(new SimplePropertySource(properties)).newManageConfig();
209245
}

0 commit comments

Comments
 (0)