From b9b2d8425c66c2e3c310029d5707074118fbd3d3 Mon Sep 17 00:00:00 2001
From: Olgun Cengiz <olgun.cengiz@vereign.com>
Date: Mon, 19 Nov 2018 16:00:12 +0300
Subject: [PATCH] getVersion added

---
 Gopkg.toml         | 2 +-
 Makefile           | 5 ++++-
 handler/handler.go | 8 ++++++++
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/Gopkg.toml b/Gopkg.toml
index 8e8e994..b7dc3c1 100644
--- a/Gopkg.toml
+++ b/Gopkg.toml
@@ -1,5 +1,5 @@
 [[constraint]]
-  branch = "master"
+  branch = "devops20-monitoring"
   name = "code.vereign.com/code/viam-apis"
 
 [[constraint]]
diff --git a/Makefile b/Makefile
index e8750a7..46b3fdb 100644
--- a/Makefile
+++ b/Makefile
@@ -2,6 +2,9 @@ SERVER_OUT := "bin/server"
 PKG := "code.vereign.com/code/key-storage-agent"
 SERVER_PKG_BUILD := "${PKG}"
 PKG_LIST := $(shell go list ${PKG}/... | grep -v /vendor/)
+BRANCH := $(shell git branch | grep \* | cut -d ' ' -f2)
+COMMIT := $(shell git branch | git describe --always --long --dirty)
+VER := $(BRANCH).$(COMMIT)
 
 .PHONY: all api server
 
@@ -10,7 +13,7 @@ all: server
 dep: ## Get the dependencies
 	dep ensure
 server: dep ## Build the binary file for server
-	@go build -i -v -o $(SERVER_OUT) $(SERVER_PKG_BUILD)
+	@go build -ldflags="-X code.vereign.com/code/key-storage-agent/handler.version=$(VER)" -i -v -o $(SERVER_OUT) $(SERVER_PKG_BUILD)
 
 clean: ## Remove previous builds
 	@rm $(SERVER_OUT)
diff --git a/handler/handler.go b/handler/handler.go
index fac6e94..b53e59b 100644
--- a/handler/handler.go
+++ b/handler/handler.go
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
 package handler
 
 import (
+	"fmt"
 	"io/ioutil"
 	"strings"
 
@@ -43,6 +44,8 @@ type KeyStorageServerImpl struct {
 	MaxMessageSize			  int
 }
 
+var version = "undefined"
+
 func (s *KeyStorageServerImpl) CreateAuthentication(ctx context.Context) *authentication.Authentication {
 	if md, ok := metadata.FromIncomingContext(ctx); ok {
 		uuid := strings.Join(md["uuid"], "")
@@ -194,3 +197,8 @@ func (s *KeyStorageServerImpl) ReserveKeyUUID(ctx context.Context, in *api.Reser
 
 	return reserveKeyUUIDResponse, nil
 }
+
+func (s *KeyStorageServerImpl) GetVersionKSA(ctx context.Context, in *api.GetVersionKSAMessage) (*api.GetVersionKSAResponseMessage, error) {
+	fmt.Println("Version: " + version)
+	return &api.GetVersionKSAResponseMessage{Version: version, Errors: ""}, nil
+}
\ No newline at end of file
-- 
GitLab