Skip to content
This repository was archived by the owner on Feb 21, 2024. It is now read-only.

Commit 6933196

Browse files
Fletcher Haynesfhaynes
Fletcher Haynes
authored andcommitted
Updated version check to use POST only. Updated version check schema. Now generating a local UUID to submit to version check as a unique ID that persists in a file.
1 parent 20429bb commit 6933196

File tree

2 files changed

+67
-11
lines changed

2 files changed

+67
-11
lines changed

server.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -607,13 +607,13 @@ func (s *Server) Open() error {
607607
// Do version check in. This is in a goroutine so that we don't block server startup if the server endpoint is down/having issues.
608608
go func() {
609609
s.logger.Printf("Beginning featurebase version check-in")
610-
vc := VersionChecker{URL: "https://analytics.featurebase.com/v2/featurebase/version"}
610+
vc := VersionChecker{URL: "https://analytics.featurebase.com/v2/featurebase/metrics"}
611611
resp, err := vc.CheckIn()
612612
if err != nil {
613613
s.logger.Errorf("doing version checkin. Error was %s", err)
614614
return
615615
}
616-
s.logger.Printf("Version check-in complete. Latest version is %s", resp.Information.Version)
616+
s.logger.Printf("Version check-in complete. Latest version is %s", resp.Version)
617617
}()
618618

619619
// Start DisCo.

verchk.go

+65-9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import (
55
"encoding/json"
66
"io"
77
"net/http"
8+
"os"
9+
"strings"
10+
11+
"github.com/google/uuid"
812
)
913

1014
type VersionChecker struct {
@@ -18,26 +22,36 @@ func NewVersionChecker(endpoint string) *VersionChecker {
1822
return &v
1923
}
2024

21-
func (v *VersionChecker) CheckIn() (*Response, error) {
25+
func (v *VersionChecker) CheckIn() (*VerCheckResponse, error) {
26+
27+
id, err := v.WriteClientUUID()
28+
if err != nil {
29+
return nil, err
30+
}
2231

2332
body := make(map[string]string, 2)
2433
body["entry_type"] = "user"
25-
body["version"] = VersionInfo(true)
34+
body["version"] = Version
35+
body["client_id"] = id
36+
2637
req, err := json.Marshal(body)
2738
if err != nil {
2839
return nil, err
2940
}
30-
_, err = http.Post(v.URL, "application/json", bytes.NewBuffer(req))
41+
42+
wReq := bytes.NewReader(req)
43+
3144
if err != nil {
3245
return nil, err
3346
}
3447

35-
var json_resp Response
36-
r, err := http.Get(v.URL)
48+
var json_resp VerCheckResponse
49+
r, err := http.Post(v.URL, "application/json", wReq)
3750
if err != nil {
3851
return nil, err
3952
}
4053
data, err := io.ReadAll(r.Body)
54+
4155
if err != nil {
4256
return nil, err
4357
}
@@ -51,10 +65,52 @@ func (v *VersionChecker) CheckIn() (*Response, error) {
5165

5266
}
5367

54-
type Response struct {
55-
Information InfoSubResponse `json:"info"`
68+
func (v *VersionChecker) GenerateClientUUID() (string, error) {
69+
clientUUID := uuid.New()
70+
cleanedUUID := strings.Replace(clientUUID.String(), "-", "", -1)
71+
return cleanedUUID, nil
72+
}
73+
74+
func (v *VersionChecker) WriteClientUUID() (string, error) {
75+
filename := ".client_id.txt"
76+
_, err := os.Stat(filename)
77+
if err != nil {
78+
if os.IsNotExist(err) {
79+
fh, err := os.Create(filename)
80+
if err != nil {
81+
return "", err
82+
}
83+
defer fh.Close()
84+
id, err := v.GenerateClientUUID()
85+
if err != nil {
86+
return "", err
87+
}
88+
89+
_, err = fh.WriteString(id)
90+
if err != nil {
91+
return "", err
92+
}
93+
94+
return "", err
95+
} else {
96+
return "", err
97+
}
98+
}
99+
100+
fh, err := os.Open(filename)
101+
if err != nil {
102+
return "", err
103+
}
104+
defer fh.Close()
105+
buf, err := os.ReadFile(filename)
106+
107+
if err != nil {
108+
return "", err
109+
}
110+
return string(buf), nil
111+
56112
}
57113

58-
type InfoSubResponse struct {
59-
Version string `json:"version"`
114+
type VerCheckResponse struct {
115+
Version string `json:"latest_version"`
60116
}

0 commit comments

Comments
 (0)