From 2d933aa2b7320760120f2a9ae9e41555311d44c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20Ko=CC=88ninger?= Date: Fri, 18 Oct 2024 14:30:32 +0200 Subject: [PATCH] feat(#2538): implement configs to hide URLs in UI when needed closes #2538 --- .../src/site/asciidoc/customize_ui.adoc | 16 ++++++ .../src/main/frontend/global.d.ts | 11 +++-- .../src/main/frontend/sba-config.ts | 12 ++--- .../src/main/frontend/services/instance.ts | 9 ++++ .../views/applications/InstancesList.vue | 49 ++++++++++++------- .../views/instances/details/details-nav.vue | 3 ++ .../AdminServerUiAutoConfiguration.java | 3 +- .../ui/config/AdminServerUiProperties.java | 7 ++- .../admin/server/ui/web/UiController.java | 3 +- 9 files changed, 81 insertions(+), 32 deletions(-) diff --git a/spring-boot-admin-docs/src/site/asciidoc/customize_ui.adoc b/spring-boot-admin-docs/src/site/asciidoc/customize_ui.adoc index 15366318cd5..e09bd4f8e06 100644 --- a/spring-boot-admin-docs/src/site/asciidoc/customize_ui.adoc +++ b/spring-boot-admin-docs/src/site/asciidoc/customize_ui.adoc @@ -216,3 +216,19 @@ You can very simply hide views in the navbar: ---- include::{samples-dir}/spring-boot-admin-sample-servlet/src/main/resources/application.yml[tags=customization-view-settings] ---- + +== Hide Service URL == +To hide service URLs in Spring Boot Admin UI entirely, set the following property in your Server's configuration: + +|=== +| Property name | Default | Usage + +| `spring.boot.admin.ui.show-instance-url` +| `true` +| Set to `false` to hide service URLs as well as actions that require them in UI (e.g. jump to /health or /actuator). + +|=== + +If you want to hide the URL for specific instances oncly, you can set the `hide-url` property in the instance metadata while registering a service. +When using Spring Boot Admin Client you can set the property `spring.boot.admin.client.metadata.hide-url=true` in the corresponding config file. +The value set in `metadata` does not have any effect, when the URLs are disabled in Server. diff --git a/spring-boot-admin-server-ui/src/main/frontend/global.d.ts b/spring-boot-admin-server-ui/src/main/frontend/global.d.ts index c475056a935..ef21de9eabd 100644 --- a/spring-boot-admin-server-ui/src/main/frontend/global.d.ts +++ b/spring-boot-admin-server-ui/src/main/frontend/global.d.ts @@ -20,7 +20,8 @@ declare global { type UITheme = { color: string; - palette: { + backgroundEnabled: boolean; + palette?: { shade50: string; shade100: string; shade200: string; @@ -60,11 +61,10 @@ declare global { type UISettings = { title: string; brand: string; - loginIcon: string; favicon: string; faviconDanger: string; pollTimer: PollTimer; - uiTheme: UITheme; + theme: UITheme; notificationFilterEnabled: boolean; rememberMeEnabled: boolean; availableLanguages: string[]; @@ -72,6 +72,7 @@ declare global { externalViews: ExternalView[]; viewSettings: ViewSettings[]; enableToasts: boolean; + showInstanceUrl: boolean; }; type SBASettings = { @@ -81,8 +82,8 @@ declare global { [key: string]: any; }; extensions: { - js: Extension[]; - css: Extension[]; + js?: Extension[]; + css?: Extension[]; }; csrf: { headerName: string; diff --git a/spring-boot-admin-server-ui/src/main/frontend/sba-config.ts b/spring-boot-admin-server-ui/src/main/frontend/sba-config.ts index 0fe5717c31d..368e4dc2556 100644 --- a/spring-boot-admin-server-ui/src/main/frontend/sba-config.ts +++ b/spring-boot-admin-server-ui/src/main/frontend/sba-config.ts @@ -18,17 +18,16 @@ import { merge } from 'lodash-es'; const brand = 'Spring Boot Admin'; -const DEFAULT_CONFIG = { +const DEFAULT_CONFIG: SBASettings = { uiSettings: { + title: 'Spring Boot Admin', brand, theme: { backgroundEnabled: true, color: '#42d3a5', }, - notifications: { - enabled: true, - }, rememberMeEnabled: true, + enableToasts: false, externalViews: [] as ExternalView[], favicon: 'assets/img/favicon.png', faviconDanger: 'assets/img/favicon-danger.png', @@ -45,9 +44,10 @@ const DEFAULT_CONFIG = { threads: 2500, logfile: 1000, }, + showInstanceUrl: true, }, user: null, - extensions: [], + extensions: {}, csrf: { parameterName: '_csrf', headerName: 'X-XSRF-TOKEN', @@ -57,7 +57,7 @@ const DEFAULT_CONFIG = { }, }; -const mergedConfig = merge(DEFAULT_CONFIG, window.SBA); +const mergedConfig = merge(DEFAULT_CONFIG, window.SBA) as SBASettings; export const getCurrentUser = () => { return mergedConfig.user; diff --git a/spring-boot-admin-server-ui/src/main/frontend/services/instance.ts b/spring-boot-admin-server-ui/src/main/frontend/services/instance.ts index 9f537913791..ba97fe05970 100644 --- a/spring-boot-admin-server-ui/src/main/frontend/services/instance.ts +++ b/spring-boot-admin-server-ui/src/main/frontend/services/instance.ts @@ -25,6 +25,8 @@ import waitForPolyfill from '../utils/eventsource-polyfill'; import logtail from '../utils/logtail'; import uri from '../utils/uri'; +import sbaConfig from '@/sba-config'; + const actuatorMimeTypes = [ 'application/vnd.spring-boot.actuator.v2+json', 'application/vnd.spring-boot.actuator.v1+json', @@ -117,6 +119,13 @@ class Instance { })); } + showUrl() { + return ( + !sbaConfig.uiSettings.showInstanceUrl || + this.registration.metadata?.['hide-url'] === 'true' + ); + } + getId() { return this.id; } diff --git a/spring-boot-admin-server-ui/src/main/frontend/views/applications/InstancesList.vue b/spring-boot-admin-server-ui/src/main/frontend/views/applications/InstancesList.vue index ef3ce04328d..1ac92520e67 100644 --- a/spring-boot-admin-server-ui/src/main/frontend/views/applications/InstancesList.vue +++ b/spring-boot-admin-server-ui/src/main/frontend/views/applications/InstancesList.vue @@ -1,5 +1,5 @@