Skip to content

Commit

Permalink
feat(cfapi): include origin-ca-issuer version
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
terinjokes committed Jan 8, 2025
1 parent a86cb47 commit 0aab9fb
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion internal/cfapi/cfapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"net/http"
"net/url"
"time"

"github.com/cloudflare/origin-ca-issuer/internal/version"
)

type Interface interface {
Expand Down Expand Up @@ -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))
Expand Down
3 changes: 3 additions & 0 deletions internal/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package version

var Version = "0.0.0"
2 changes: 1 addition & 1 deletion pkgs/controllers/testdata/database-failure.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkgs/controllers/testdata/working.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0aab9fb

Please sign in to comment.