From 72276a39515f20f6570077b8fd742fe3e53df87a Mon Sep 17 00:00:00 2001 From: HiSEN Date: Tue, 11 Jun 2019 15:41:07 +0800 Subject: [PATCH] dashboard: Add HTTP API to get the version the of the dashboard (#800) --- sentinel-dashboard/pom.xml | 1 + .../controller/VersionController.java | 46 +++++++++++++++++++ .../src/main/resources/application.properties | 5 +- 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/VersionController.java diff --git a/sentinel-dashboard/pom.xml b/sentinel-dashboard/pom.xml index b8bafb10..31334f5d 100755 --- a/sentinel-dashboard/pom.xml +++ b/sentinel-dashboard/pom.xml @@ -175,6 +175,7 @@ src/main/resources + true diff --git a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/VersionController.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/VersionController.java new file mode 100644 index 00000000..255acdfd --- /dev/null +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/VersionController.java @@ -0,0 +1,46 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alibaba.csp.sentinel.dashboard.controller; + +import com.alibaba.csp.sentinel.dashboard.domain.Result; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author hisenyuan + * @date 2019-05-30 10:47:50 + */ +@RestController +@RequestMapping(value = "/") +public class VersionController { + @Value("${sentinel.dashboard.version:''}") + private String sentinelDashboardVersion; + private static String VERSION_PATTERN = "-"; + + @RequestMapping(value = "/getVersion") + public Result getVersion() { + if (sentinelDashboardVersion != null) { + String res = sentinelDashboardVersion; + if (sentinelDashboardVersion.contains(VERSION_PATTERN)) { + res = sentinelDashboardVersion.substring(0, sentinelDashboardVersion.indexOf(VERSION_PATTERN)); + } + return Result.ofSuccess(res); + } else { + return Result.ofFail(1, "getVersion failed"); + } + } +} diff --git a/sentinel-dashboard/src/main/resources/application.properties b/sentinel-dashboard/src/main/resources/application.properties index 609cd90e..f15544dd 100755 --- a/sentinel-dashboard/src/main/resources/application.properties +++ b/sentinel-dashboard/src/main/resources/application.properties @@ -13,4 +13,7 @@ logging.pattern.file= %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - % auth.filter.exclude-urls=/,/auth/login,/auth/logout,/registry/machine auth.filter.exclude-url-suffixes=htm,html,js,css,map,ico,ttf,woff,png auth.username=sentinel -auth.password=sentinel \ No newline at end of file +auth.password=sentinel + +# get the project version for index +sentinel.dashboard.version=${project.version} \ No newline at end of file