Skip to content
Snippets Groups Projects
Commit 87ae7c73 authored by Niall Sheridan's avatar Niall Sheridan
Browse files

Add version string

Add `lib.Version` to get updated at build time.
Add --version flags to cashier and cashierd
Send client version in the signing request
Send server version in http response headers and in signing response
Set version at build time
parent 3e006c39
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,7 @@ LABEL maintainer="nsheridan@gmail.com"
ARG SRC_DIR=/go/src/github.com/nsheridan/cashier
WORKDIR ${SRC_DIR}
ADD . ${SRC_DIR}
RUN CGO_ENABLED=0 GOOS=linux go install -a -installsuffix static ./cmd/cashierd
RUN CGO_ENABLED=0 GOOS=linux make install-cashierd
FROM scratch
LABEL maintainer="nsheridan@gmail.com"
......
CASHIER_CMD := ./cmd/cashier
CASHIER_BIN := ./cashier
CASHIERD_BIN := ./cashierd
CASHIERD_CMD := ./cmd/cashierd
SRC_FILES = $(shell find * -type f -name '*.go' -not -path 'vendor/*' -not -name 'a_*-packr.go')
VERSION_PKG := "github.com/nsheridan/cashier/lib.Version"
VERSION := $(shell git describe --tags --always --dirty)
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
CGO_ENABLED ?= $(shell go env CGO_ENABLED)
all: test build
......@@ -20,11 +24,11 @@ build: cashier cashierd
generate:
go generate -x ./...
cashier:
go build -o cashier $(CASHIER_CMD)
%-cmd:
CGO_ENABLED=$(CGO_ENABLED) GOARCH=$(GOARCH) GOOS=$(GOOS) go build -ldflags="-X $(VERSION_PKG)=$(VERSION)" -o $* ./cmd/$*
cashierd: generate
go build -o cashierd $(CASHIERD_CMD)
install-%: generate
CGO_ENABLED=$(CGO_ENABLED) GOARCH=$(GOARCH) GOOS=$(GOOS) go install -x -ldflags="-X $(VERSION_PKG)=$(VERSION)" ./cmd/$*
clean:
rm -f cashier cashierd
......@@ -37,4 +41,7 @@ dep:
go get -u golang.org/x/lint/golint
go get -u golang.org/x/tools/cmd/goimports
version:
@echo $(VERSION)
.PHONY: all build dep generate test cashier cashierd clean migration
......@@ -142,6 +142,7 @@ func Sign(pub ssh.PublicKey, token string, conf *Config) (*ssh.Certificate, erro
s := &lib.SignRequest{
Key: string(lib.GetPublicKey(pub)),
ValidUntil: time.Now().Add(validity),
Version: lib.Version,
}
resp := &lib.SignResponse{}
for {
......
......@@ -13,6 +13,7 @@ import (
"time"
"github.com/nsheridan/cashier/client"
"github.com/nsheridan/cashier/lib"
"github.com/pkg/browser"
"github.com/spf13/pflag"
"golang.org/x/crypto/ssh/agent"
......@@ -21,15 +22,20 @@ import (
var (
u, _ = user.Current()
cfg = pflag.String("config", path.Join(u.HomeDir, ".cashier.conf"), "Path to config file")
ca = pflag.String("ca", "http://localhost:10000", "CA server")
keysize = pflag.Int("key_size", 0, "Size of key to generate. Ignored for ed25519 keys. (default 2048 for rsa keys, 256 for ecdsa keys)")
validity = pflag.Duration("validity", time.Hour*24, "Key lifetime. May be overridden by the CA at signing time")
keytype = pflag.String("key_type", "", "Type of private key to generate - rsa, ecdsa or ed25519. (default \"rsa\")")
publicFilePrefix = pflag.String("key_file_prefix", "", "Prefix for filename for public key and cert (optional, no default)")
_ = pflag.String("ca", "http://localhost:10000", "CA server")
_ = pflag.Int("key_size", 0, "Size of key to generate. Ignored for ed25519 keys. (default 2048 for rsa keys, 256 for ecdsa keys)")
_ = pflag.Duration("validity", time.Hour*24, "Key lifetime. May be overridden by the CA at signing time")
_ = pflag.String("key_type", "", "Type of private key to generate - rsa, ecdsa or ed25519. (default \"rsa\")")
_ = pflag.String("key_file_prefix", "", "Prefix for filename for public key and cert (optional, no default)")
version = pflag.Bool("version", false, "Print version and exit")
)
func main() {
pflag.Parse()
if *version {
fmt.Printf("%s\n", lib.Version)
os.Exit(0)
}
log.SetPrefix("cashier: ")
log.SetFlags(0)
var err error
......
......@@ -2,8 +2,11 @@ package main
import (
"flag"
"fmt"
"log"
"os"
"github.com/nsheridan/cashier/lib"
"github.com/nsheridan/cashier/server"
"github.com/nsheridan/cashier/server/config"
"github.com/nsheridan/cashier/server/wkfs/vaultfs"
......@@ -12,10 +15,15 @@ import (
var (
cfg = flag.String("config_file", "cashierd.conf", "Path to configuration file.")
version = flag.Bool("version", false, "Print version and exit")
)
func main() {
flag.Parse()
if *version {
fmt.Printf("%s\n", lib.Version)
os.Exit(0)
}
conf, err := config.ReadConfig(*cfg)
if err != nil {
log.Fatal(err)
......
......@@ -7,10 +7,12 @@ type SignRequest struct {
Key string `json:"key"`
ValidUntil time.Time `json:"valid_until"`
Message string `json:"message"`
Version string `json:"version"`
}
// SignResponse is sent by the server.
type SignResponse struct {
Status string `json:"status"` // Status will be "ok" or "error".
Response string `json:"response"` // Response will contain either the signed certificate or the error message.
Version string `json:"version"`
}
package lib
// Version string
var Version = "unknown"
......@@ -306,6 +306,14 @@ func newState() string {
return hex.EncodeToString(k)
}
// mwVersion is middleware to add a X-Cashier-Version header to the response.
func mwVersion(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-Cashier-Version", lib.Version)
next.ServeHTTP(w, r)
})
}
func runHTTPServer(conf *config.Server, l net.Listener) {
var err error
ctx := &appContext{
......@@ -330,6 +338,7 @@ func runHTTPServer(conf *config.Server, l net.Listener) {
CSRF := csrf.Protect([]byte(conf.CSRFSecret), csrf.Secure(conf.UseTLS))
r := mux.NewRouter()
r.Use(mwVersion)
r.Methods("GET").Path("/").Handler(appHandler{ctx, rootHandler})
r.Methods("GET").Path("/auth/login").Handler(appHandler{ctx, loginHandler})
r.Methods("GET").Path("/auth/callback").Handler(appHandler{ctx, callbackHandler})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment