Move external dependency fleetdm/kolide-kit to monorepo (#15861)

#15556

We will need to pay attention when releasing fleet (the github actions
were modified to use the local file now).

Should be reviewed by commits (first commit is the actual adding of the
`version.go` file)

- [X] Manual QA for all new/changed functionality

Manually tested the following:
- `Settings -> My account` on the UI and checked the `/version` endpoint
response. (Or also visiting https://localhost:8080/version on a
browser).
- Ran `make fleetctl fleet`, `./build/fleetctl --version` and
`./build/fleet version`.
This commit is contained in:
Lucas Manuel Rodriguez
2024-01-02 18:22:52 -03:00
committed by GitHub
parent d2015d1a36
commit 417f45fc61
15 changed files with 159 additions and 57 deletions
+1 -1
View File
@@ -10,9 +10,9 @@ import (
"github.com/fleetdm/fleet/v4/server/contexts/ctxerr"
"github.com/fleetdm/fleet/v4/server/contexts/license"
"github.com/fleetdm/fleet/v4/server/fleet"
"github.com/fleetdm/fleet/v4/server/version"
"github.com/go-kit/kit/log/level"
"github.com/jmoiron/sqlx"
"github.com/kolide/kit/version"
)
type statistics struct {
+1 -1
View File
@@ -7,8 +7,8 @@ import (
"io"
"time"
"github.com/fleetdm/fleet/v4/server/version"
"github.com/fleetdm/fleet/v4/server/websocket"
"github.com/kolide/kit/version"
)
// EnterpriseOverrides contains the methods that can be overriden by the
+1 -1
View File
@@ -23,8 +23,8 @@ import (
"github.com/fleetdm/fleet/v4/server/contexts/license"
"github.com/fleetdm/fleet/v4/server/contexts/viewer"
"github.com/fleetdm/fleet/v4/server/fleet"
"github.com/fleetdm/fleet/v4/server/version"
"github.com/go-kit/kit/log/level"
"github.com/kolide/kit/version"
)
////////////////////////////////////////////////////////////////////////////////
+1 -1
View File
@@ -2,7 +2,7 @@ package service
import (
"github.com/fleetdm/fleet/v4/server/fleet"
"github.com/kolide/kit/version"
"github.com/fleetdm/fleet/v4/server/version"
)
// ApplyAppConfig sends the application config to be applied to the Fleet instance.
+91
View File
@@ -0,0 +1,91 @@
/*
Package version provides utilities for displaying version information about a Go application.
To use this package, a program would set the package variables at build time, using the
-ldflags go build flag.
Example:
go build -ldflags "-X github.com/fleetdm/fleet/v4/server/version.version=1.0.0"
Available values and defaults to use with ldflags:
version = "unknown"
branch = "unknown"
revision = "unknown"
goVersion = "unknown"
buildDate = "unknown"
buildUser = "unknown"
appName = "unknown"
This file was copied (on December 2023) from https://github.com/fleetdm/kolide-kit, which is a fork of https://github.com/kolide/kit.
*/
package version
import (
"encoding/json"
"fmt"
"net/http"
"runtime"
)
// These values are private which ensures they can only be set with the build flags.
var (
version = "unknown"
branch = "unknown"
revision = "unknown"
goVersion = runtime.Version()
buildDate = "unknown"
buildUser = "unknown"
appName = "unknown"
)
// Info is a structure with version build information about the current application.
type Info struct {
Version string `json:"version"`
Branch string `json:"branch"`
Revision string `json:"revision"`
GoVersion string `json:"go_version"`
BuildDate string `json:"build_date"`
BuildUser string `json:"build_user"`
}
// Version returns a structure with the current version information.
func Version() Info {
return Info{
Version: version,
Branch: branch,
Revision: revision,
GoVersion: goVersion,
BuildDate: buildDate,
BuildUser: buildUser,
}
}
// Print outputs the application name and version string.
func Print() {
v := Version()
fmt.Printf("%s version %s\n", appName, v.Version)
}
// PrintFull prints the application name and detailed version information.
func PrintFull() {
v := Version()
fmt.Printf("%s - version %s\n", appName, v.Version)
fmt.Printf(" branch: \t%s\n", v.Branch)
fmt.Printf(" revision: \t%s\n", v.Revision)
fmt.Printf(" build date: \t%s\n", v.BuildDate)
fmt.Printf(" build user: \t%s\n", v.BuildUser)
fmt.Printf(" go version: \t%s\n", v.GoVersion)
}
// Handler returns an HTTP Handler which returns JSON formatted version information.
func Handler() http.Handler {
v := Version()
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
enc := json.NewEncoder(w)
enc.SetIndent("", " ")
enc.Encode(v) //nolint:errcheck
})
}