From 735711536a91f1ab1f45655ecec5f19eeafda95d Mon Sep 17 00:00:00 2001 From: Marko Zivanovic Date: Wed, 26 Nov 2014 23:11:52 +0100 Subject: [PATCH] Frontend should display version information. --- pom.xml | 4 ++ .../secret/api/controllers/SasController.java | 20 +++++++ .../share/a/secret/api/dto/SasResponse.java | 10 ++-- .../share/a/secret/api/dto/Version.java | 55 +++++++++++++++++++ src/main/resources/application.properties | 4 ++ src/main/resources/application.yml | 5 -- src/main/resources/static/index.html | 11 ++++ src/main/resources/static/js/app.js | 4 ++ src/main/resources/static/js/controllers.js | 6 +- src/main/resources/static/js/services.js | 9 ++- 10 files changed, 113 insertions(+), 15 deletions(-) create mode 100644 src/main/java/rs/in/zivanovic/share/a/secret/api/dto/Version.java create mode 100644 src/main/resources/application.properties delete mode 100644 src/main/resources/application.yml diff --git a/pom.xml b/pom.xml index 062268e..975ede6 100644 --- a/pom.xml +++ b/pom.xml @@ -52,6 +52,10 @@ org.springframework.boot spring-boot-maven-plugin + + pl.project13.maven + git-commit-id-plugin + diff --git a/src/main/java/rs/in/zivanovic/share/a/secret/api/controllers/SasController.java b/src/main/java/rs/in/zivanovic/share/a/secret/api/controllers/SasController.java index 1481fc6..74b474e 100644 --- a/src/main/java/rs/in/zivanovic/share/a/secret/api/controllers/SasController.java +++ b/src/main/java/rs/in/zivanovic/share/a/secret/api/controllers/SasController.java @@ -24,7 +24,10 @@ package rs.in.zivanovic.share.a.secret.api.controllers; import java.util.List; +import java.util.MissingResourceException; +import java.util.ResourceBundle; import javax.validation.Valid; +import org.springframework.beans.factory.annotation.Value; import org.springframework.http.ResponseEntity; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.RequestBody; @@ -36,6 +39,7 @@ import rs.in.zivanovic.share.a.secret.api.SecretShare; import rs.in.zivanovic.share.a.secret.api.ShamirSecretSharing; import rs.in.zivanovic.share.a.secret.api.dto.SasResponse; import rs.in.zivanovic.share.a.secret.api.dto.SplitParameters; +import rs.in.zivanovic.share.a.secret.api.dto.Version; /** * @@ -45,6 +49,9 @@ import rs.in.zivanovic.share.a.secret.api.dto.SplitParameters; @RequestMapping("/sas") public class SasController { + @Value("${info.build.version:''}") + private String version; + @RequestMapping(method = RequestMethod.POST, value = "/split") public ResponseEntity split(@Valid @RequestBody SplitParameters params, BindingResult br) { if (br.hasErrors()) { @@ -62,4 +69,17 @@ public class SasController { params.getThreshold()); return SasResponse.ok().withData(new Shares(shares)).build(); } + + @RequestMapping(method = RequestMethod.GET, value = "/version") + public ResponseEntity version() { + String commitId = ""; + String buildTime = ""; + try { + ResourceBundle rb = ResourceBundle.getBundle("git"); + commitId = rb.getString("git.commit.id.abbrev"); + buildTime = rb.getString("git.build.time"); + } catch (MissingResourceException ex) { + } + return SasResponse.ok().withData(new Version(String.format("%s.%s", version, commitId), buildTime)).build(); + } } diff --git a/src/main/java/rs/in/zivanovic/share/a/secret/api/dto/SasResponse.java b/src/main/java/rs/in/zivanovic/share/a/secret/api/dto/SasResponse.java index fb255c7..385ae63 100644 --- a/src/main/java/rs/in/zivanovic/share/a/secret/api/dto/SasResponse.java +++ b/src/main/java/rs/in/zivanovic/share/a/secret/api/dto/SasResponse.java @@ -29,8 +29,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; /** - * Every call to share-a-secret API service returns object of SasResponse class - * as response. + * Every call to share-a-secret API service returns object of SasResponse class as response. * * @author Marko Zivanovic */ @@ -48,13 +47,14 @@ public class SasResponse { return new SasResponse(status); } - public SasResponse withData(Shares shares) { - data = shares; + public SasResponse withData(Object data) { + this.data = data; return this; } public SasResponse withInvalidParameterValueError(String field, Object value, String reason) { - return withError(Error.INVALID_PARAMETER_VALUE, String.format("Invalid value '%s' for field '%s' because '%s'", value, field, reason)); + return withError(Error.INVALID_PARAMETER_VALUE, String.format("Invalid value '%s' for field '%s' because '%s'", + value, field, reason)); } public SasResponse withError(int code, String message) { diff --git a/src/main/java/rs/in/zivanovic/share/a/secret/api/dto/Version.java b/src/main/java/rs/in/zivanovic/share/a/secret/api/dto/Version.java new file mode 100644 index 0000000..80bda7a --- /dev/null +++ b/src/main/java/rs/in/zivanovic/share/a/secret/api/dto/Version.java @@ -0,0 +1,55 @@ +/* + * The MIT License + * + * Copyright 2014 Marko Zivanovic. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package rs.in.zivanovic.share.a.secret.api.dto; + +/** + * + * @author Marko Zivanovic + */ +public class Version { + + private String frontendVersion; + private String buildTime; + + public Version(String frontendVersion, String buildTime) { + this.frontendVersion = frontendVersion; + this.buildTime = buildTime; + } + + public String getFrontendVersion() { + return frontendVersion; + } + + public void setFrontendVersion(String frontendVersion) { + this.frontendVersion = frontendVersion; + } + + public String getBuildTime() { + return buildTime; + } + + public void setBuildTime(String buildTime) { + this.buildTime = buildTime; + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..e5e005c --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,4 @@ +info.build.artifact=@project.artifactId@ +info.build.name=@project.name@ +info.build.description=@project.description@ +info.build.version=@project.version@ diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml deleted file mode 100644 index 7bc2b98..0000000 --- a/src/main/resources/application.yml +++ /dev/null @@ -1,5 +0,0 @@ -spring: - jackson: - serialization: - WRITE_NULL_PROPERTIES: false - \ No newline at end of file diff --git a/src/main/resources/static/index.html b/src/main/resources/static/index.html index cc92be3..84d7a5f 100644 --- a/src/main/resources/static/index.html +++ b/src/main/resources/static/index.html @@ -90,7 +90,18 @@ + + + diff --git a/src/main/resources/static/js/app.js b/src/main/resources/static/js/app.js index 90c3087..e663b5a 100644 --- a/src/main/resources/static/js/app.js +++ b/src/main/resources/static/js/app.js @@ -39,4 +39,8 @@ angular.module('sasApp', [ }); } }; +}).run(function (SasService, $rootScope) { + SasService.version({}, function (response) { + $rootScope.version = response.data; + }); }); diff --git a/src/main/resources/static/js/controllers.js b/src/main/resources/static/js/controllers.js index 35180e8..5ca65e2 100644 --- a/src/main/resources/static/js/controllers.js +++ b/src/main/resources/static/js/controllers.js @@ -23,8 +23,8 @@ */ angular.module('sasControllers', []). - controller('MainController', ['$scope', 'SplitService', - function ($scope, SplitService) { + controller('MainController', ['$scope', 'SasService', + function ($scope, SasService) { $scope.total = 10; $scope.threshold = 3; @@ -48,7 +48,7 @@ angular.module('sasControllers', []). $scope.errors = []; $scope.shares = []; clickedShares = {}; - SplitService.split({ + SasService.split({ secret: $scope.secret, total: $scope.total, threshold: $scope.threshold}, diff --git a/src/main/resources/static/js/services.js b/src/main/resources/static/js/services.js index 3bac9e8..61eb957 100644 --- a/src/main/resources/static/js/services.js +++ b/src/main/resources/static/js/services.js @@ -23,10 +23,15 @@ */ angular.module('sasServices', []). - factory('SplitService', ['$resource', function ($resource) { - return $resource("/sas/split", {}, { + factory('SasService', ['$resource', function ($resource) { + return $resource("/sas", {}, { split: { + url: "/sas/split", method: "POST" + }, + version: { + url: "/sas/version", + method: "GET" } }); }]);