Skip to content
This repository has been archived by the owner on Dec 7, 2020. It is now read-only.

Build Time #212

Merged
merged 1 commit into from
Apr 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
26 changes: 21 additions & 5 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,34 @@ 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 (
prog = "keycloak-proxy"
author = "Rohith"
email = "[email protected]"
description = "is a proxy using the keycloak service for auth and authorization"
httpSchema = "http"

headerUpgrade = "Upgrade"
userContextName = "identity"
revokeContextName = "revoke"
authorizationHeader = "Authorization"
versionHeader = "X-Auth-Proxy-Version"
envPrefix = "PROXY_"
httpSchema = "http"

oauthURL = "/oauth"
authorizationURL = "/authorize"
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down