From 8919c48f31f6b61cb64ccd955a5c71986d27d4b4 Mon Sep 17 00:00:00 2001 From: MiniDigger | Martin Date: Sat, 5 Nov 2022 12:22:53 +0100 Subject: [PATCH] feat: add version page --- backend/pom.xml | 2 +- .../hangar/config/hangar/HangarConfig.java | 9 ---- .../controller/ApplicationController.java | 25 ++------- .../hangar/controller/extras/StatusZ.java | 42 --------------- .../internal/BackendDataController.java | 22 +++++++- backend/src/main/resources/banner.txt | 2 +- frontend/src/lib | 2 +- frontend/src/pages/tos.vue | 1 + frontend/src/pages/version.vue | 52 +++++++++++++++++++ frontend/src/store/backendData.ts | 14 +++++ 10 files changed, 96 insertions(+), 75 deletions(-) delete mode 100644 backend/src/main/java/io/papermc/hangar/controller/extras/StatusZ.java create mode 100644 frontend/src/pages/version.vue diff --git a/backend/pom.xml b/backend/pom.xml index dd1bf55e..8d2e9540 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -319,7 +319,7 @@ false yyyy-MM-dd-HH:mm:ss ${project.basedir}/.git - false + true diff --git a/backend/src/main/java/io/papermc/hangar/config/hangar/HangarConfig.java b/backend/src/main/java/io/papermc/hangar/config/hangar/HangarConfig.java index c7ad8dc1..7ed529f3 100644 --- a/backend/src/main/java/io/papermc/hangar/config/hangar/HangarConfig.java +++ b/backend/src/main/java/io/papermc/hangar/config/hangar/HangarConfig.java @@ -17,7 +17,6 @@ import java.util.List; public class HangarConfig { private String logo = "https://docs.papermc.io/img/paper.png"; - private String service = "Hangar"; private List sponsors; private boolean dev = true; @@ -119,14 +118,6 @@ public class HangarConfig { this.logo = logo; } - public String getService() { - return service; - } - - public void setService(String service) { - this.service = service; - } - public List getSponsors() { return sponsors; } diff --git a/backend/src/main/java/io/papermc/hangar/controller/ApplicationController.java b/backend/src/main/java/io/papermc/hangar/controller/ApplicationController.java index 1c92f741..84f965fc 100644 --- a/backend/src/main/java/io/papermc/hangar/controller/ApplicationController.java +++ b/backend/src/main/java/io/papermc/hangar/controller/ApplicationController.java @@ -1,33 +1,18 @@ package io.papermc.hangar.controller; -import com.fasterxml.jackson.databind.node.ObjectNode; -import io.papermc.hangar.HangarComponent; -import io.papermc.hangar.controller.extras.RobotsBuilder; -import io.papermc.hangar.controller.extras.StatusZ; -import io.papermc.hangar.security.annotations.Anyone; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ResponseBody; +import io.papermc.hangar.HangarComponent; +import io.papermc.hangar.controller.extras.RobotsBuilder; +import io.papermc.hangar.security.annotations.Anyone; + @Anyone @Controller public class ApplicationController extends HangarComponent { - private final StatusZ statusZ; - - @Autowired - public ApplicationController(StatusZ statusZ) { - this.statusZ = statusZ; - } - - @ResponseBody - @GetMapping("/statusz") - public ObjectNode showStatusZ() { - return statusZ.getStatus(); - } - @GetMapping(path = "/robots.txt", produces = MediaType.TEXT_PLAIN_VALUE) @ResponseBody public String robots() { @@ -45,7 +30,7 @@ public class ApplicationController extends HangarComponent { .disallow("/admin") .disallow("/actuator") .disallow("/error") - .disallow("/statusz") + .disallow("/version-info") .disallow("/api") .allow("/api$") .disallow("/notifications") diff --git a/backend/src/main/java/io/papermc/hangar/controller/extras/StatusZ.java b/backend/src/main/java/io/papermc/hangar/controller/extras/StatusZ.java deleted file mode 100644 index fa4a7852..00000000 --- a/backend/src/main/java/io/papermc/hangar/controller/extras/StatusZ.java +++ /dev/null @@ -1,42 +0,0 @@ -package io.papermc.hangar.controller.extras; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; -import io.papermc.hangar.config.hangar.HangarConfig; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -@Component -public class StatusZ { - - private final ObjectNode status; - - private final String BUILD_NUM = "BUILD_NUMBER"; - private final String GIT_BRANCH = "GIT_BRANCH"; - private final String GIT_COMMIT = "GIT_COMMIT"; - private final String JOB_NAME = "JOB_NAME"; - private final String BUILD_TAG = "BUILD_TAG"; - private final String HANGAR_ENV = "HANGAR_ENV"; - private final String SERVICE = "SERVICE"; - - @Autowired - public StatusZ(HangarConfig hangarConfig, ObjectMapper mapper) { - status = mapper.createObjectNode(); - status.set(BUILD_NUM, mapper.valueToTree(getEnv(BUILD_NUM))); - status.set(GIT_BRANCH, mapper.valueToTree(getEnv(GIT_BRANCH))); - status.set(GIT_COMMIT, mapper.valueToTree(getEnv(GIT_COMMIT))); - status.set(JOB_NAME, mapper.valueToTree(getEnv(JOB_NAME))); - status.set(BUILD_TAG, mapper.valueToTree(getEnv(BUILD_TAG))); - status.set(HANGAR_ENV, mapper.valueToTree(getEnv(HANGAR_ENV))); - status.set(SERVICE, mapper.valueToTree(hangarConfig.getService())); - - } - - public ObjectNode getStatus() { - return status; - } - - private String getEnv(String key) { - return System.getenv().getOrDefault(key, "unknown"); - } -} diff --git a/backend/src/main/java/io/papermc/hangar/controller/internal/BackendDataController.java b/backend/src/main/java/io/papermc/hangar/controller/internal/BackendDataController.java index 80393c5c..c2388343 100644 --- a/backend/src/main/java/io/papermc/hangar/controller/internal/BackendDataController.java +++ b/backend/src/main/java/io/papermc/hangar/controller/internal/BackendDataController.java @@ -25,6 +25,7 @@ import io.papermc.hangar.security.annotations.Anyone; import io.papermc.hangar.security.annotations.ratelimit.RateLimit; import io.papermc.hangar.service.internal.PlatformService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.info.GitProperties; import org.springframework.cache.annotation.Cacheable; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -38,6 +39,8 @@ import org.springframework.web.bind.annotation.ResponseBody; import java.lang.annotation.Annotation; import java.util.Arrays; import java.util.List; +import java.util.Map; +import java.util.Optional; import java.util.concurrent.ThreadLocalRandom; @Controller @@ -49,12 +52,14 @@ public class BackendDataController { private final ObjectMapper noJsonValueMapper; private final HangarConfig config; private final PlatformService platformService; + private final GitProperties gitProperties; @Autowired - public BackendDataController(ObjectMapper mapper, HangarConfig config, PlatformService platformService) { + public BackendDataController(ObjectMapper mapper, HangarConfig config, PlatformService platformService, GitProperties gitProperties) { this.config = config; this.noJsonValueMapper = mapper.copy(); this.platformService = platformService; + this.gitProperties = gitProperties; this.noJsonValueMapper.setAnnotationIntrospector(new JacksonAnnotationIntrospector() { @Override protected A _findAnnotation(Annotated annotated, Class annoClass) { @@ -182,6 +187,21 @@ public class BackendDataController { return Prompt.getValues(); } + @ResponseBody + @GetMapping("/version-info") + public Map info() { + return Map.of( + "version", gitProperties.get("build.version"), + "committer", gitProperties.get("commit.user.name"), + "time", gitProperties.get("commit.time"), + "commit", gitProperties.getCommitId(), + "commitShort", gitProperties.getShortCommitId(), + "message", gitProperties.get("commit.message.short"), + "tag", Optional.of(gitProperties.get("tags")).orElse(gitProperties.get("closest.tag.name")), + "behind", gitProperties.get("closest.tag.commit.count") + ); + } + @GetMapping("/validations") @Cacheable("validations") public ResponseEntity getValidations() { diff --git a/backend/src/main/resources/banner.txt b/backend/src/main/resources/banner.txt index 4ba7b664..54e5e390 100644 --- a/backend/src/main/resources/banner.txt +++ b/backend/src/main/resources/banner.txt @@ -14,4 +14,4 @@ Hangar version @project.version@, running commit @git.commit.id.abbrev@, committed on @git.commit.time@ @git.commit.user.name@ <@git.commit.user.email@>: @git.commit.message.short@ -Running Spring Boot @spring-boot.version@ +Running Spring Boot ${spring-boot.version} diff --git a/frontend/src/lib b/frontend/src/lib index ec51c259..32e402d1 160000 --- a/frontend/src/lib +++ b/frontend/src/lib @@ -1 +1 @@ -Subproject commit ec51c259360015f4d905bbcb2b97c9a1ed55e7a4 +Subproject commit 32e402d11c4eb6d9ca4077d2a9eba5d0c30471ac diff --git a/frontend/src/pages/tos.vue b/frontend/src/pages/tos.vue index b38caf57..3697794f 100644 --- a/frontend/src/pages/tos.vue +++ b/frontend/src/pages/tos.vue @@ -1,5 +1,6 @@