Skip to content

Commit

Permalink
feat(#2538): implement configs to hide URLs in UI when needed
Browse files Browse the repository at this point in the history
closes #2538
  • Loading branch information
SteKoe committed Oct 18, 2024
1 parent 3b94e24 commit 2d933aa
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 32 deletions.
16 changes: 16 additions & 0 deletions spring-boot-admin-docs/src/site/asciidoc/customize_ui.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
11 changes: 6 additions & 5 deletions spring-boot-admin-server-ui/src/main/frontend/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ declare global {

type UITheme = {
color: string;
palette: {
backgroundEnabled: boolean;
palette?: {
shade50: string;
shade100: string;
shade200: string;
Expand Down Expand Up @@ -60,18 +61,18 @@ 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[];
routes: string[];
externalViews: ExternalView[];
viewSettings: ViewSettings[];
enableToasts: boolean;
showInstanceUrl: boolean;
};

type SBASettings = {
Expand All @@ -81,8 +82,8 @@ declare global {
[key: string]: any;
};
extensions: {
js: Extension[];
css: Extension[];
js?: Extension[];
css?: Extension[];
};
csrf: {
headerName: string;
Expand Down
12 changes: 6 additions & 6 deletions spring-boot-admin-server-ui/src/main/frontend/sba-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@ import { merge } from 'lodash-es';
const brand =
'<img src="assets/img/icon-spring-boot-admin.svg">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',
Expand All @@ -45,9 +44,10 @@ const DEFAULT_CONFIG = {
threads: 2500,
logfile: 1000,
},
showInstanceUrl: true,
},
user: null,
extensions: [],
extensions: {},
csrf: {
parameterName: '_csrf',
headerName: 'X-XSRF-TOKEN',
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -117,6 +119,13 @@ class Instance {
}));
}

showUrl() {
return (
!sbaConfig.uiSettings.showInstanceUrl ||
this.registration.metadata?.['hide-url'] === 'true'
);
}

getId() {
return this.id;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
- Copyright 2014-2018 the original author or authors.
- Copyright 2014-2024 the original author or authors.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,23 +30,36 @@
/>
</div>
<div class="flex-auto xl:flex-1 xl:w-1/4 truncate">
<a
:href="
instance.registration.serviceUrl || instance.registration.healthUrl
"
@click.stop
v-text="
instance.registration.serviceUrl || instance.registration.healthUrl
"
/>
<sba-tag
v-if="instance.registration.metadata?.['group']"
class="ml-2"
:value="instance.registration.metadata?.['group']"
small
/>
<br />
<span class="text-sm italic" v-text="instance.id" />
<template v-if="instance.showUrl()">
<a
:href="
instance.registration.serviceUrl ||
instance.registration.healthUrl
"
@click.stop
v-text="
instance.registration.serviceUrl ||
instance.registration.healthUrl
"
/>
<sba-tag
v-if="instance.registration.metadata?.['group']"
class="ml-2"
:value="instance.registration.metadata?.['group']"
small
/>
<br />
<span class="text-sm italic" v-text="instance.id" />
</template>
<template v-else>
<span v-text="instance.id"></span>
<sba-tag
v-if="instance.registration.metadata?.['group']"
class="ml-2"
:value="instance.registration.metadata?.['group']"
small
/>
</template>
</div>
<div
class="hidden xl:block w-1/4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<div class="flex-1 text-right">
<sba-button-group>
<sba-button
v-if="instance.showUrl()"
:title="instance.registration.serviceUrl"
class="border-gray-400 ml-1"
@click="openLink(instance.registration.serviceUrl)"
Expand All @@ -31,6 +32,7 @@
</sba-button>

<sba-button
v-if="instance.showUrl()"
:title="instance.registration.managementUrl"
class="border-gray-400 ml-1"
@click="openLink(instance.registration.managementUrl)"
Expand All @@ -52,6 +54,7 @@
</sba-button>

<sba-button
v-if="instance.showUrl()"
:title="instance.registration.healthUrl"
class="border-gray-400 ml-1"
@click="openLink(instance.registration.healthUrl)"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2023 the original author or authors.
* Copyright 2014-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -109,6 +109,7 @@ public UiController homeUiController(UiExtensions uiExtensions) throws IOExcepti
.favicon(this.adminUi.getFavicon())
.faviconDanger(this.adminUi.getFaviconDanger())
.enableToasts(this.adminUi.getEnableToasts())
.showInstanceUrl(this.adminUi.getShowInstanceUrl())
.notificationFilterEnabled(
!this.applicationContext.getBeansOfType(NotificationFilterController.class).isEmpty())
.routes(routes)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2023 the original author or authors.
* Copyright 2014-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -132,6 +132,11 @@ public class AdminServerUiProperties {
*/
private Boolean enableToasts = false;

/**
* Show or hide URL of instances.
*/
private Boolean showInstanceUrl = true;

private UiTheme theme = new UiTheme();

@lombok.Data
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2023 the original author or authors.
* Copyright 2014-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -150,6 +150,7 @@ public static class Settings {

private final Boolean enableToasts;

private final Boolean showInstanceUrl;
}

@lombok.Data
Expand Down

0 comments on commit 2d933aa

Please sign in to comment.