Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support context path for admin servlet #3520

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ private static Map<String, String> asMap() {
.put(LOG_TEMPLATE_EXCEPTIONS_KEY_CAMEL_CASE, Boolean.FALSE.toString())
.put(NUMBER_FORMAT_KEY_CAMEL_CASE, "computer")
.put(LOCALE_KEY, "")
.put(OUTPUT_ENCODING_KEY, "utf-8")
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,31 @@
import com.bakdata.conquery.models.config.ConqueryConfig;
import com.bakdata.conquery.models.jobs.JobManager;
import com.bakdata.conquery.models.worker.DatasetRegistry;
import com.bakdata.conquery.resources.admin.rest.*;
import com.bakdata.conquery.resources.admin.ui.*;
import com.bakdata.conquery.resources.admin.rest.AdminConceptsResource;
import com.bakdata.conquery.resources.admin.rest.AdminDatasetProcessor;
import com.bakdata.conquery.resources.admin.rest.AdminDatasetResource;
import com.bakdata.conquery.resources.admin.rest.AdminDatasetsResource;
import com.bakdata.conquery.resources.admin.rest.AdminProcessor;
import com.bakdata.conquery.resources.admin.rest.AdminResource;
import com.bakdata.conquery.resources.admin.rest.AdminTablesResource;
import com.bakdata.conquery.resources.admin.rest.AuthOverviewResource;
import com.bakdata.conquery.resources.admin.rest.GroupResource;
import com.bakdata.conquery.resources.admin.rest.PermissionResource;
import com.bakdata.conquery.resources.admin.rest.RoleResource;
import com.bakdata.conquery.resources.admin.rest.UIProcessor;
import com.bakdata.conquery.resources.admin.rest.UserResource;
import com.bakdata.conquery.resources.admin.ui.AdminUIResource;
import com.bakdata.conquery.resources.admin.ui.AuthOverviewUIResource;
import com.bakdata.conquery.resources.admin.ui.ConceptsUIResource;
import com.bakdata.conquery.resources.admin.ui.DatasetsUIResource;
import com.bakdata.conquery.resources.admin.ui.GroupUIResource;
import com.bakdata.conquery.resources.admin.ui.IndexServiceUIResource;
import com.bakdata.conquery.resources.admin.ui.RoleUIResource;
import com.bakdata.conquery.resources.admin.ui.TablesUIResource;
import com.bakdata.conquery.resources.admin.ui.UserUIResource;
import com.bakdata.conquery.resources.admin.ui.model.ConnectorUIResource;
import io.dropwizard.core.setup.AdminEnvironment;
import io.dropwizard.core.setup.Environment;
import io.dropwizard.jersey.DropwizardResourceConfig;
import io.dropwizard.jersey.jackson.JacksonMessageBodyProvider;
import io.dropwizard.servlets.assets.AssetServlet;
Expand Down Expand Up @@ -95,6 +116,7 @@ protected void configure() {
bind(manager.getValidator()).to(Validator.class);
bind(manager.getJobManager()).to(JobManager.class);
bind(manager.getConfig()).to(ConqueryConfig.class);
bind(manager.getEnvironment()).to(Environment.class);
bind(adminProcessor).to(AdminProcessor.class);
bind(adminDatasetProcessor).to(AdminDatasetProcessor.class);
}
Expand All @@ -117,6 +139,7 @@ protected void configure() {
bind(manager.getDatasetRegistry()).to(DatasetRegistry.class);
bind(manager.getMetaStorage()).to(MetaStorage.class);
bind(manager.getConfig()).to(ConqueryConfig.class);
bind(manager.getEnvironment()).to(Environment.class);
}
})
.register(AdminPermissionFilter.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.TreeSet;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import jakarta.inject.Inject;

import com.bakdata.conquery.io.cps.CPSTypeIdResolver;
import com.bakdata.conquery.io.storage.MetaStorage;
Expand Down Expand Up @@ -43,7 +44,7 @@
import com.bakdata.conquery.resources.admin.ui.model.TableStatistics;
import com.bakdata.conquery.resources.admin.ui.model.UIContext;
import com.google.common.cache.CacheStats;
import jakarta.inject.Inject;
import io.dropwizard.core.setup.Environment;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -60,6 +61,8 @@ public class UIProcessor {
@Getter
private final AdminProcessor adminProcessor;

private final Environment environment;

public DatasetRegistry<? extends Namespace> getDatasetRegistry() {
return adminProcessor.getDatasetRegistry();
}
Expand All @@ -69,7 +72,10 @@ public MetaStorage getStorage() {
}

public UIContext getUIContext(String csrfToken) {
return new UIContext(adminProcessor.getNodeProvider(), csrfToken);
String adminContextPath = environment.getAdminContext().getContextPath();
// If the context is just the root, we omit the slash as our path are absolute
adminContextPath = adminContextPath.equals("/")? "" : adminContextPath;
return new UIContext(adminProcessor.getNodeProvider(), csrfToken, adminContextPath);
}

public Set<IndexKey<?>> getLoadedIndexes() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class UIContext {
@Getter
public final String csrfToken;

@Getter
public final String adminContextPath;

public Map<SocketAddress, ShardNodeInformation> getShardNodes() {
return shardNodeSupplier.get().stream().collect(Collectors.toMap(
ShardNodeInformation::getRemoteAddress,
Expand Down
2 changes: 1 addition & 1 deletion backend/src/main/resources/assets/custom/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function toForceURL(url) {

async function rest(url, options) {
var res = await fetch(
url,
`${adminContextPath}${url}`,
{
method: 'get',
credentials: 'same-origin',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

<div id="all_datasets" class="mt-1">
<h3>All Datasets</h3>
<@table.table columns=columns items=c?sort_by("name") link="/admin-ui/datasets/" deleteButton=deleteDatasetButton cypressId="datasets"/>
<@table.table columns=columns items=c?sort_by("name") link="${ctxPath}/admin-ui/datasets/" deleteButton=deleteDatasetButton cypressId="datasets"/>
</div>

</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<#global ctxPath=ctx.adminContextPath?url_path>
<#macro html title >
<!doctype html>
<html lang="en">
Expand All @@ -7,20 +8,21 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<link rel="stylesheet" href="/assets/bootstrap-4.3.1/css/bootstrap.min.css">
<link rel="stylesheet" href="/assets/fontawesome-5.0.8/css/fa-solid.min.css">
<link rel="stylesheet" href="/assets/fontawesome-5.0.8/css/fontawesome.min.css">
<link rel="stylesheet" href="/assets/custom/css/style.css">
<link rel="stylesheet" href="${ctxPath}/assets/bootstrap-4.3.1/css/bootstrap.min.css">
<link rel="stylesheet" href="${ctxPath}/assets/fontawesome-5.0.8/css/fa-solid.min.css">
<link rel="stylesheet" href="${ctxPath}/assets/fontawesome-5.0.8/css/fontawesome.min.css">
<link rel="stylesheet" href="${ctxPath}/assets/custom/css/style.css">

<script src="/assets/jquery-3.3.1/jquery.min.js"></script>
<script src="/assets/popper-1.12.9/popper.min.js"></script>
<script src="/assets/bootstrap-4.3.1/js/bootstrap.min.js"></script>
<script src="/assets/custom/js/script.js"></script>
<script src="${ctxPath}/assets/jquery-3.3.1/jquery.min.js"></script>
<script src="${ctxPath}/assets/popper-1.12.9/popper.min.js"></script>
<script src="${ctxPath}/assets/bootstrap-4.3.1/js/bootstrap.min.js"></script>
<script src="${ctxPath}/assets/custom/js/script.js"></script>


<script>
<#-- Global varaible for csrf used by rest-method -->
<#-- Global variable for csrf used by rest-method -->
var csrf_token = "${ctx.csrfToken}"
const adminContextPath = "${ctxPath}"
</script>

<title>${title}</title>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<@base.html "Conquery Admin UI" >
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light" style="margin-bottom:30px">
<a class="navbar-brand" href="/admin-ui">Conquery Admin</a>
<a class="navbar-brand" href="${ctxPath}/admin-ui">Conquery Admin</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
Expand All @@ -12,29 +12,29 @@
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="/admin-ui/datasets">Datasets</a>
<a class="nav-link" href="${ctxPath}/admin-ui/datasets">Datasets</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/${ctx.staticUriElem.ADMIN_UI_SERVLET_PATH}/${ctx.staticUriElem.INDEX_SERVICE_PATH_ELEMENT}">Index Service</a>
<a class="nav-link" href="${ctxPath}/${ctx.staticUriElem.ADMIN_UI_SERVLET_PATH}/${ctx.staticUriElem.INDEX_SERVICE_PATH_ELEMENT}">Index Service</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/admin-ui/jobs">Jobs</a>
<a class="nav-link" href="${ctxPath}/admin-ui/jobs">Jobs</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/admin-ui/queries">Queries</a>
<a class="nav-link" href="${ctxPath}/admin-ui/queries">Queries</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/admin-ui/script">Script</a>
<a class="nav-link" href="${ctxPath}/admin-ui/script">Script</a>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Auth
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="/admin-ui/auth-overview">Overview</a>
<a class="dropdown-item" href="/admin-ui/groups">Groups</a>
<a class="dropdown-item" href="/admin-ui/users">Users</a>
<a class="dropdown-item" href="/admin-ui/roles">Roles</a>
<a class="dropdown-item" href="${ctxPath}/admin-ui/auth-overview">Overview</a>
<a class="dropdown-item" href="${ctxPath}/admin-ui/groups">Groups</a>
<a class="dropdown-item" href="${ctxPath}/admin-ui/users">Users</a>
<a class="dropdown-item" href="${ctxPath}/admin-ui/roles">Roles</a>
</div>
</li>
<li class="nav-item dropdown">
Expand All @@ -43,9 +43,9 @@
Dropwizard
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="/metrics?pretty=true">Metrics JSON</a>
<a class="dropdown-item" href="/threads">Threads</a>
<a class="dropdown-item" href="/healthcheck?pretty=true">Health</a>
<a class="dropdown-item" href="${ctxPath}/metrics?pretty=true">Metrics JSON</a>
<a class="dropdown-item" href="${ctxPath}/threads">Threads</a>
<a class="dropdown-item" href="${ctxPath}/healthcheck?pretty=true">Health</a>
<a class="dropdown-item" href=""
onclick="shutdown(event)"><i
class="fas fa-power-off text-danger"></i> Shutdown</a>
Expand All @@ -61,7 +61,7 @@
</div>

<div class="pl-2">
<a href="/admin-ui/logout" class="btn btn-secondary">Logout</a>
<a href="${ctxPath}/admin-ui/logout" class="btn btn-secondary">Logout</a>
</div>
</nav>

Expand Down
Loading