Skip to content

Commit

Permalink
fnapi: set user agent based on internal version.
Browse files Browse the repository at this point in the history
  • Loading branch information
hugosantos committed Oct 19, 2023
1 parent fd2f173 commit 149c5cd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
7 changes: 7 additions & 0 deletions internal/cli/fncobra/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"log"
"os"
"path/filepath"
"runtime/debug"
"runtime/pprof"

containerdlog "github.com/containerd/containerd/log"
Expand Down Expand Up @@ -61,6 +62,12 @@ type MainOpts struct {
func DoMain(opts MainOpts) {
fncobraname.CmdName = opts.Name

if info, ok := debug.ReadBuildInfo(); ok {
if v, err := version.VersionFrom(info); err == nil {
fnapi.UserAgent = fmt.Sprintf("%s/%s", opts.Name, v.Version)
}
}

style, err := doMain(opts)

if err != nil && !errors.Is(err, context.Canceled) {
Expand Down
3 changes: 3 additions & 0 deletions internal/fnapi/fnapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ var (
EndpointAddress = "https://api.namespacelabs.net"
AdminMode = false
ExchangeGithubToTenantToken = false

UserAgent = "ns/unknown"
)

func SetupFlags(flags *pflag.FlagSet) {
Expand Down Expand Up @@ -81,6 +83,7 @@ func DecodeJSONResponse(resp any) func(io.Reader) error {

func AddNamespaceHeaders(ctx context.Context, headers *http.Header) {
headers.Add("NS-Internal-Version", fmt.Sprintf("%d", versions.Builtin().APIVersion))
headers.Add("User-Agent", UserAgent)

if AdminMode {
headers.Add("NS-API-Mode", "admin")
Expand Down
2 changes: 1 addition & 1 deletion internal/versions/versions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"api_version": 95,
"api_version": 96,
"minimum_api_version": 40,
"cache_version": 1
}

0 comments on commit 149c5cd

Please sign in to comment.