diff --git a/Makefile b/Makefile index 8c3c1e5a..43ea1d49 100644 --- a/Makefile +++ b/Makefile @@ -6,11 +6,11 @@ GOVERSION ?= 1.8.1 ROOT_DIR=${PWD} HARDWARE=$(shell uname -m) GIT_SHA=$(shell git --no-pager describe --always --dirty) -BUILD_TIME=$(shell date -u '+%Y-%m-%d_%I:%M:%S%p') +BUILD_TIME=$(shell date '+%s') VERSION ?= $(shell awk '/release.*=/ { print $$3 }' doc.go | sed 's/"//g') DEPS=$(shell go list -f '{{range .TestImports}}{{.}} {{end}}' ./...) PACKAGES=$(shell go list ./...) -LFLAGS ?= -X main.gitsha=${GIT_SHA} +LFLAGS ?= -X main.gitsha=${GIT_SHA} -X main.compiled=${BUILD_TIME} VETARGS ?= -asmdecl -atomic -bool -buildtags -copylocks -methods -nilfunc -printf -rangeloops -shift -structtags -unsafeptr .PHONY: test authors changelog build docker static release lint cover vet diff --git a/cli.go b/cli.go index b7743134..ceb951b6 100644 --- a/cli.go +++ b/cli.go @@ -32,7 +32,7 @@ func newOauthProxyApp() *cli.App { app := cli.NewApp() app.Name = prog app.Usage = description - app.Version = version + app.Version = getVersion() app.Author = author app.Email = email app.Flags = getCommandLineOptions() diff --git a/doc.go b/doc.go index 404e31a9..819c083b 100644 --- a/doc.go +++ b/doc.go @@ -17,16 +17,19 @@ package main import ( "errors" + "fmt" "net/http" + "strconv" "time" "github.com/coreos/go-oidc/jose" ) var ( - release = "v2.1.0" - gitsha = "no gitsha provided" - version = release + " (git+sha: " + gitsha + ")" + release = "v2.1.0" + gitsha = "no gitsha provided" + compiled = "0" + version = "" ) const ( @@ -34,7 +37,6 @@ const ( author = "Rohith" email = "gambol99@gmail.com" description = "is a proxy using the keycloak service for auth and authorization" - httpSchema = "http" headerUpgrade = "Upgrade" userContextName = "identity" @@ -42,6 +44,7 @@ const ( authorizationHeader = "Authorization" versionHeader = "X-Auth-Proxy-Version" envPrefix = "PROXY_" + httpSchema = "http" oauthURL = "/oauth" authorizationURL = "/authorize" @@ -229,10 +232,23 @@ type Config struct { ForwardingDomains []string `json:"forwarding-domains" yaml:"forwarding-domains" usage:"list of domains which should be signed; everything else is relayed unsigned"` } +// getVersion returns the proxy version +func getVersion() string { + if version == "" { + tm, err := strconv.ParseInt(compiled, 10, 64) + if err != nil { + return "unable to parse compiled time" + } + version = fmt.Sprintf("git+sha: %s, built: %s", gitsha, time.Unix(tm, 0).Format("02/01/2006")) + } + + return version +} + // storage is used to hold the offline refresh token, assuming you don't want to use // the default practice of a encrypted cookie type storage interface { - // Add the token to the store + // Set the token to the store Set(string, string) error // Get retrieves a token from the store Get(string) (string, error) diff --git a/handlers.go b/handlers.go index 76678494..a976db4e 100644 --- a/handlers.go +++ b/handlers.go @@ -425,7 +425,7 @@ func (r *oauthProxy) tokenHandler(cx echo.Context) error { // healthHandler is a health check handler for the service func (r *oauthProxy) healthHandler(cx echo.Context) error { - cx.Response().Writer.Header().Set(versionHeader, version) + cx.Response().Writer.Header().Set(versionHeader, getVersion()) return cx.String(http.StatusOK, "OK\n") }