From 0aab9fbf615776c707067e947bd5b04eab6c2c1c Mon Sep 17 00:00:00 2001 From: Terin Stock Date: Wed, 8 Jan 2025 03:16:25 +0100 Subject: [PATCH] feat(cfapi): include origin-ca-issuer version The team operating the Origin CA have requested this issuer include version information in the User-Agent to aid in debugging issues on their side and understand the rate at which updates to the issuer have been adopted. Introduces an internal "version" package where the binary version is set via LDFLAGS. Starting with Go 1.24 this information will be embedded into the binary's module, which can be queried instead. --- Makefile | 2 +- internal/cfapi/cfapi.go | 4 +++- internal/version/version.go | 3 +++ pkgs/controllers/testdata/database-failure.yaml | 2 +- pkgs/controllers/testdata/working.yaml | 4 ++-- 5 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 internal/version/version.go diff --git a/Makefile b/Makefile index b7e5f99..4e0b9e5 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ ifeq (${KERNEL},Linux) GOFLAGS ?= -buildmode=pie endif -GO_LDFLAGS += -w -s -X main.version=${VERSION} +GO_LDFLAGS += -w -s -X github.com/cloudflare/origin-ca-issuer/internal/version.Version=${VERSION} GOFLAGS += -v export CGO_ENABLED diff --git a/internal/cfapi/cfapi.go b/internal/cfapi/cfapi.go index d803613..7e15d9b 100644 --- a/internal/cfapi/cfapi.go +++ b/internal/cfapi/cfapi.go @@ -8,6 +8,8 @@ import ( "net/http" "net/url" "time" + + "github.com/cloudflare/origin-ca-issuer/internal/version" ) type Interface interface { @@ -121,7 +123,7 @@ func (c *Client) Sign(ctx context.Context, req *SignRequest) (*SignResponse, err return nil, err } - r.Header.Add("User-Agent", "github.com/cloudflare/origin-ca-issuer") + r.Header.Add("User-Agent", "origin-ca-issuer/"+version.Version) if c.serviceKey != nil { r.Header.Add("X-Auth-User-Service-Key", string(c.serviceKey)) diff --git a/internal/version/version.go b/internal/version/version.go new file mode 100644 index 0000000..415100d --- /dev/null +++ b/internal/version/version.go @@ -0,0 +1,3 @@ +package version + +var Version = "0.0.0" diff --git a/pkgs/controllers/testdata/database-failure.yaml b/pkgs/controllers/testdata/database-failure.yaml index 3188476..29bf93a 100644 --- a/pkgs/controllers/testdata/database-failure.yaml +++ b/pkgs/controllers/testdata/database-failure.yaml @@ -16,7 +16,7 @@ interactions: form: {} headers: User-Agent: - - github.com/cloudflare/origin-ca-issuer + - origin-ca-issuer/0.0.0 X-Auth-User-Service-Key: - djEuMC0weDAwQkFCMTBD url: https://api.cloudflare.com/client/v4/certificates diff --git a/pkgs/controllers/testdata/working.yaml b/pkgs/controllers/testdata/working.yaml index 83dbd45..a19bfd3 100644 --- a/pkgs/controllers/testdata/working.yaml +++ b/pkgs/controllers/testdata/working.yaml @@ -16,7 +16,7 @@ interactions: form: {} headers: User-Agent: - - github.com/cloudflare/origin-ca-issuer + - origin-ca-issuer/0.0.0 X-Auth-User-Service-Key: - djEuMC0weDAwQkFCMTBD url: https://api.cloudflare.com/client/v4/certificates @@ -62,7 +62,7 @@ interactions: form: {} headers: User-Agent: - - github.com/cloudflare/origin-ca-issuer + - origin-ca-issuer/0.0.0 Authorization: - Bearer api-token url: https://api.cloudflare.com/client/v4/certificates