Skip to content

Commit

Permalink
feat: add version info (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
thevilledev committed Jul 7, 2023
1 parent e8ccc60 commit 4729c5b
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 7 deletions.
25 changes: 19 additions & 6 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com
before:
hooks:
- go mod tidy
- go generate ./...

builds:
- env:
Expand All @@ -17,6 +14,22 @@ builds:
- arm64
main: cmd/vault-plugin-secrets-vercel/main.go
binary: vault-plugin-secrets-vercel
flags:
- -v
- -trimpath
- -a
ldflags:
- -s
- -w
- -extld ld
- -extldflags
- -static
- -X github.com/thevilledev/vault-plugin-secrets-vercel/internal/version.BuildDate={{.Date}}
- -X github.com/thevilledev/vault-plugin-secrets-vercel/internal/version.Version={{.Version}}
- -X github.com/thevilledev/vault-plugin-secrets-vercel/internal/version.Commit={{.FullCommit}}
- -X github.com/thevilledev/vault-plugin-secrets-vercel/internal/version.Dirty={{.IsGitDirty}}
- -X github.com/thevilledev/vault-plugin-secrets-vercel/internal/version.CommitDate={{.CommitDate}}
- -X github.com/thevilledev/vault-plugin-secrets-vercel/internal/version.Branch={{.Branch}}

archives:
- format: tar.gz
Expand All @@ -38,6 +51,6 @@ changelog:
sort: asc
filters:
exclude:
- '^chore(docs):'
- '^chore(test):'
- '^chore(ci):'
- '^chore(docs)'
- '^chore(test)'
- '^chore(ci)'
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,23 @@ ifndef OS
endif
endif

DATE =$(shell date '+%a %b %d %H:%m:%S %Z %Y')
REVISION =$(shell git rev-parse --verify --short HEAD)
VERSION =$(shell git describe --always --tags --exact-match 2>/dev/null || \
echo $(REVISION))

LDFLAGS =-s -w -extld ld -extldflags -static \
-X 'github.com/thevilledev/vault-plugin-secrets-vercel/internal/version.BuildDate=$(DATE)' \
-X 'github.com/thevilledev/vault-plugin-secrets-vercel/internal/version.Version=$(VERSION)' \
-X 'github.com/thevilledev/vault-plugin-secrets-vercel/internal/version.Commit=$(REVISION)'
FLAGS =-trimpath -a -ldflags "$(LDFLAGS)"

.DEFAULT_GOAL := all

all: fmt build start

build:
GOOS=$(OS) GOARCH="$(GOARCH)" go build -o vault/plugins/vault-plugin-secrets-vercel cmd/vault-plugin-secrets-vercel/main.go
CGO_ENABLED=0 GOOS=$(OS) GOARCH="$(GOARCH)" go build $(FLAGS) -o vault/plugins/vault-plugin-secrets-vercel cmd/vault-plugin-secrets-vercel/main.go

start:
VAULT_ADDR='http://127.0.0.1:8200' VAULT_API_ADDR='http://127.0.0.1:8200' vault server -dev -dev-root-token-id=root -dev-plugin-dir=./vault/plugins
Expand Down
1 change: 1 addition & 0 deletions internal/plugin/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func newBackend() *backend {
Paths: framework.PathAppend(
b.pathConfig(),
b.pathToken(),
b.pathInfo(),
),
Secrets: []*framework.Secret{
{
Expand Down
44 changes: 44 additions & 0 deletions internal/plugin/path_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package plugin

import (
"context"

"github.com/hashicorp/vault/sdk/framework"
"github.com/hashicorp/vault/sdk/logical"
"github.com/thevilledev/vault-plugin-secrets-vercel/internal/version"
)

const (
pathPatternInfo = "info"
)

func (b *backend) pathInfo() []*framework.Path {
return []*framework.Path{
{
Pattern: pathPatternInfo,
Operations: map[logical.Operation]framework.OperationHandler{
logical.ReadOperation: &framework.PathOperation{
Callback: b.pathInfoRead,
},
},
},
}
}

func (b *backend) pathInfoRead(
_ context.Context,
_ *logical.Request,
_ *framework.FieldData,
) (*logical.Response, error) {
return &logical.Response{
Data: map[string]any{
"build_date": version.BuildDate,
"build_version": version.Version,
"build_commit": version.Commit,
"build_commit_date": version.CommitDate,
"build_branch": version.Branch,
"build_tag": version.Tag,
"build_dirty": version.Dirty,
},
}, nil
}
11 changes: 11 additions & 0 deletions internal/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package version

var (
BuildDate string
Version string
Commit string
CommitDate string
Branch string
Tag string
Dirty string
)

0 comments on commit 4729c5b

Please sign in to comment.