aboutsummaryrefslogtreecommitdiff
path: root/pkg/api/api0
diff options
context:
space:
mode:
authorpg9182 <96569817+pg9182@users.noreply.github.com>2022-10-16 02:56:45 -0400
committerpg9182 <96569817+pg9182@users.noreply.github.com>2022-10-16 02:56:45 -0400
commit223f15f9842d529e93af38e3edcb58c3ce53cfe8 (patch)
tree6418e3b936ba4fc2bc8943bf16312b2e13092f86 /pkg/api/api0
parentc0e4ec7ab48d0676af1f45c71a0a4cc8a54a1110 (diff)
downloadAtlas-223f15f9842d529e93af38e3edcb58c3ce53cfe8.tar.gz
Atlas-223f15f9842d529e93af38e3edcb58c3ce53cfe8.zip
pkg/api/api0: Store launcher version in server list
Diffstat (limited to 'pkg/api/api0')
-rw-r--r--pkg/api/api0/api.go19
-rw-r--r--pkg/api/api0/server.go4
-rw-r--r--pkg/api/api0/serverlist.go2
3 files changed, 24 insertions, 1 deletions
diff --git a/pkg/api/api0/api.go b/pkg/api/api0/api.go
index 10729e1..51d3c18 100644
--- a/pkg/api/api0/api.go
+++ b/pkg/api/api0/api.go
@@ -148,6 +148,25 @@ func (h *Handler) checkLauncherVersion(r *http.Request) bool {
return semver.Compare(rver, mver) >= 0
}
+// extractLauncherVersion extracts the launcher version from r, returning an
+// empty string if it's missing or invalid.
+func (h *Handler) extractLauncherVersion(r *http.Request) string {
+ rver, _, _ := strings.Cut(r.Header.Get("User-Agent"), " ")
+ if x := strings.TrimPrefix(rver, "R2Northstar/"); rver != x {
+ if len(x) > 0 && x[0] != 'v' {
+ rver = "v" + x
+ } else {
+ rver = x
+ }
+ } else {
+ rver = ""
+ }
+ if rver != "" && semver.IsValid(rver) {
+ return rver[1:]
+ }
+ return ""
+}
+
// respFail writes a {success:false,error:ErrorObj} response with the provided
// response status.
func respFail(w http.ResponseWriter, r *http.Request, status int, obj ErrorObj) {
diff --git a/pkg/api/api0/server.go b/pkg/api/api0/server.go
index 756c48b..68c94c9 100644
--- a/pkg/api/api0/server.go
+++ b/pkg/api/api0/server.go
@@ -85,7 +85,9 @@ func (h *Handler) handleServerUpsert(w http.ResponseWriter, r *http.Request) {
var s *Server
if canCreate {
- s = &Server{}
+ s = &Server{
+ LauncherVersion: h.extractLauncherVersion(r),
+ }
}
var u *ServerUpdate
diff --git a/pkg/api/api0/serverlist.go b/pkg/api/api0/serverlist.go
index 04ee79b..35be9f6 100644
--- a/pkg/api/api0/serverlist.go
+++ b/pkg/api/api0/serverlist.go
@@ -53,6 +53,8 @@ type Server struct {
Addr netip.AddrPort // unique, must not be modified after creation
AuthPort uint16 // unique with Addr.Addr(), must not be modified after creation
+ LauncherVersion string // for metrics
+
Name string
Description string
Password string // blank for none