Skip to content

Commit 03e6bab

Browse files
rahulvudutalaSanjeevani19
authored andcommitted
DHFPROD-10455: Consume ML Cloud Headers in HubCentral
1 parent 6a11882 commit 03e6bab

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

marklogic-data-hub-central/src/main/java/com/marklogic/hub/central/CloudParameters.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ public class CloudParameters {
1616
public static String ADMIN_BASE_PATH = "";
1717

1818
public static void updateCloudParameters(Map<String, String> cloudProperties) {
19-
ML_HOST = cloudProperties.get("mlHost");
20-
AUTHENTICATION_TYPE = cloudProperties.get("mlAuthentication");
21-
HC_BASE_PATH = cloudProperties.get("mlHcBasePath");
22-
STAGING_BASE_PATH = cloudProperties.get("mlStagingBasePath");
23-
FINAL_BASE_PATH = cloudProperties.get("mlFinalBasePath");
24-
JOB_BASE_PATH = cloudProperties.get("mlJobBasePath");
25-
MANAGE_BASE_PATH = cloudProperties.get("mlManageBasePath");
26-
APP_SERVICES_BASE_PATH = cloudProperties.get("mlAppServicesBasePath");
27-
ADMIN_BASE_PATH = cloudProperties.get("mlAdminBasePath");
19+
ML_HOST = cloudProperties.get("mlHost".toLowerCase());
20+
AUTHENTICATION_TYPE = cloudProperties.get("mlAuthentication".toLowerCase());
21+
HC_BASE_PATH = cloudProperties.get("mlHcBasePath".toLowerCase());
22+
STAGING_BASE_PATH = cloudProperties.get("mlStagingBasePath".toLowerCase());
23+
FINAL_BASE_PATH = cloudProperties.get("mlFinalBasePath".toLowerCase());
24+
JOB_BASE_PATH = cloudProperties.get("mlJobBasePath".toLowerCase());
25+
MANAGE_BASE_PATH = cloudProperties.get("mlManageBasePath".toLowerCase());
26+
APP_SERVICES_BASE_PATH = cloudProperties.get("mlAppServicesBasePath".toLowerCase());
27+
ADMIN_BASE_PATH = cloudProperties.get("mlAdminBasePath".toLowerCase());
2828
}
2929
}

marklogic-data-hub-central/src/main/java/com/marklogic/hub/central/HubCentral.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ protected PropertySource buildPropertySource(String username, String password, P
111111
protected PropertySource buildPropertySource(Properties primaryProperties) {
112112
return propertyName -> {
113113
String value = primaryProperties.getProperty(propertyName);
114-
if (!propertyName.equals("mlUsername") && !propertyName.equals("mlPassword") && environment.getProperty(propertyName) != null) {
114+
if (!propertyName.equals("mlUsername") && !propertyName.equals("mlPassword") && !propertyName.equals("mlAuthentication") && environment.getProperty(propertyName) != null) {
115115
value = environment.getProperty(propertyName);
116116
}
117117
return value;

marklogic-data-hub-central/src/main/java/com/marklogic/hub/central/controllers/SinglePageAppController.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import java.util.stream.Collectors;
2020

2121
@Controller
22-
public class SinglePageAppController implements ErrorController {
22+
public class SinglePageAppController extends BaseController implements ErrorController {
2323

2424
@Autowired
2525
HubCentral hubCentral;
@@ -40,9 +40,11 @@ public class SinglePageAppController implements ErrorController {
4040
@RequestMapping(value = {"/"})
4141
public String index(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
4242
if(environment.getProperty("mlAuthentication").equalsIgnoreCase("cloud")) {
43-
Map<String, String> headers = getHeadersMap(httpServletRequest);
43+
Map<String, String> headers = Collections.list(httpServletRequest.getHeaderNames()).stream()
44+
.collect(Collectors.toMap(h -> h, httpServletRequest::getHeader));
45+
logger.info("Headers Map: " + headers);
4446
CloudParameters.updateCloudParameters(headers);
45-
createHubConfigurations(headers.getOrDefault("mlCloudApiKey", ""));
47+
createHubConfigurations(headers.getOrDefault("mlCloudApiKey".toLowerCase(), ""));
4648
addCookiesToResponse(httpServletResponse);
4749
}
4850
return "forward:index.html";
@@ -55,8 +57,7 @@ private void createHubConfigurations(String cloudApikey) {
5557
}
5658

5759
private Map<String, String> getHeadersMap(HttpServletRequest httpServletRequest) {
58-
Map<String, String> headers = new HashMap<>();
59-
Collections.list(httpServletRequest.getHeaderNames()).stream()
60+
Map<String, String> headers = Collections.list(httpServletRequest.getHeaderNames()).stream()
6061
.collect(Collectors.toMap(h -> h, httpServletRequest::getHeader));
6162
// These values are for testing
6263
addHeadersFromCloudForTesting(headers);
@@ -78,7 +79,7 @@ private void addHeadersFromCloudForTesting(Map<String, String> headers) {
7879
}
7980

8081
private void addCookiesToResponse(HttpServletResponse response) {
81-
response.addCookie(new Cookie("mlHcBasePath", "/hc"));
82-
response.addCookie(new Cookie("mlAuthentication", "cloud"));
82+
response.addCookie(new Cookie("mlHcBasePath", CloudParameters.HC_BASE_PATH));
83+
response.addCookie(new Cookie("mlAuthentication", CloudParameters.AUTHENTICATION_TYPE));
8384
}
8485
}

marklogic-data-hub-central/src/main/resources/application.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ log.path=./logs
3939
#management.endpoint.health.show-details=always
4040
spring.mvc.pathmatch.matching-strategy=ant_path_matcher
4141
hubCentralVersion=6.0-SNAPSHOT
42+
mlAuthentication=local

0 commit comments

Comments
 (0)