Skip to content

Commit 04d0a50

Browse files
david-leifkerestebanchriscollins3456
authored
feat(): Basepath support (#14866)
Co-authored-by: Esteban Gutierrez <[email protected]> Co-authored-by: Chris Collins <[email protected]>
1 parent 00caa38 commit 04d0a50

File tree

137 files changed

+5739
-400
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+5739
-400
lines changed

datahub-frontend/app/Filters.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import filters.BasePathRedirectFilter
2+
import javax.inject.Inject
3+
import play.api.http.HttpFilters
4+
5+
class Filters @Inject()(basePathRedirectFilter: BasePathRedirectFilter) extends HttpFilters {
6+
override val filters = Seq(basePathRedirectFilter)
7+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package modules;
2+
3+
import com.google.inject.AbstractModule;
4+
import com.typesafe.config.Config;
5+
import com.typesafe.config.ConfigRenderOptions;
6+
import javax.inject.Inject;
7+
import javax.inject.Singleton;
8+
import lombok.extern.slf4j.Slf4j;
9+
import play.Environment;
10+
11+
/** Module to dump configuration on application startup */
12+
public class StartupModule extends AbstractModule {
13+
14+
@Override
15+
protected void configure() {
16+
bind(ConfigDumper.class).asEagerSingleton();
17+
}
18+
19+
@Slf4j
20+
@Singleton
21+
public static class ConfigDumper {
22+
23+
@Inject
24+
public ConfigDumper(Config config, Environment environment) {
25+
// Dump configuration on startup (constructor is called during app initialization)
26+
dumpConfiguration(config, environment);
27+
}
28+
29+
private void dumpConfiguration(Config config, Environment environment) {
30+
log.info("=== DataHub Frontend Configuration ===");
31+
log.info("Environment: {}", environment.mode());
32+
log.info("Env root path: {}", environment.rootPath());
33+
log.info("Base Path: {}", config.getString("datahub.basePath"));
34+
log.info("GMS Host: {}", config.getString("metadataService.host"));
35+
log.info("GMS Port: {}", config.getInt("metadataService.port"));
36+
log.info(
37+
"GMS Base Path: {}",
38+
config.hasPath("metadataService.basePath")
39+
? config.getString("metadataService.basePath")
40+
: "not set");
41+
42+
// Dump all datahub.* configuration if available
43+
if (config.hasPath("datahub")) {
44+
Config datahubConfig = config.getConfig("datahub");
45+
String datahubConfigStr =
46+
datahubConfig.root().render(ConfigRenderOptions.defaults().setOriginComments(false));
47+
log.info("DataHub Configuration:\n{}", datahubConfigStr);
48+
}
49+
50+
// Optionally dump full configuration (be careful - may contain secrets)
51+
if (config.hasPath("debug.dumpFullConfig") && config.getBoolean("debug.dumpFullConfig")) {
52+
log.warn("=== FULL CONFIGURATION DUMP (may contain secrets) ===");
53+
String fullConfig =
54+
config.root().render(ConfigRenderOptions.defaults().setOriginComments(false));
55+
log.info("Full Configuration:\n{}", fullConfig);
56+
}
57+
58+
log.info("=== End Configuration Dump ===");
59+
}
60+
}
61+
}

datahub-frontend/app/auth/AuthModule.java

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,14 @@ protected AuthServiceClient provideAuthClient(
303303

304304
final int metadataServicePort = getMetadataServicePort(configs);
305305

306+
final String metadataServiceBasePath = getMetadataServiceBasePath(configs);
307+
306308
final boolean metadataServiceUseSsl = doesMetadataServiceUseSsl(configs);
307309

308310
return new AuthServiceClient(
309311
metadataServiceHost,
310312
metadataServicePort,
313+
metadataServiceBasePath,
311314
metadataServiceUseSsl,
312315
systemAuthentication,
313316
httpClient);
@@ -356,6 +359,16 @@ private com.linkedin.restli.client.Client buildRestliClient() {
356359
configs,
357360
utils.ConfigUtil.METADATA_SERVICE_PORT_CONFIG_PATH,
358361
utils.ConfigUtil.DEFAULT_METADATA_SERVICE_PORT);
362+
final String metadataServiceBasePath =
363+
utils.ConfigUtil.getString(
364+
configs,
365+
utils.ConfigUtil.METADATA_SERVICE_BASE_PATH_CONFIG_PATH,
366+
utils.ConfigUtil.DEFAULT_METADATA_SERVICE_BASE_PATH);
367+
final boolean metadataServiceBasePathEnabled =
368+
utils.ConfigUtil.getBoolean(
369+
configs,
370+
utils.ConfigUtil.METADATA_SERVICE_BASE_PATH_ENABLED_CONFIG_PATH,
371+
utils.ConfigUtil.DEFAULT_METADATA_SERVICE_BASE_PATH_ENABLED);
359372
final boolean metadataServiceUseSsl =
360373
utils.ConfigUtil.getBoolean(
361374
configs,
@@ -366,9 +379,16 @@ private com.linkedin.restli.client.Client buildRestliClient() {
366379
configs,
367380
utils.ConfigUtil.METADATA_SERVICE_SSL_PROTOCOL_CONFIG_PATH,
368381
ConfigUtil.DEFAULT_METADATA_SERVICE_SSL_PROTOCOL);
382+
383+
// Use the same logic as GMSConfiguration.getResolvedBasePath()
384+
String resolvedBasePath =
385+
com.linkedin.metadata.utils.BasePathUtils.resolveBasePath(
386+
metadataServiceBasePathEnabled, metadataServiceBasePath);
387+
369388
return DefaultRestliClientFactory.getRestLiClient(
370389
metadataServiceHost,
371390
metadataServicePort,
391+
resolvedBasePath,
372392
metadataServiceUseSsl,
373393
metadataServiceSslProtocol);
374394
}
@@ -393,13 +413,35 @@ protected Integer getMetadataServicePort(com.typesafe.config.Config configs) {
393413
Configuration.getEnvironmentVariable(GMS_PORT_ENV_VAR, DEFAULT_GMS_PORT));
394414
}
395415

416+
protected String getMetadataServiceBasePath(com.typesafe.config.Config configs) {
417+
final String basePath =
418+
configs.hasPath(METADATA_SERVICE_BASE_PATH_CONFIG_PATH)
419+
? configs.getString(METADATA_SERVICE_BASE_PATH_CONFIG_PATH)
420+
: Configuration.getEnvironmentVariable(GMS_BASE_PATH_ENV_VAR, DEFAULT_GMS_BASE_PATH);
421+
422+
final boolean basePathEnabled =
423+
configs.hasPath(METADATA_SERVICE_BASE_PATH_ENABLED_CONFIG_PATH)
424+
? configs.getBoolean(METADATA_SERVICE_BASE_PATH_ENABLED_CONFIG_PATH)
425+
: Boolean.parseBoolean(
426+
Configuration.getEnvironmentVariable(
427+
"DATAHUB_GMS_BASE_PATH_ENABLED", DEFAULT_GMS_BASE_PATH_ENABLED));
428+
429+
// Use the same logic as GMSConfiguration.getResolvedBasePath()
430+
return com.linkedin.metadata.utils.BasePathUtils.resolveBasePath(basePathEnabled, basePath);
431+
}
432+
396433
protected String getSsoSettingsRequestUrl(com.typesafe.config.Config configs) {
397434
final String protocol = doesMetadataServiceUseSsl(configs) ? "https" : "http";
398435
final String metadataServiceHost = getMetadataServiceHost(configs);
436+
final String metadataServiceBasePath = getMetadataServiceBasePath(configs);
399437
final Integer metadataServicePort = getMetadataServicePort(configs);
400438

401439
return String.format(
402-
"%s://%s:%s/%s",
403-
protocol, metadataServiceHost, metadataServicePort, GET_SSO_SETTINGS_ENDPOINT);
440+
"%s://%s:%s%s/%s",
441+
protocol,
442+
metadataServiceHost,
443+
metadataServicePort,
444+
metadataServiceBasePath,
445+
GET_SSO_SETTINGS_ENDPOINT);
404446
}
405447
}

datahub-frontend/app/client/AuthServiceClient.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public class AuthServiceClient {
4646

4747
private final String metadataServiceHost;
4848
private final Integer metadataServicePort;
49+
private final String metadataServiceBasePath;
4950
private final Boolean metadataServiceUseSsl;
5051
private final Authentication systemAuthentication;
5152
private final CloseableHttpClient httpClient;
@@ -54,11 +55,13 @@ public class AuthServiceClient {
5455
public AuthServiceClient(
5556
@Nonnull final String metadataServiceHost,
5657
@Nonnull final Integer metadataServicePort,
58+
@Nonnull final String metadataServiceBasePath,
5759
@Nonnull final Boolean useSsl,
5860
@Nonnull final Authentication systemAuthentication,
5961
@Nonnull final CloseableHttpClient httpClient) {
6062
this.metadataServiceHost = Objects.requireNonNull(metadataServiceHost);
6163
this.metadataServicePort = Objects.requireNonNull(metadataServicePort);
64+
this.metadataServiceBasePath = Objects.requireNonNull(metadataServiceBasePath);
6265
this.metadataServiceUseSsl = Objects.requireNonNull(useSsl);
6366
this.systemAuthentication = Objects.requireNonNull(systemAuthentication);
6467
this.httpClient = Objects.requireNonNull(httpClient);
@@ -81,10 +84,11 @@ public String generateSessionTokenForUser(@Nonnull final String userId, String l
8184
final HttpPost request =
8285
new HttpPost(
8386
String.format(
84-
"%s://%s:%s/%s",
87+
"%s://%s:%s%s/%s",
8588
protocol,
8689
this.metadataServiceHost,
8790
this.metadataServicePort,
91+
this.metadataServiceBasePath,
8892
GENERATE_SESSION_TOKEN_ENDPOINT));
8993

9094
log.info("Requesting session token for user: {}", userId);
@@ -150,8 +154,12 @@ public boolean signUp(
150154
final HttpPost request =
151155
new HttpPost(
152156
String.format(
153-
"%s://%s:%s/%s",
154-
protocol, this.metadataServiceHost, this.metadataServicePort, SIGN_UP_ENDPOINT));
157+
"%s://%s:%s%s/%s",
158+
protocol,
159+
this.metadataServiceHost,
160+
this.metadataServicePort,
161+
this.metadataServiceBasePath,
162+
SIGN_UP_ENDPOINT));
155163

156164
// Build JSON request to sign up a native user.
157165
final ObjectMapper objectMapper = new ObjectMapper();
@@ -215,10 +223,11 @@ public boolean resetNativeUserCredentials(
215223
final HttpPost request =
216224
new HttpPost(
217225
String.format(
218-
"%s://%s:%s/%s",
226+
"%s://%s:%s%s/%s",
219227
protocol,
220228
this.metadataServiceHost,
221229
this.metadataServicePort,
230+
this.metadataServiceBasePath,
222231
RESET_NATIVE_USER_CREDENTIALS_ENDPOINT));
223232

224233
// Build JSON request to verify credentials for a native user.
@@ -272,10 +281,11 @@ public boolean verifyNativeUserCredentials(
272281
final HttpPost request =
273282
new HttpPost(
274283
String.format(
275-
"%s://%s:%s/%s",
284+
"%s://%s:%s%s/%s",
276285
protocol,
277286
this.metadataServiceHost,
278287
this.metadataServicePort,
288+
this.metadataServiceBasePath,
279289
VERIFY_NATIVE_USER_CREDENTIALS_ENDPOINT));
280290

281291
// Build JSON request to verify credentials for a native user.

0 commit comments

Comments
 (0)