diff --git a/.goreleaser.yaml b/.goreleaser.yaml index cde7329..0debeb8 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -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: @@ -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 @@ -38,6 +51,6 @@ changelog: sort: asc filters: exclude: - - '^chore(docs):' - - '^chore(test):' - - '^chore(ci):' + - '^chore(docs)' + - '^chore(test)' + - '^chore(ci)' diff --git a/Makefile b/Makefile index cb588e1..a42bcbd 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/internal/plugin/backend.go b/internal/plugin/backend.go index b4e1dd4..025a6c5 100644 --- a/internal/plugin/backend.go +++ b/internal/plugin/backend.go @@ -46,6 +46,7 @@ func newBackend() *backend { Paths: framework.PathAppend( b.pathConfig(), b.pathToken(), + b.pathInfo(), ), Secrets: []*framework.Secret{ { diff --git a/internal/plugin/path_info.go b/internal/plugin/path_info.go new file mode 100644 index 0000000..d9046aa --- /dev/null +++ b/internal/plugin/path_info.go @@ -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 +} diff --git a/internal/version/version.go b/internal/version/version.go new file mode 100644 index 0000000..f587d10 --- /dev/null +++ b/internal/version/version.go @@ -0,0 +1,11 @@ +package version + +var ( + BuildDate string + Version string + Commit string + CommitDate string + Branch string + Tag string + Dirty string +)